From ac7280d82e7c17ca6d4de65bb7c435218b60d556 Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Tue, 29 Apr 2025 22:25:21 +0600 Subject: [PATCH 01/63] Add `KeepWhatsRaised` treasury abstract contract --- src/treasuries/KeepWhatsRaised.sol | 215 +++++++++++++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 src/treasuries/KeepWhatsRaised.sol diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol new file mode 100644 index 00000000..95d68072 --- /dev/null +++ b/src/treasuries/KeepWhatsRaised.sol @@ -0,0 +1,215 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.20; + +import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; +import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol"; + +import "../utils/Counters.sol"; +import "../utils/TimestampChecker.sol"; +import "../utils/BaseTreasury.sol"; +import "../interfaces/IReward.sol"; + +/** + * @title KeepWhatsRaised + * @notice A contract that keeps all the funds raised, regardless of the success condition. + */ +abstract contract KeepWhatsRaised is + IReward, + BaseTreasury, + TimestampChecker, + ERC721Burnable +{ + using Counters for Counters.Counter; + using SafeERC20 for IERC20; + + // Mapping to store reward details by name + mapping(bytes32 => Reward) private s_reward; + + // Counters for token IDs and rewards + Counters.Counter private s_tokenIdCounter; + Counters.Counter private s_rewardCounter; + + string private s_name; + string private s_symbol; + + /** + * @dev Emitted when rewards are added to the campaign. + * @param rewardNames The names of the rewards. + * @param rewards The details of the rewards. + */ + event RewardsAdded(bytes32[] rewardNames, Reward[] rewards); + + /** + * @dev Emitted when a reward is removed from the campaign. + * @param rewardName The name of the reward. + */ + event RewardRemoved(bytes32 indexed rewardName); + + /** + * @dev Emitted when an unauthorized action is attempted. + */ + error KeepWhatsRaisedUnAuthorized(); + + /** + * @dev Emitted when an invalid input is detected. + */ + error KeepWhatsRaisedInvalidInput(); + + /** + * @dev Emitted when a `Reward` already exists for given input. + */ + error KeepWhatsRaisedRewardExists(); + + /** + * @dev Constructor for the KeepWhatsRaised contract. + */ + constructor() ERC721("", "") {} + + function initialize( + bytes32 _platformHash, + address _infoAddress, + string calldata _name, + string calldata _symbol + ) external initializer { + __BaseContract_init(_platformHash, _infoAddress); + s_name = _name; + s_symbol = _symbol; + } + + function name() public view override returns (string memory) { + return s_name; + } + + function symbol() public view override returns (string memory) { + return s_symbol; + } + + /** + * @notice Retrieves the details of a reward. + * @param rewardName The name of the reward. + * @return reward The details of the reward as a `Reward` struct. + */ + function getReward( + bytes32 rewardName + ) external view returns (Reward memory reward) { + if (s_reward[rewardName].rewardValue == 0) { + revert KeepWhatsRaisedInvalidInput(); + } + return s_reward[rewardName]; + } + + /** + * @inheritdoc ICampaignTreasury + */ + function getRaisedAmount() external view override returns (uint256) { + return s_pledgedAmount; + } + + /** + * @notice Adds multiple rewards in a batch. + * @dev This function allows for both reward tiers and non-reward tiers. + * For both types, rewards must have non-zero value. + * If items are specified (non-empty arrays), the itemId, itemValue, and itemQuantity arrays must match in length. + * Empty arrays are allowed for both reward tiers and non-reward tiers. + * @param rewardNames An array of reward names. + * @param rewards An array of `Reward` structs containing reward details. + */ + function addRewards( + bytes32[] calldata rewardNames, + Reward[] calldata rewards + ) + external + onlyCampaignOwner + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled + { + if (rewardNames.length != rewards.length) { + revert KeepWhatsRaisedInvalidInput(); + } + + for (uint256 i = 0; i < rewardNames.length; i++) { + bytes32 rewardName = rewardNames[i]; + Reward calldata reward = rewards[i]; + + // Reward name must not be zero bytes and reward value must be non-zero + if (rewardName == ZERO_BYTES || reward.rewardValue == 0) { + revert KeepWhatsRaisedInvalidInput(); + } + + // If there are any items, their arrays must match in length + if ( + (reward.itemId.length != reward.itemValue.length) || + (reward.itemId.length != reward.itemQuantity.length) + ) { + revert KeepWhatsRaisedInvalidInput(); + } + + // Check for duplicate reward + if (s_reward[rewardName].rewardValue != 0) { + revert KeepWhatsRaisedRewardExists(); + } + + s_reward[rewardName] = reward; + s_rewardCounter.increment(); + } + emit RewardsAdded(rewardNames, rewards); + } + + /** + * @notice Removes a reward from the campaign. + * @param rewardName The name of the reward. + */ + function removeReward( + bytes32 rewardName + ) + external + onlyCampaignOwner + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled + { + if (s_reward[rewardName].rewardValue == 0) { + revert KeepWhatsRaisedInvalidInput(); + } + delete s_reward[rewardName]; + s_rewardCounter.decrement(); + emit RewardRemoved(rewardName); + } + + /** + * @inheritdoc BaseTreasury + * @dev This function is overridden to allow the platform admin and the campaign owner to cancel a treasury. + */ + function cancelTreasury(bytes32 message) public override { + if ( + msg.sender != INFO.getPlatformAdminAddress(PLATFORM_HASH) && + msg.sender != INFO.owner() + ) { + revert KeepWhatsRaisedUnAuthorized(); + } + _cancel(message); + } + + /** + * @inheritdoc BaseTreasury + */ + function _checkSuccessCondition() + internal + view + virtual + override + returns (bool) + { + return INFO.getTotalRaisedAmount() >= INFO.getGoalAmount(); + } + + // The following functions are overrides required by Solidity. + function supportsInterface( + bytes4 interfaceId + ) public view override returns (bool) { + return super.supportsInterface(interfaceId); + } +} From 0c2bfae3eb56cc82a0fc36a25a5c87c67c13efa3 Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Wed, 30 Apr 2025 11:26:45 +0600 Subject: [PATCH 02/63] Add `pledge` functionality in `KeepWhatsRaised` treasury - pledgeForAReward - Allows a backer to pledge for a reward. - pledgeWithoutAReward - Allows a backer to pledge without selecting a reward. - _pledge - A private function to contain all the pledge logic --- src/treasuries/KeepWhatsRaised.sol | 117 +++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index 95d68072..9b4cc22b 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -22,6 +22,12 @@ abstract contract KeepWhatsRaised is using Counters for Counters.Counter; using SafeERC20 for IERC20; + // Mapping to store the total collected amount (pledged amount and tip amount) per token ID + mapping(uint256 => uint256) private s_tokenToTotalCollectedAmount; + // Mapping to store the pledged amount per token ID + mapping(uint256 => uint256) private s_tokenToPledgedAmount; + // Mapping to store the tipped amount per token ID + mapping(uint256 => uint256) private s_tokenToTippedAmount; // Mapping to store reward details by name mapping(bytes32 => Reward) private s_reward; @@ -31,6 +37,25 @@ abstract contract KeepWhatsRaised is string private s_name; string private s_symbol; + uint256 private s_tip; + + /** + * @dev Emitted when a backer makes a pledge. + * @param backer The address of the backer making the pledge. + * @param reward The name of the reward. + * @param pledgeAmount The amount pledged. + * @param tip An optional tip can be added during the process. + * @param tokenId The ID of the token representing the pledge. + * @param rewards An array of reward names. + */ + event Receipt( + address indexed backer, + bytes32 indexed reward, + uint256 pledgeAmount, + uint256 tip, + uint256 tokenId, + bytes32[] rewards + ); /** * @dev Emitted when rewards are added to the campaign. @@ -179,6 +204,71 @@ abstract contract KeepWhatsRaised is emit RewardRemoved(rewardName); } + /** + * @notice Allows a backer to pledge for a reward. + * @dev The first element of the `reward` array must be a reward tier and the other elements can be either reward tiers or non-reward tiers. + * The non-reward tiers cannot be pledged for without a reward. + * @param backer The address of the backer making the pledge. + * @param tip An optional tip can be added during the process. + * @param reward An array of reward names. + */ + function pledgeForAReward( + address backer, + uint256 tip, + bytes32[] calldata reward + ) + external + currentTimeIsWithinRange(INFO.getLaunchTime(), INFO.getDeadline()) + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled + { + uint256 tokenId = s_tokenIdCounter.current(); + uint256 rewardLen = reward.length; + Reward storage tempReward = s_reward[reward[0]]; + if ( + backer == address(0) || + rewardLen > s_rewardCounter.current() || + reward[0] == ZERO_BYTES || + !tempReward.isRewardTier + ) { + revert KeepWhatsRaisedInvalidInput(); + } + uint256 pledgeAmount = tempReward.rewardValue; + for (uint256 i = 1; i < rewardLen; i++) { + if (reward[i] == ZERO_BYTES) { + revert KeepWhatsRaisedInvalidInput(); + } + pledgeAmount += s_reward[reward[i]].rewardValue; + } + _pledge(backer, reward[0], pledgeAmount, tip, tokenId, reward); + } + + /** + * @notice Allows a backer to pledge without selecting a reward. + * @param backer The address of the backer making the pledge. + * @param pledgeAmount The amount of the pledge. + * @param tip An optional tip can be added during the process. + */ + function pledgeWithoutAReward( + address backer, + uint256 pledgeAmount, + uint256 tip + ) + external + currentTimeIsWithinRange(INFO.getLaunchTime(), INFO.getDeadline()) + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled + { + uint256 tokenId = s_tokenIdCounter.current(); + bytes32[] memory emptyByteArray = new bytes32[](0); + + _pledge(backer, ZERO_BYTES, pledgeAmount, tip, tokenId, emptyByteArray); + } + /** * @inheritdoc BaseTreasury * @dev This function is overridden to allow the platform admin and the campaign owner to cancel a treasury. @@ -206,6 +296,33 @@ abstract contract KeepWhatsRaised is return INFO.getTotalRaisedAmount() >= INFO.getGoalAmount(); } + function _pledge( + address backer, + bytes32 reward, + uint256 pledgeAmount, + uint256 tip, + uint256 tokenId, + bytes32[] memory rewards + ) private { + uint256 totalAmount = pledgeAmount + tip; + TOKEN.safeTransferFrom(backer, address(this), totalAmount); + s_tokenIdCounter.increment(); + _safeMint(backer, tokenId, abi.encodePacked(backer, reward)); + s_tokenToPledgedAmount[tokenId] = pledgeAmount; + s_tokenToTotalCollectedAmount[tokenId] = totalAmount; + s_tokenToTippedAmount[tokenId] = tip; + s_pledgedAmount += pledgeAmount; + s_tip += tip; + emit Receipt( + backer, + reward, + pledgeAmount, + tip, + tokenId, + rewards + ); + } + // The following functions are overrides required by Solidity. function supportsInterface( bytes4 interfaceId From 9cb7fc722f39cb8efbdda313b36663d1db443af1 Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Wed, 30 Apr 2025 16:49:04 +0600 Subject: [PATCH 03/63] WIP: Add `withdraw` functionality in `KeepWhatsRaised` treasury - Add lock and approval feature for the withdraw function - Add set fee keys and values function for admin --- src/treasuries/KeepWhatsRaised.sol | 93 ++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index 9b4cc22b..a5ab206a 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -38,6 +38,11 @@ abstract contract KeepWhatsRaised is string private s_name; string private s_symbol; uint256 private s_tip; + uint256 private s_minimumWithdrawalForFeeExemption; + bool private s_isWithdrawalApproved; + bytes32 private s_flatFeeKey; + bytes32[] private s_grossPercentageFeeKeys; + bytes32[] private s_netPercentageFeeKeys; /** * @dev Emitted when a backer makes a pledge. @@ -70,6 +75,15 @@ abstract contract KeepWhatsRaised is */ event RewardRemoved(bytes32 indexed rewardName); + event WithdrawalApproved(); + + event FeeKeysAndValuesSet( + uint256 indexed minimumWithdrawalForFeeExemption, + bytes32 indexed flatFeeKey, + bytes32[] grossPercentageFeeKeys, + bytes32[] netPercentageFeeKeys + ); + /** * @dev Emitted when an unauthorized action is attempted. */ @@ -85,6 +99,20 @@ abstract contract KeepWhatsRaised is */ error KeepWhatsRaisedRewardExists(); + /** + * @dev Emitted when anyone called a disabled function. + */ + error KeepWhatsRaisedDisabled(); + + error KeepWhatsRaisedAlreadyEnabled(); + + modifier withdrawalEnabled() { + if(!s_isWithdrawalApproved){ + revert KeepWhatsRaisedDisabled(); + } + _; + } + /** * @dev Constructor for the KeepWhatsRaised contract. */ @@ -109,6 +137,10 @@ abstract contract KeepWhatsRaised is return s_symbol; } + function getWithdrawalApprovalStatus() public view returns (bool) { + return s_isWithdrawalApproved; + } + /** * @notice Retrieves the details of a reward. * @param rewardName The name of the reward. @@ -130,6 +162,49 @@ abstract contract KeepWhatsRaised is return s_pledgedAmount; } + function approveWithdrawal() + external + onlyPlatformAdmin(PLATFORM_HASH) + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled + { + if(s_isWithdrawalApproved){ + revert KeepWhatsRaisedAlreadyEnabled(); + } + + s_isWithdrawalApproved = true; + + emit WithdrawalApproved(); + } + + function setFeeKeysAndValues( + bytes32 flatFeeKey, + bytes32[] calldata grossPercentageFeeKeys, + bytes32[] calldata netPercentageFeeKeys, + uint256 minimumWithdrawalForFeeExemption + ) + external + onlyPlatformAdmin(PLATFORM_HASH) + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled + { + s_flatFeeKey = flatFeeKey; + s_grossPercentageFeeKeys = grossPercentageFeeKeys; + s_netPercentageFeeKeys = netPercentageFeeKeys; + s_minimumWithdrawalForFeeExemption = minimumWithdrawalForFeeExemption; + + emit FeeKeysAndValuesSet( + minimumWithdrawalForFeeExemption, + flatFeeKey, + grossPercentageFeeKeys, + netPercentageFeeKeys + ); + } + /** * @notice Adds multiple rewards in a batch. * @dev This function allows for both reward tiers and non-reward tiers. @@ -269,6 +344,24 @@ abstract contract KeepWhatsRaised is _pledge(backer, ZERO_BYTES, pledgeAmount, tip, tokenId, emptyByteArray); } + /** + * @inheritdoc ICampaignTreasury + */ + function withdraw() public view override whenNotPaused whenNotCancelled { + revert KeepWhatsRaisedDisabled(); + } + + function withdraw( + uint256 amount + ) + public + whenNotPaused + whenNotCancelled + withdrawalEnabled + { + //TODO: withdraw functionality + } + /** * @inheritdoc BaseTreasury * @dev This function is overridden to allow the platform admin and the campaign owner to cancel a treasury. From bdda8d9edfca212fe1654b13b4a0d573a2dafc75 Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Fri, 2 May 2025 12:14:31 +0600 Subject: [PATCH 04/63] Update configuration and fee keys setup in `KeepWhatsRaised` treasury --- src/treasuries/KeepWhatsRaised.sol | 48 +++++++++++++++--------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index a5ab206a..2d6c7771 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -34,15 +34,23 @@ abstract contract KeepWhatsRaised is // Counters for token IDs and rewards Counters.Counter private s_tokenIdCounter; Counters.Counter private s_rewardCounter; + struct FeeKeys { + bytes32 flatFeeKey; + bytes32[] grossPercentageFeeKeys; + bytes32[] netPercentageFeeKeys; + } + struct Config { + uint256 minimumWithdrawalForFeeExemption; + uint256 withdrawalDelay; + uint256 minimumWithdrawal; + } string private s_name; string private s_symbol; uint256 private s_tip; - uint256 private s_minimumWithdrawalForFeeExemption; bool private s_isWithdrawalApproved; - bytes32 private s_flatFeeKey; - bytes32[] private s_grossPercentageFeeKeys; - bytes32[] private s_netPercentageFeeKeys; + FeeKeys private s_feeKeys; + Config private s_config; /** * @dev Emitted when a backer makes a pledge. @@ -77,11 +85,9 @@ abstract contract KeepWhatsRaised is event WithdrawalApproved(); - event FeeKeysAndValuesSet( - uint256 indexed minimumWithdrawalForFeeExemption, - bytes32 indexed flatFeeKey, - bytes32[] grossPercentageFeeKeys, - bytes32[] netPercentageFeeKeys + event ConfigAndFeeKeysSet( + Config s_config, + FeeKeys s_feeKeys ); /** @@ -179,11 +185,9 @@ abstract contract KeepWhatsRaised is emit WithdrawalApproved(); } - function setFeeKeysAndValues( - bytes32 flatFeeKey, - bytes32[] calldata grossPercentageFeeKeys, - bytes32[] calldata netPercentageFeeKeys, - uint256 minimumWithdrawalForFeeExemption + function setConfigsAndFeeKeys( + Config memory config, + FeeKeys memory feeKeys ) external onlyPlatformAdmin(PLATFORM_HASH) @@ -192,16 +196,12 @@ abstract contract KeepWhatsRaised is whenCampaignNotCancelled whenNotCancelled { - s_flatFeeKey = flatFeeKey; - s_grossPercentageFeeKeys = grossPercentageFeeKeys; - s_netPercentageFeeKeys = netPercentageFeeKeys; - s_minimumWithdrawalForFeeExemption = minimumWithdrawalForFeeExemption; - - emit FeeKeysAndValuesSet( - minimumWithdrawalForFeeExemption, - flatFeeKey, - grossPercentageFeeKeys, - netPercentageFeeKeys + s_config = config; + s_feeKeys = feeKeys; + + emit ConfigAndFeeKeysSet( + config, + feeKeys ); } From 89b3ee9eb0618e0a8124a6c036156ca96f9545ea Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Fri, 2 May 2025 16:28:25 +0600 Subject: [PATCH 05/63] Update withdraw functionality - add withdrawal fee calculation - update _pledge function - update fee keys and config variables - add new storage variables, events and custom errors --- src/treasuries/KeepWhatsRaised.sol | 89 +++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 2 deletions(-) diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index 2d6c7771..13e0e730 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -36,18 +36,21 @@ abstract contract KeepWhatsRaised is Counters.Counter private s_rewardCounter; struct FeeKeys { bytes32 flatFeeKey; + bytes32 cumulativeFlatFeeKey; bytes32[] grossPercentageFeeKeys; bytes32[] netPercentageFeeKeys; } struct Config { uint256 minimumWithdrawalForFeeExemption; uint256 withdrawalDelay; - uint256 minimumWithdrawal; } string private s_name; string private s_symbol; uint256 private s_tip; + uint256 private s_platformFee; + uint256 private s_protocolFee; + uint256 private s_availablePledgedAmount; bool private s_isWithdrawalApproved; FeeKeys private s_feeKeys; Config private s_config; @@ -90,6 +93,8 @@ abstract contract KeepWhatsRaised is FeeKeys s_feeKeys ); + event WithdrawalWithFeeSuccessful(address to, uint256 amount, uint256 fee); + /** * @dev Emitted when an unauthorized action is attempted. */ @@ -112,6 +117,12 @@ abstract contract KeepWhatsRaised is error KeepWhatsRaisedAlreadyEnabled(); + error KeepWhatsRaisedInvalidKey(); + + error KeepWhatsRaisedWithdrawalOverload(uint256 availableAmount, uint256 withdrawalAmount, uint256 fee); + + error KeepWhatsRaisedAlreadyWithdrawn(); + modifier withdrawalEnabled() { if(!s_isWithdrawalApproved){ revert KeepWhatsRaisedDisabled(); @@ -355,11 +366,84 @@ abstract contract KeepWhatsRaised is uint256 amount ) public + currentTimeIsLess(INFO.getDeadline() + s_config.withdrawalDelay) whenNotPaused whenNotCancelled withdrawalEnabled { - //TODO: withdraw functionality + uint256 flatFee = uint256(INFO.getPlatformData(s_feeKeys.flatFeeKey)); + uint256 cumulativeFee = uint256(INFO.getPlatformData(s_feeKeys.cumulativeFlatFeeKey)); + uint256 currentTime = block.timestamp; + uint256 withdrawalAmount = s_availablePledgedAmount; + uint256 totalFee = 0; + address recipient = INFO.owner(); + + //Main Fees + if(currentTime > INFO.getDeadline()){ + if(withdrawalAmount == 0){ + revert KeepWhatsRaisedAlreadyWithdrawn(); + } + if(withdrawalAmount < s_config.minimumWithdrawalForFeeExemption){ + s_platformFee += flatFee; + totalFee += flatFee; + } + + }else { + withdrawalAmount = amount; + if(withdrawalAmount == 0){ + revert KeepWhatsRaisedInvalidInput(); + } + if(withdrawalAmount > s_availablePledgedAmount){ + revert KeepWhatsRaisedWithdrawalOverload(s_availablePledgedAmount, withdrawalAmount, totalFee); + } + + if(withdrawalAmount < s_config.minimumWithdrawalForFeeExemption){ + s_platformFee += cumulativeFee; + totalFee += cumulativeFee; + }else { + s_platformFee += flatFee; + totalFee += flatFee; + } + } + + //Other Fees + uint256 fee = (s_availablePledgedAmount * INFO.getProtocolFeePercent()) / + PERCENT_DIVIDER; + s_protocolFee += fee; + totalFee += fee; + + //Gross Percentage Fee Calculation + uint256 len = s_feeKeys.grossPercentageFeeKeys.length; + for(uint256 i = 0; i < len; i++){ + fee = (s_availablePledgedAmount * uint256(s_feeKeys.grossPercentageFeeKeys[i])) / + PERCENT_DIVIDER; + s_platformFee += fee; + totalFee += fee; + } + + //Net Percentage Fee Calculation + if(totalFee > withdrawalAmount){ + revert KeepWhatsRaisedWithdrawalOverload(s_availablePledgedAmount, withdrawalAmount, totalFee); + } + uint256 availableBeforeNet = withdrawalAmount - totalFee; + len = s_feeKeys.netPercentageFeeKeys.length; + for(uint256 i = 0; i < len; i++){ + fee = (availableBeforeNet * uint256(s_feeKeys.netPercentageFeeKeys[i])) / + PERCENT_DIVIDER; + s_platformFee += fee; + totalFee += fee; + } + + if(totalFee > withdrawalAmount){ + revert KeepWhatsRaisedWithdrawalOverload(s_availablePledgedAmount, withdrawalAmount, totalFee); + } + + s_availablePledgedAmount -= withdrawalAmount; + withdrawalAmount -= totalFee; + + TOKEN.safeTransfer(recipient, withdrawalAmount); + + emit WithdrawalWithFeeSuccessful(recipient, withdrawalAmount, totalFee); } /** @@ -405,6 +489,7 @@ abstract contract KeepWhatsRaised is s_tokenToTotalCollectedAmount[tokenId] = totalAmount; s_tokenToTippedAmount[tokenId] = tip; s_pledgedAmount += pledgeAmount; + s_availablePledgedAmount += pledgeAmount; s_tip += tip; emit Receipt( backer, From ccfb169715eb1e1bc81273d0ab86fe507344b81d Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Fri, 2 May 2025 19:31:13 +0600 Subject: [PATCH 06/63] Add disburse fee functionality --- src/treasuries/KeepWhatsRaised.sol | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index 13e0e730..e4d7bcc6 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -446,6 +446,26 @@ abstract contract KeepWhatsRaised is emit WithdrawalWithFeeSuccessful(recipient, withdrawalAmount, totalFee); } + function disburseFees() + public + override + whenNotPaused + whenNotCancelled + { + uint256 protocolShare = s_protocolFee; + uint256 platformShare = s_platformFee; + (s_protocolFee, s_platformFee) = (0, 0); + + TOKEN.safeTransfer(INFO.getProtocolAdminAddress(), protocolShare); + + TOKEN.safeTransfer( + INFO.getPlatformAdminAddress(PLATFORM_HASH), + platformShare + ); + + emit FeesDisbursed(protocolShare, platformShare); + } + /** * @inheritdoc BaseTreasury * @dev This function is overridden to allow the platform admin and the campaign owner to cancel a treasury. From 632f1b2d378f482a5a24716e84da3e12f87b903b Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Fri, 2 May 2025 20:02:40 +0600 Subject: [PATCH 07/63] Add claim tip functionality --- src/treasuries/KeepWhatsRaised.sol | 31 +++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index e4d7bcc6..c7792c8c 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -52,6 +52,7 @@ abstract contract KeepWhatsRaised is uint256 private s_protocolFee; uint256 private s_availablePledgedAmount; bool private s_isWithdrawalApproved; + bool private s_tipDisbursed; FeeKeys private s_feeKeys; Config private s_config; @@ -95,6 +96,8 @@ abstract contract KeepWhatsRaised is event WithdrawalWithFeeSuccessful(address to, uint256 amount, uint256 fee); + event TipClaimed(uint256 amount, address claimer); + /** * @dev Emitted when an unauthorized action is attempted. */ @@ -123,6 +126,8 @@ abstract contract KeepWhatsRaised is error KeepWhatsRaisedAlreadyWithdrawn(); + error KeepWhatsRaisedAlreadyDisbursed(); + modifier withdrawalEnabled() { if(!s_isWithdrawalApproved){ revert KeepWhatsRaisedDisabled(); @@ -420,7 +425,7 @@ abstract contract KeepWhatsRaised is s_platformFee += fee; totalFee += fee; } - + //Net Percentage Fee Calculation if(totalFee > withdrawalAmount){ revert KeepWhatsRaisedWithdrawalOverload(s_availablePledgedAmount, withdrawalAmount, totalFee); @@ -466,6 +471,30 @@ abstract contract KeepWhatsRaised is emit FeesDisbursed(protocolShare, platformShare); } + function claimTip() + external + onlyPlatformAdmin(PLATFORM_HASH) + currentTimeIsGreater(INFO.getDeadline()) + whenCampaignNotPaused + whenNotPaused + { + if(s_tipDisbursed){ + revert KeepWhatsRaisedAlreadyDisbursed(); + } + + address platformAdmin = INFO.getPlatformAdminAddress(PLATFORM_HASH); + uint256 tip = s_tip; + s_tip = 0; + s_tipDisbursed = true; + + TOKEN.safeTransfer( + platformAdmin, + tip + ); + + emit TipClaimed(tip, platformAdmin); + } + /** * @inheritdoc BaseTreasury * @dev This function is overridden to allow the platform admin and the campaign owner to cancel a treasury. From 58afe26cf52b657649af861884b14c1d930867d5 Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Mon, 5 May 2025 13:57:32 +0600 Subject: [PATCH 08/63] Add claim refund functionality --- src/treasuries/KeepWhatsRaised.sol | 45 ++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index c7792c8c..13caee8e 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -43,6 +43,7 @@ abstract contract KeepWhatsRaised is struct Config { uint256 minimumWithdrawalForFeeExemption; uint256 withdrawalDelay; + uint256 refundDelay; } string private s_name; @@ -51,6 +52,7 @@ abstract contract KeepWhatsRaised is uint256 private s_platformFee; uint256 private s_protocolFee; uint256 private s_availablePledgedAmount; + uint256 private s_cancellationTime; bool private s_isWithdrawalApproved; bool private s_tipDisbursed; FeeKeys private s_feeKeys; @@ -98,6 +100,14 @@ abstract contract KeepWhatsRaised is event TipClaimed(uint256 amount, address claimer); + /** + * @dev Emitted when a refund is claimed. + * @param tokenId The ID of the token representing the pledge. + * @param refundAmount The refund amount claimed. + * @param claimer The address of the claimer. + */ + event RefundClaimed(uint256 tokenId, uint256 refundAmount, address claimer); + /** * @dev Emitted when an unauthorized action is attempted. */ @@ -128,6 +138,8 @@ abstract contract KeepWhatsRaised is error KeepWhatsRaisedAlreadyDisbursed(); + error KeepWhatsRaisedNotClaimable(uint256 tokenId); + modifier withdrawalEnabled() { if(!s_isWithdrawalApproved){ revert KeepWhatsRaisedDisabled(); @@ -451,6 +463,38 @@ abstract contract KeepWhatsRaised is emit WithdrawalWithFeeSuccessful(recipient, withdrawalAmount, totalFee); } + function claimRefund( + uint256 tokenId + ) + external + currentTimeIsGreater(INFO.getLaunchTime()) + whenCampaignNotPaused + whenNotPaused + { + if (block.timestamp > (INFO.getDeadline() + s_config.refundDelay) || block.timestamp > (s_cancellationTime + s_config.refundDelay)) { + revert KeepWhatsRaisedNotClaimable(tokenId); + } + uint256 amountToRefund = 0; + uint256 pledgedAmount = s_tokenToPledgedAmount[tokenId]; + uint256 availablePledgedAmount = s_availablePledgedAmount; + if(availablePledgedAmount < pledgedAmount){ + amountToRefund = availablePledgedAmount; + }else { + amountToRefund = pledgedAmount; + } + + if (amountToRefund == 0) { + revert KeepWhatsRaisedNotClaimable(tokenId); + } + s_tokenToTotalCollectedAmount[tokenId] -= amountToRefund; + s_tokenToPledgedAmount[tokenId] -= amountToRefund; + s_pledgedAmount -= amountToRefund; + s_availablePledgedAmount -= amountToRefund; + burn(tokenId); + TOKEN.safeTransfer(msg.sender, amountToRefund); + emit RefundClaimed(tokenId, amountToRefund, msg.sender); + } + function disburseFees() public override @@ -506,6 +550,7 @@ abstract contract KeepWhatsRaised is ) { revert KeepWhatsRaisedUnAuthorized(); } + s_cancellationTime = block.timestamp; _cancel(message); } From 2c4bf40bba82dbfff639b85b2f597bd5135b474e Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Mon, 5 May 2025 14:45:23 +0600 Subject: [PATCH 09/63] Add admin fund claim functionality; Update claim tip --- src/treasuries/KeepWhatsRaised.sol | 41 ++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index 13caee8e..b620ca0e 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -54,7 +54,8 @@ abstract contract KeepWhatsRaised is uint256 private s_availablePledgedAmount; uint256 private s_cancellationTime; bool private s_isWithdrawalApproved; - bool private s_tipDisbursed; + bool private s_tipClaimed; + bool private s_fundClaimed; FeeKeys private s_feeKeys; Config private s_config; @@ -100,6 +101,8 @@ abstract contract KeepWhatsRaised is event TipClaimed(uint256 amount, address claimer); + event FundClaimed(uint256 amount, address claimer); + /** * @dev Emitted when a refund is claimed. * @param tokenId The ID of the token representing the pledge. @@ -136,9 +139,10 @@ abstract contract KeepWhatsRaised is error KeepWhatsRaisedAlreadyWithdrawn(); - error KeepWhatsRaisedAlreadyDisbursed(); + error KeepWhatsRaisedAlreadyClaimed(); error KeepWhatsRaisedNotClaimable(uint256 tokenId); + error KeepWhatsRaisedNotClaimableAdmin(); modifier withdrawalEnabled() { if(!s_isWithdrawalApproved){ @@ -522,14 +526,14 @@ abstract contract KeepWhatsRaised is whenCampaignNotPaused whenNotPaused { - if(s_tipDisbursed){ - revert KeepWhatsRaisedAlreadyDisbursed(); + if(s_tipClaimed){ + revert KeepWhatsRaisedAlreadyClaimed(); } address platformAdmin = INFO.getPlatformAdminAddress(PLATFORM_HASH); uint256 tip = s_tip; s_tip = 0; - s_tipDisbursed = true; + s_tipClaimed = true; TOKEN.safeTransfer( platformAdmin, @@ -539,6 +543,33 @@ abstract contract KeepWhatsRaised is emit TipClaimed(tip, platformAdmin); } + function claimFund() + external + onlyPlatformAdmin(PLATFORM_HASH) + whenCampaignNotPaused + whenNotPaused + { + if (block.timestamp < (INFO.getDeadline() + s_config.withdrawalDelay) || block.timestamp < (s_cancellationTime + s_config.withdrawalDelay)) { + revert KeepWhatsRaisedNotClaimableAdmin(); + } + + if(s_fundClaimed){ + revert KeepWhatsRaisedAlreadyClaimed(); + } + + address platformAdmin = INFO.getPlatformAdminAddress(PLATFORM_HASH); + uint256 amountToClaim = s_availablePledgedAmount; + s_availablePledgedAmount = 0; + s_fundClaimed = true; + + TOKEN.safeTransfer( + platformAdmin, + amountToClaim + ); + + emit FundClaimed(amountToClaim, platformAdmin); + } + /** * @inheritdoc BaseTreasury * @dev This function is overridden to allow the platform admin and the campaign owner to cancel a treasury. From 44390a2cb5c794d39b4b3f1190bb837c9853845c Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Mon, 5 May 2025 14:51:37 +0600 Subject: [PATCH 10/63] Update success condition; Remove abstract keyword --- src/treasuries/KeepWhatsRaised.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index b620ca0e..72586d05 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -13,7 +13,7 @@ import "../interfaces/IReward.sol"; * @title KeepWhatsRaised * @notice A contract that keeps all the funds raised, regardless of the success condition. */ -abstract contract KeepWhatsRaised is +contract KeepWhatsRaised is IReward, BaseTreasury, TimestampChecker, @@ -595,7 +595,7 @@ abstract contract KeepWhatsRaised is override returns (bool) { - return INFO.getTotalRaisedAmount() >= INFO.getGoalAmount(); + return true; } function _pledge( From a466fa3b7d2182a0e034611c389b532d7eb77694 Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Mon, 5 May 2025 16:36:00 +0600 Subject: [PATCH 11/63] Add custom campaign configurations in treasury - Update the treasury configuration method - Add campaign data like launch time, deadline, and goal amount in treasury with a getter method - Update all the campaign configuration usage --- src/treasuries/KeepWhatsRaised.sol | 48 +++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index 72586d05..68d86d0a 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -8,6 +8,7 @@ import "../utils/Counters.sol"; import "../utils/TimestampChecker.sol"; import "../utils/BaseTreasury.sol"; import "../interfaces/IReward.sol"; +import "../interfaces/ICampaignData.sol"; /** * @title KeepWhatsRaised @@ -17,7 +18,8 @@ contract KeepWhatsRaised is IReward, BaseTreasury, TimestampChecker, - ERC721Burnable + ERC721Burnable, + ICampaignData { using Counters for Counters.Counter; using SafeERC20 for IERC20; @@ -44,6 +46,7 @@ contract KeepWhatsRaised is uint256 minimumWithdrawalForFeeExemption; uint256 withdrawalDelay; uint256 refundDelay; + uint256 configLockPeriod; } string private s_name; @@ -58,6 +61,7 @@ contract KeepWhatsRaised is bool private s_fundClaimed; FeeKeys private s_feeKeys; Config private s_config; + CampaignData private s_campaignData; /** * @dev Emitted when a backer makes a pledge. @@ -92,9 +96,10 @@ contract KeepWhatsRaised is event WithdrawalApproved(); - event ConfigAndFeeKeysSet( - Config s_config, - FeeKeys s_feeKeys + event TreasuryConfigured( + Config config, + CampaignData campaignData, + FeeKeys feeKeys ); event WithdrawalWithFeeSuccessful(address to, uint256 amount, uint256 fee); @@ -200,6 +205,18 @@ contract KeepWhatsRaised is return s_pledgedAmount; } + function getLaunchTime() public view returns (uint256) { + return s_campaignData.launchTime; + } + + function getDeadline() public view returns (uint256) { + return s_campaignData.deadline; + } + + function getGoalAmount() external view returns (uint256) { + return s_campaignData.goalAmount; + } + function approveWithdrawal() external onlyPlatformAdmin(PLATFORM_HASH) @@ -217,8 +234,9 @@ contract KeepWhatsRaised is emit WithdrawalApproved(); } - function setConfigsAndFeeKeys( + function configureTreasury( Config memory config, + CampaignData memory campaignData, FeeKeys memory feeKeys ) external @@ -230,9 +248,11 @@ contract KeepWhatsRaised is { s_config = config; s_feeKeys = feeKeys; + s_campaignData = campaignData; - emit ConfigAndFeeKeysSet( + emit TreasuryConfigured( config, + campaignData, feeKeys ); } @@ -325,7 +345,7 @@ contract KeepWhatsRaised is bytes32[] calldata reward ) external - currentTimeIsWithinRange(INFO.getLaunchTime(), INFO.getDeadline()) + currentTimeIsWithinRange(getLaunchTime(), getDeadline()) whenCampaignNotPaused whenNotPaused whenCampaignNotCancelled @@ -364,7 +384,7 @@ contract KeepWhatsRaised is uint256 tip ) external - currentTimeIsWithinRange(INFO.getLaunchTime(), INFO.getDeadline()) + currentTimeIsWithinRange(getLaunchTime(), getDeadline()) whenCampaignNotPaused whenNotPaused whenCampaignNotCancelled @@ -387,7 +407,7 @@ contract KeepWhatsRaised is uint256 amount ) public - currentTimeIsLess(INFO.getDeadline() + s_config.withdrawalDelay) + currentTimeIsLess(getDeadline() + s_config.withdrawalDelay) whenNotPaused whenNotCancelled withdrawalEnabled @@ -400,7 +420,7 @@ contract KeepWhatsRaised is address recipient = INFO.owner(); //Main Fees - if(currentTime > INFO.getDeadline()){ + if(currentTime > getDeadline()){ if(withdrawalAmount == 0){ revert KeepWhatsRaisedAlreadyWithdrawn(); } @@ -471,11 +491,11 @@ contract KeepWhatsRaised is uint256 tokenId ) external - currentTimeIsGreater(INFO.getLaunchTime()) + currentTimeIsGreater(getLaunchTime()) whenCampaignNotPaused whenNotPaused { - if (block.timestamp > (INFO.getDeadline() + s_config.refundDelay) || block.timestamp > (s_cancellationTime + s_config.refundDelay)) { + if (block.timestamp > (getDeadline() + s_config.refundDelay) || block.timestamp > (s_cancellationTime + s_config.refundDelay)) { revert KeepWhatsRaisedNotClaimable(tokenId); } uint256 amountToRefund = 0; @@ -522,7 +542,7 @@ contract KeepWhatsRaised is function claimTip() external onlyPlatformAdmin(PLATFORM_HASH) - currentTimeIsGreater(INFO.getDeadline()) + currentTimeIsGreater(getDeadline()) whenCampaignNotPaused whenNotPaused { @@ -549,7 +569,7 @@ contract KeepWhatsRaised is whenCampaignNotPaused whenNotPaused { - if (block.timestamp < (INFO.getDeadline() + s_config.withdrawalDelay) || block.timestamp < (s_cancellationTime + s_config.withdrawalDelay)) { + if (block.timestamp < (getDeadline() + s_config.withdrawalDelay) || block.timestamp < (s_cancellationTime + s_config.withdrawalDelay)) { revert KeepWhatsRaisedNotClaimableAdmin(); } From 7c6ce308fa5ca649485b9c8d96648d615fe92590 Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Mon, 5 May 2025 17:21:04 +0600 Subject: [PATCH 12/63] Add update deadline and goal amount functionality --- src/treasuries/KeepWhatsRaised.sol | 51 ++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index 68d86d0a..dc9965bf 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -116,6 +116,14 @@ contract KeepWhatsRaised is */ event RefundClaimed(uint256 tokenId, uint256 refundAmount, address claimer); + /** + * @dev Emitted when the deadline of the campaign is updated. + * @param newDeadline The new deadline. + */ + event KeepWhatsRaisedDeadlineUpdated(uint256 newDeadline); + + event KeepWhatsRaisedGoalAmountUpdated(uint256 newGoalAmount); + /** * @dev Emitted when an unauthorized action is attempted. */ @@ -147,7 +155,10 @@ contract KeepWhatsRaised is error KeepWhatsRaisedAlreadyClaimed(); error KeepWhatsRaisedNotClaimable(uint256 tokenId); + error KeepWhatsRaisedNotClaimableAdmin(); + + error KeepWhatsRaisedConfigLocked(); modifier withdrawalEnabled() { if(!s_isWithdrawalApproved){ @@ -156,6 +167,13 @@ contract KeepWhatsRaised is _; } + modifier onlyBeforeConfigLock() { + if(block.timestamp > s_campaignData.deadline - s_config.configLockPeriod){ + revert KeepWhatsRaisedConfigLocked(); + } + _; + } + /** * @dev Constructor for the KeepWhatsRaised contract. */ @@ -257,6 +275,39 @@ contract KeepWhatsRaised is ); } + function updateDeadline( + uint256 deadline + ) + external + onlyPlatformAdmin(PLATFORM_HASH) + onlyBeforeConfigLock + whenNotPaused + whenNotCancelled + { + if (deadline <= getLaunchTime()) { + revert KeepWhatsRaisedInvalidInput(); + } + + s_campaignData.deadline = deadline; + emit KeepWhatsRaisedDeadlineUpdated(deadline); + } + + function updateGoalAmount( + uint256 goalAmount + ) + external + onlyPlatformAdmin(PLATFORM_HASH) + onlyBeforeConfigLock + whenNotPaused + whenNotCancelled + { + if (goalAmount == 0) { + revert KeepWhatsRaisedInvalidInput(); + } + s_campaignData.goalAmount = goalAmount; + emit KeepWhatsRaisedGoalAmountUpdated(goalAmount); + } + /** * @notice Adds multiple rewards in a batch. * @dev This function allows for both reward tiers and non-reward tiers. From 805e6992582d41c66a787497edd741fb70b71dc5 Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Tue, 6 May 2025 13:11:00 +0600 Subject: [PATCH 13/63] Fix the refund and fund claiming time logic --- src/treasuries/KeepWhatsRaised.sol | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index dc9965bf..c1acad12 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -546,9 +546,16 @@ contract KeepWhatsRaised is whenCampaignNotPaused whenNotPaused { - if (block.timestamp > (getDeadline() + s_config.refundDelay) || block.timestamp > (s_cancellationTime + s_config.refundDelay)) { + uint256 deadline = getDeadline(); + + bool canceledAndExpired = s_cancellationTime > 0 && block.timestamp > s_cancellationTime + s_config.refundDelay; + bool tooEarly = block.timestamp <= deadline; + bool tooLate = block.timestamp > deadline + s_config.refundDelay; + + if (canceledAndExpired || tooEarly || tooLate) { revert KeepWhatsRaisedNotClaimable(tokenId); } + uint256 amountToRefund = 0; uint256 pledgedAmount = s_tokenToPledgedAmount[tokenId]; uint256 availablePledgedAmount = s_availablePledgedAmount; @@ -620,7 +627,10 @@ contract KeepWhatsRaised is whenCampaignNotPaused whenNotPaused { - if (block.timestamp < (getDeadline() + s_config.withdrawalDelay) || block.timestamp < (s_cancellationTime + s_config.withdrawalDelay)) { + uint256 cancelLimit = s_cancellationTime + s_config.withdrawalDelay; + uint256 deadlineLimit = getDeadline() + s_config.withdrawalDelay; + + if ((s_cancellationTime > 0 && block.timestamp <= cancelLimit) || block.timestamp <= deadlineLimit) { revert KeepWhatsRaisedNotClaimableAdmin(); } From 757e2e15735899f477d2ef3b8e019e052f0bc01a Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Tue, 6 May 2025 13:17:48 +0600 Subject: [PATCH 14/63] Update claim refund - Add all-or-nothing refund, and remove partial refund support --- src/treasuries/KeepWhatsRaised.sol | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index c1acad12..bbf9f655 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -556,16 +556,10 @@ contract KeepWhatsRaised is revert KeepWhatsRaisedNotClaimable(tokenId); } - uint256 amountToRefund = 0; - uint256 pledgedAmount = s_tokenToPledgedAmount[tokenId]; + uint256 amountToRefund = s_tokenToPledgedAmount[tokenId]; uint256 availablePledgedAmount = s_availablePledgedAmount; - if(availablePledgedAmount < pledgedAmount){ - amountToRefund = availablePledgedAmount; - }else { - amountToRefund = pledgedAmount; - } - if (amountToRefund == 0) { + if (amountToRefund == 0 || availablePledgedAmount < amountToRefund) { revert KeepWhatsRaisedNotClaimable(tokenId); } s_tokenToTotalCollectedAmount[tokenId] -= amountToRefund; From 8958d70c9acaf67fc633752e9ded49dc48dad4b0 Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Tue, 6 May 2025 16:21:16 +0600 Subject: [PATCH 15/63] Fix withdrawal fee calculation --- src/treasuries/KeepWhatsRaised.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index bbf9f655..e44b4f47 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -499,7 +499,7 @@ contract KeepWhatsRaised is } //Other Fees - uint256 fee = (s_availablePledgedAmount * INFO.getProtocolFeePercent()) / + uint256 fee = (withdrawalAmount * INFO.getProtocolFeePercent()) / PERCENT_DIVIDER; s_protocolFee += fee; totalFee += fee; @@ -507,7 +507,7 @@ contract KeepWhatsRaised is //Gross Percentage Fee Calculation uint256 len = s_feeKeys.grossPercentageFeeKeys.length; for(uint256 i = 0; i < len; i++){ - fee = (s_availablePledgedAmount * uint256(s_feeKeys.grossPercentageFeeKeys[i])) / + fee = (withdrawalAmount * uint256(s_feeKeys.grossPercentageFeeKeys[i])) / PERCENT_DIVIDER; s_platformFee += fee; totalFee += fee; From 7fdfa653fb755592e4bfbb63062cb19c265f14cc Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Tue, 6 May 2025 19:34:10 +0600 Subject: [PATCH 16/63] Fix withdrawal; Add NatSpec doc; Add `getAvailableRaisedAmount` function --- src/treasuries/KeepWhatsRaised.sol | 181 ++++++++++++++++++++++++++++- 1 file changed, 177 insertions(+), 4 deletions(-) diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index e44b4f47..45f4bd41 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -36,16 +36,38 @@ contract KeepWhatsRaised is // Counters for token IDs and rewards Counters.Counter private s_tokenIdCounter; Counters.Counter private s_rewardCounter; + + /** + * @dev Represents keys used to reference different fee configurations. + * These keys are typically used to look up fee values stored in `s_platformData`. + */ struct FeeKeys { + /// @dev Key for a flat fee applied to an operation. bytes32 flatFeeKey; + + /// @dev Key for a cumulative flat fee, potentially across multiple actions. bytes32 cumulativeFlatFeeKey; + + /// @dev Keys for gross percentage-based fees (calculated before deductions). bytes32[] grossPercentageFeeKeys; + + /// @dev Keys for net percentage-based fees (calculated after deductions). bytes32[] netPercentageFeeKeys; } + /** + * @dev System configuration parameters related to withdrawal and refund behavior. + */ struct Config { + /// @dev The minimum withdrawal amount required to qualify for fee exemption. uint256 minimumWithdrawalForFeeExemption; + + /// @dev Time delay (in timestamp) enforced before a withdrawal can be completed. uint256 withdrawalDelay; + + /// @dev Time delay (in timestamp) before a refund becomes claimable or processed. uint256 refundDelay; + + /// @dev Duration (in timestamp) for which config changes are locked to prevent immediate updates. uint256 configLockPeriod; } @@ -94,18 +116,41 @@ contract KeepWhatsRaised is */ event RewardRemoved(bytes32 indexed rewardName); + /// @dev Emitted when withdrawal functionality has been approved by the platform admin. event WithdrawalApproved(); + /** + * @dev Emitted when the treasury configuration is updated. + * @param config The updated configuration parameters (e.g., delays, exemptions). + * @param campaignData The campaign-related data associated with the treasury setup. + * @param feeKeys The set of keys used to determine applicable fees. + */ event TreasuryConfigured( Config config, CampaignData campaignData, FeeKeys feeKeys ); + /** + * @dev Emitted when a withdrawal is successfully processed along with the applied fee. + * @param to The recipient address receiving the funds. + * @param amount The total amount withdrawn (excluding fee). + * @param fee The fee amount deducted from the withdrawal. + */ event WithdrawalWithFeeSuccessful(address to, uint256 amount, uint256 fee); + /** + * @dev Emitted when a tip is claimed from the contract. + * @param amount The amount of tip claimed. + * @param claimer The address that claimed the tip. + */ event TipClaimed(uint256 amount, address claimer); + /** + * @dev Emitted when campaign or user's remaining funds are successfully claimed by the platform admin. + * @param amount The amount of funds claimed. + * @param claimer The address that claimed the funds. + */ event FundClaimed(uint256 amount, address claimer); /** @@ -122,6 +167,10 @@ contract KeepWhatsRaised is */ event KeepWhatsRaisedDeadlineUpdated(uint256 newDeadline); + /** + * @dev Emitted when the goal amount for a campaign is updated. + * @param newGoalAmount The new goal amount set for the campaign. + */ event KeepWhatsRaisedGoalAmountUpdated(uint256 newGoalAmount); /** @@ -144,22 +193,49 @@ contract KeepWhatsRaised is */ error KeepWhatsRaisedDisabled(); + /** + * @dev Emitted when any functionality is already enabled and cannot be re-enabled. + */ error KeepWhatsRaisedAlreadyEnabled(); - error KeepWhatsRaisedInvalidKey(); - + /** + * @dev Emitted when a withdrawal attempt exceeds the available funds after accounting for the fee. + * @param availableAmount The maximum amount that can be withdrawn. + * @param withdrawalAmount The attempted withdrawal amount. + * @param fee The fee that would be applied to the withdrawal. + */ error KeepWhatsRaisedWithdrawalOverload(uint256 availableAmount, uint256 withdrawalAmount, uint256 fee); + /** + * @dev Emitted when a withdrawal has already been made and cannot be repeated. + */ error KeepWhatsRaisedAlreadyWithdrawn(); + /** + * @dev Emitted when funds or rewards have already been claimed for the given context. + */ error KeepWhatsRaisedAlreadyClaimed(); + /** + * @dev Emitted when a token or pledge is not eligible for claiming (e.g., claim period not reached or not valid). + * @param tokenId The ID of the token that was attempted to be claimed. + */ error KeepWhatsRaisedNotClaimable(uint256 tokenId); + /** + * @dev Emitted when an admin attempts to claim funds that are not yet claimable according to the rules. + */ error KeepWhatsRaisedNotClaimableAdmin(); + /** + * @dev Emitted when a configuration change is attempted during the lock period. + */ error KeepWhatsRaisedConfigLocked(); + /** + * @dev Ensures that withdrawals are currently enabled. + * Reverts with `KeepWhatsRaisedDisabled` if the withdrawal approval flag is not set. + */ modifier withdrawalEnabled() { if(!s_isWithdrawalApproved){ revert KeepWhatsRaisedDisabled(); @@ -167,6 +243,11 @@ contract KeepWhatsRaised is _; } + /** + * @dev Restricts execution to only occur before the configuration lock period. + * Reverts with `KeepWhatsRaisedConfigLocked` if called too close to or after the campaign deadline. + * The lock period is defined as the duration before the deadline during which configuration changes are not allowed. + */ modifier onlyBeforeConfigLock() { if(block.timestamp > s_campaignData.deadline - s_config.configLockPeriod){ revert KeepWhatsRaisedConfigLocked(); @@ -198,6 +279,9 @@ contract KeepWhatsRaised is return s_symbol; } + /** + * @notice Retrieves the withdrawal approval status. + */ function getWithdrawalApprovalStatus() public view returns (bool) { return s_isWithdrawalApproved; } @@ -223,18 +307,41 @@ contract KeepWhatsRaised is return s_pledgedAmount; } + /** + * @notice Retrieves the currently available raised amount in the treasury. + * @return The current available raised amount as a uint256 value. + */ + function getAvailableRaisedAmount() external view returns (uint256) { + return s_availablePledgedAmount; + } + + /** + * @notice Retrieves the campaign's launch time. + * @return The timestamp when the campaign was launched. + */ function getLaunchTime() public view returns (uint256) { return s_campaignData.launchTime; } + /** + * @notice Retrieves the campaign's deadline. + * @return The timestamp when the campaign ends. + */ function getDeadline() public view returns (uint256) { return s_campaignData.deadline; } + /** + * @notice Retrieves the campaign's funding goal amount. + * @return The funding goal amount of the campaign. + */ function getGoalAmount() external view returns (uint256) { return s_campaignData.goalAmount; } + /** + * @notice Approves the withdrawal of the treasury by the platform admin. + */ function approveWithdrawal() external onlyPlatformAdmin(PLATFORM_HASH) @@ -252,6 +359,15 @@ contract KeepWhatsRaised is emit WithdrawalApproved(); } + /** + * @dev Configures the treasury for a campaign by setting the system parameters, + * campaign-specific data, and fee configuration keys. + * + * @param config The configuration settings including withdrawal delay, refund delay, + * fee exemption threshold, and configuration lock period. + * @param campaignData The campaign-related metadata such as deadlines and funding goals. + * @param feeKeys The set of keys used to reference applicable flat and percentage-based fees. + */ function configureTreasury( Config memory config, CampaignData memory campaignData, @@ -275,6 +391,15 @@ contract KeepWhatsRaised is ); } + /** + * @dev Updates the campaign's deadline. + * + * @param deadline The new deadline timestamp for the campaign. + * + * Requirements: + * - Must be called before the configuration lock period (see `onlyBeforeConfigLock`). + * - The new deadline must be a future timestamp. + */ function updateDeadline( uint256 deadline ) @@ -292,6 +417,14 @@ contract KeepWhatsRaised is emit KeepWhatsRaisedDeadlineUpdated(deadline); } + /** + * @dev Updates the funding goal amount for the campaign. + * + * @param goalAmount The new goal amount. + * + * Requirements: + * - Must be called before the configuration lock period (see `onlyBeforeConfigLock`). + */ function updateGoalAmount( uint256 goalAmount ) @@ -454,6 +587,16 @@ contract KeepWhatsRaised is revert KeepWhatsRaisedDisabled(); } + /** + * @dev Allows a campaign owner or eligible party to withdraw a specified amount of funds. + * + * @param amount The amount to withdraw. + * + * Requirements: + * - Withdrawals must be approved (see `withdrawalEnabled` modifier). + * - Amount must not exceed the available balance after fees. + * - May apply and deduct a withdrawal fee. + */ function withdraw( uint256 amount ) @@ -507,7 +650,7 @@ contract KeepWhatsRaised is //Gross Percentage Fee Calculation uint256 len = s_feeKeys.grossPercentageFeeKeys.length; for(uint256 i = 0; i < len; i++){ - fee = (withdrawalAmount * uint256(s_feeKeys.grossPercentageFeeKeys[i])) / + fee = (withdrawalAmount * uint256(INFO.getPlatformData(s_feeKeys.grossPercentageFeeKeys[i]))) / PERCENT_DIVIDER; s_platformFee += fee; totalFee += fee; @@ -520,7 +663,8 @@ contract KeepWhatsRaised is uint256 availableBeforeNet = withdrawalAmount - totalFee; len = s_feeKeys.netPercentageFeeKeys.length; for(uint256 i = 0; i < len; i++){ - fee = (availableBeforeNet * uint256(s_feeKeys.netPercentageFeeKeys[i])) / + + fee = (availableBeforeNet * uint256(INFO.getPlatformData(s_feeKeys.netPercentageFeeKeys[i]))) / PERCENT_DIVIDER; s_platformFee += fee; totalFee += fee; @@ -538,6 +682,15 @@ contract KeepWhatsRaised is emit WithdrawalWithFeeSuccessful(recipient, withdrawalAmount, totalFee); } + /** + * @dev Allows a backer to claim a refund associated with a specific pledge (token ID). + * + * @param tokenId The ID of the token representing the backer's pledge. + * + * Requirements: + * - Refund delay must have passed. + * - The token must be eligible for a refund and not previously claimed. + */ function claimRefund( uint256 tokenId ) @@ -571,6 +724,12 @@ contract KeepWhatsRaised is emit RefundClaimed(tokenId, amountToRefund, msg.sender); } + /** + * @dev Disburses all accumulated fees to the appropriate fee collector or treasury. + * + * Requirements: + * - Only callable when fees are available. + */ function disburseFees() public override @@ -591,6 +750,13 @@ contract KeepWhatsRaised is emit FeesDisbursed(protocolShare, platformShare); } + /** + * @dev Allows an authorized claimer to collect tips contributed during the campaign. + * + * Requirements: + * - Caller must be authorized to claim tips. + * - Tip amount must be non-zero. + */ function claimTip() external onlyPlatformAdmin(PLATFORM_HASH) @@ -615,6 +781,13 @@ contract KeepWhatsRaised is emit TipClaimed(tip, platformAdmin); } + /** + * @dev Allows a campaign owner or authorized user to claim remaining campaign funds. + * + * Requirements: + * - Claim period must have started and funds must be available. + * - Cannot be previously claimed. + */ function claimFund() external onlyPlatformAdmin(PLATFORM_HASH) From fb8199ef9a5a7961f2536f98d06b029e261971f3 Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Tue, 6 May 2025 23:10:08 +0600 Subject: [PATCH 17/63] Fix refund, tip, and fund claiming time logic --- src/treasuries/KeepWhatsRaised.sol | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index 45f4bd41..350359ef 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -701,11 +701,11 @@ contract KeepWhatsRaised is { uint256 deadline = getDeadline(); - bool canceledAndExpired = s_cancellationTime > 0 && block.timestamp > s_cancellationTime + s_config.refundDelay; - bool tooEarly = block.timestamp <= deadline; - bool tooLate = block.timestamp > deadline + s_config.refundDelay; + bool isCancelled = s_cancellationTime > 0; + bool refundWindowFromDeadline = !isCancelled && block.timestamp > deadline && block.timestamp <= deadline + s_config.refundDelay; + bool refundWindowFromCancellation = isCancelled && block.timestamp <= s_cancellationTime + s_config.refundDelay; - if (canceledAndExpired || tooEarly || tooLate) { + if (!(refundWindowFromDeadline || refundWindowFromCancellation)) { revert KeepWhatsRaisedNotClaimable(tokenId); } @@ -760,10 +760,13 @@ contract KeepWhatsRaised is function claimTip() external onlyPlatformAdmin(PLATFORM_HASH) - currentTimeIsGreater(getDeadline()) whenCampaignNotPaused whenNotPaused { + if(s_cancellationTime == 0 && block.timestamp <= getDeadline()){ + revert KeepWhatsRaisedNotClaimableAdmin(); + } + if(s_tipClaimed){ revert KeepWhatsRaisedAlreadyClaimed(); } @@ -794,10 +797,11 @@ contract KeepWhatsRaised is whenCampaignNotPaused whenNotPaused { + bool isCancelled = s_cancellationTime > 0; uint256 cancelLimit = s_cancellationTime + s_config.withdrawalDelay; uint256 deadlineLimit = getDeadline() + s_config.withdrawalDelay; - if ((s_cancellationTime > 0 && block.timestamp <= cancelLimit) || block.timestamp <= deadlineLimit) { + if ((isCancelled && block.timestamp <= cancelLimit) || (!isCancelled && block.timestamp <= deadlineLimit)) { revert KeepWhatsRaisedNotClaimableAdmin(); } From 2ad54e2b1f75c91f33eb1402c7b9321461ed8133 Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Thu, 8 May 2025 00:58:49 +0600 Subject: [PATCH 18/63] Update `KeepWhatsRaised` treasury - Add indexing for selected events - Remove redundant storage variable - Reorder _pledge function - Perform all checks first - Update state variables - Only then interact with external contracts (TOKEN transfer) - Remove unnecessary storage use --- src/treasuries/KeepWhatsRaised.sol | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index 350359ef..a5b22de6 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -24,8 +24,6 @@ contract KeepWhatsRaised is using Counters for Counters.Counter; using SafeERC20 for IERC20; - // Mapping to store the total collected amount (pledged amount and tip amount) per token ID - mapping(uint256 => uint256) private s_tokenToTotalCollectedAmount; // Mapping to store the pledged amount per token ID mapping(uint256 => uint256) private s_tokenToPledgedAmount; // Mapping to store the tipped amount per token ID @@ -137,21 +135,21 @@ contract KeepWhatsRaised is * @param amount The total amount withdrawn (excluding fee). * @param fee The fee amount deducted from the withdrawal. */ - event WithdrawalWithFeeSuccessful(address to, uint256 amount, uint256 fee); + event WithdrawalWithFeeSuccessful(address indexed to, uint256 amount, uint256 fee); /** * @dev Emitted when a tip is claimed from the contract. * @param amount The amount of tip claimed. * @param claimer The address that claimed the tip. */ - event TipClaimed(uint256 amount, address claimer); + event TipClaimed(uint256 amount, address indexed claimer); /** * @dev Emitted when campaign or user's remaining funds are successfully claimed by the platform admin. * @param amount The amount of funds claimed. * @param claimer The address that claimed the funds. */ - event FundClaimed(uint256 amount, address claimer); + event FundClaimed(uint256 amount, address indexed claimer); /** * @dev Emitted when a refund is claimed. @@ -159,7 +157,7 @@ contract KeepWhatsRaised is * @param refundAmount The refund amount claimed. * @param claimer The address of the claimer. */ - event RefundClaimed(uint256 tokenId, uint256 refundAmount, address claimer); + event RefundClaimed(uint256 indexed tokenId, uint256 refundAmount, address indexed claimer); /** * @dev Emitted when the deadline of the campaign is updated. @@ -537,7 +535,7 @@ contract KeepWhatsRaised is { uint256 tokenId = s_tokenIdCounter.current(); uint256 rewardLen = reward.length; - Reward storage tempReward = s_reward[reward[0]]; + Reward memory tempReward = s_reward[reward[0]]; if ( backer == address(0) || rewardLen > s_rewardCounter.current() || @@ -715,7 +713,6 @@ contract KeepWhatsRaised is if (amountToRefund == 0 || availablePledgedAmount < amountToRefund) { revert KeepWhatsRaisedNotClaimable(tokenId); } - s_tokenToTotalCollectedAmount[tokenId] -= amountToRefund; s_tokenToPledgedAmount[tokenId] -= amountToRefund; s_pledgedAmount -= amountToRefund; s_availablePledgedAmount -= amountToRefund; @@ -859,15 +856,14 @@ contract KeepWhatsRaised is bytes32[] memory rewards ) private { uint256 totalAmount = pledgeAmount + tip; - TOKEN.safeTransferFrom(backer, address(this), totalAmount); - s_tokenIdCounter.increment(); - _safeMint(backer, tokenId, abi.encodePacked(backer, reward)); s_tokenToPledgedAmount[tokenId] = pledgeAmount; - s_tokenToTotalCollectedAmount[tokenId] = totalAmount; s_tokenToTippedAmount[tokenId] = tip; s_pledgedAmount += pledgeAmount; s_availablePledgedAmount += pledgeAmount; s_tip += tip; + TOKEN.safeTransferFrom(backer, address(this), totalAmount); + s_tokenIdCounter.increment(); + _safeMint(backer, tokenId, abi.encodePacked(backer, reward)); emit Receipt( backer, reward, From 9f5aa88b8bc90cc1db07a720180d2d3626c53346 Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Thu, 8 May 2025 15:10:56 +0600 Subject: [PATCH 19/63] Add deployment scripts for `KeepWhatsRaised` treasury --- script/DeployAllKeepWhatsRaisedAndSetup.s.sol | 400 ++++++++++++++++++ script/DeployKeepWhatsRaised.s.sol | 32 ++ 2 files changed, 432 insertions(+) create mode 100644 script/DeployAllKeepWhatsRaisedAndSetup.s.sol create mode 100644 script/DeployKeepWhatsRaised.s.sol diff --git a/script/DeployAllKeepWhatsRaisedAndSetup.s.sol b/script/DeployAllKeepWhatsRaisedAndSetup.s.sol new file mode 100644 index 00000000..465cdccc --- /dev/null +++ b/script/DeployAllKeepWhatsRaisedAndSetup.s.sol @@ -0,0 +1,400 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.20; + +import "forge-std/Script.sol"; +import "forge-std/console2.sol"; +import "src/TestUSD.sol"; +import "src/GlobalParams.sol"; +import "src/CampaignInfoFactory.sol"; +import "src/CampaignInfo.sol"; +import "src/TreasuryFactory.sol"; +import "src/treasuries/KeepWhatsRaised.sol"; + +/** + * @notice Script to deploy and setup all needed contracts for the keepWhatsRaised + */ +contract DeployAllKeepWhatsRaisedAndSetup is Script { + // Customizable values (set through environment variables) + bytes32 platformHash; + uint256 protocolFeePercent; + uint256 platformFeePercent; + uint256 tokenMintAmount; + bool simulate; + + // Contract addresses + address testUSD; + address globalParams; + address campaignInfo; + address treasuryFactory; + address campaignInfoFactory; + address keepWhatsRaisedImplementation; + + // User addresses + address deployerAddress; + address finalProtocolAdmin; + address finalPlatformAdmin; + address backer1; + address backer2; + + // Flags to track what was completed + bool platformEnlisted = false; + bool implementationRegistered = false; + bool implementationApproved = false; + bool adminRightsTransferred = false; + bool platformDataKeyAdded = false; + + // Flags for contract deployment or reuse + bool testUsdDeployed = false; + bool globalParamsDeployed = false; + bool treasuryFactoryDeployed = false; + bool campaignInfoFactoryDeployed = false; + bool keepWhatsRaisedDeployed = false; + + //Treasury Keys + bytes32 PLATFORM_FEE_KEY; + bytes32 FLAT_FEE_KEY; + bytes32 CUMULATIVE_FLAT_FEE_KEY; + bytes32 PAYMENT_GATEWAY_FEE_KEY; + bytes32 COLUMBIAN_CREATOR_TAX_KEY; + + // Configure parameters based on environment variables + function setupParams() internal { + // Get customizable values + string memory platformName = vm.envOr("PLATFORM_NAME", string("VAKI")); + platformHash = keccak256(abi.encodePacked(platformName)); + protocolFeePercent = vm.envOr("PROTOCOL_FEE_PERCENT", uint256(100)); // Default 1% + platformFeePercent = vm.envOr("PLATFORM_FEE_PERCENT", uint256(600)); // Default 6% + tokenMintAmount = vm.envOr("TOKEN_MINT_AMOUNT", uint256(10000000e18)); + simulate = vm.envOr("SIMULATE", false); + + // Get user addresses + uint256 deployerKey = vm.envUint("PRIVATE_KEY"); + deployerAddress = vm.addr(deployerKey); + + // These are the final admin addresses that will receive control + finalProtocolAdmin = vm.envOr("PROTOCOL_ADMIN_ADDRESS", deployerAddress); + finalPlatformAdmin = vm.envOr("PLATFORM_ADMIN_ADDRESS", deployerAddress); + backer1 = vm.envOr("BACKER1_ADDRESS", address(0)); + backer2 = vm.envOr("BACKER2_ADDRESS", address(0)); + + // Check for existing contract addresses + testUSD = vm.envOr("TEST_USD_ADDRESS", address(0)); + globalParams = vm.envOr("GLOBAL_PARAMS_ADDRESS", address(0)); + treasuryFactory = vm.envOr("TREASURY_FACTORY_ADDRESS", address(0)); + campaignInfoFactory = vm.envOr("CAMPAIGN_INFO_FACTORY_ADDRESS", address(0)); + keepWhatsRaisedImplementation = vm.envOr("KEEP_WHATS_RAISED_IMPLEMENTATION_ADDRESS", address(0)); + + //Get Treasury Keys + PLATFORM_FEE_KEY = keccak256(abi.encodePacked("platformFee")); + FLAT_FEE_KEY = keccak256(abi.encodePacked("flatFee")); + CUMULATIVE_FLAT_FEE_KEY = keccak256(abi.encodePacked("cumulativeFlatFee")); + PAYMENT_GATEWAY_FEE_KEY = keccak256(abi.encodePacked("paymentGatewayFee")); + COLUMBIAN_CREATOR_TAX_KEY = keccak256(abi.encodePacked("columbianCreatorTax")); + + console2.log("Using platform hash for:", platformName); + console2.log("Protocol fee percent:", protocolFeePercent); + console2.log("Platform fee percent:", platformFeePercent); + console2.log("Simulation mode:", simulate); + console2.log("Deployer address:", deployerAddress); + console2.log("Final protocol admin:", finalProtocolAdmin); + console2.log("Final platform admin:", finalPlatformAdmin); + } + + // Deploy or reuse contracts + function deployContracts() internal { + console2.log("Setting up contracts..."); + + // Deploy or reuse TestUSD + if (testUSD == address(0)) { + testUSD = address(new TestUSD()); + testUsdDeployed = true; + console2.log("TestUSD deployed at:", testUSD); + } else { + console2.log("Reusing TestUSD at:", testUSD); + } + + // Deploy or reuse GlobalParams + if (globalParams == address(0)) { + globalParams = address(new GlobalParams( + deployerAddress, // Initially deployer is protocol admin + testUSD, + protocolFeePercent + )); + globalParamsDeployed = true; + console2.log("GlobalParams deployed at:", globalParams); + } else { + console2.log("Reusing GlobalParams at:", globalParams); + } + + // We need at least TestUSD and GlobalParams to continue + require(testUSD != address(0), "TestUSD address is required"); + require(globalParams != address(0), "GlobalParams address is required"); + + // Deploy CampaignInfo implementation if needed for new deployments + if (campaignInfoFactory == address(0)) { + campaignInfo = address(new CampaignInfo(address(this))); + console2.log("CampaignInfo deployed at:", campaignInfo); + } + + // Deploy or reuse TreasuryFactory + if (treasuryFactory == address(0)) { + treasuryFactory = address(new TreasuryFactory(GlobalParams(globalParams))); + treasuryFactoryDeployed = true; + console2.log("TreasuryFactory deployed at:", treasuryFactory); + } else { + console2.log("Reusing TreasuryFactory at:", treasuryFactory); + } + + // Deploy or reuse CampaignInfoFactory + if (campaignInfoFactory == address(0)) { + campaignInfoFactory = address(new CampaignInfoFactory( + GlobalParams(globalParams), + campaignInfo + )); + CampaignInfoFactory(campaignInfoFactory)._initialize( + treasuryFactory, + globalParams + ); + campaignInfoFactoryDeployed = true; + console2.log("CampaignInfoFactory deployed and initialized at:", campaignInfoFactory); + } else { + console2.log("Reusing CampaignInfoFactory at:", campaignInfoFactory); + } + + // Deploy or reuse KeepWhatsRaised implementation + if (keepWhatsRaisedImplementation == address(0)) { + keepWhatsRaisedImplementation = address(new KeepWhatsRaised()); + keepWhatsRaisedDeployed = true; + console2.log("KeepWhatsRaised implementation deployed at:", keepWhatsRaisedImplementation); + } else { + console2.log("Reusing KeepWhatsRaised implementation at:", keepWhatsRaisedImplementation); + } + } + + // Setup steps when deployer has all roles + function enlistPlatform() internal { + // Skip if we didn't deploy GlobalParams (assuming it's already set up) + if (!globalParamsDeployed) { + console2.log("Skipping enlistPlatform - using existing GlobalParams"); + platformEnlisted = true; + return; + } + + console2.log("Setting up: enlistPlatform"); + // Only use startPrank in simulation mode + if (simulate) { + vm.startPrank(deployerAddress); + } + + GlobalParams(globalParams).enlistPlatform( + platformHash, + deployerAddress, // Initially deployer is platform admin + platformFeePercent + ); + + if (simulate) { + vm.stopPrank(); + } + platformEnlisted = true; + console2.log("Platform enlisted successfully"); + } + + function registerTreasuryImplementation() internal { + // Skip if we didn't deploy TreasuryFactory (assuming it's already set up) + if (!treasuryFactoryDeployed || !keepWhatsRaisedDeployed) { + console2.log("Skipping registerTreasuryImplementation - using existing contracts"); + implementationRegistered = true; + return; + } + + console2.log("Setting up: registerTreasuryImplementation"); + // Only use startPrank in simulation mode + if (simulate) { + vm.startPrank(deployerAddress); + } + + TreasuryFactory(treasuryFactory).registerTreasuryImplementation( + platformHash, + 0, // Implementation ID + keepWhatsRaisedImplementation + ); + + if (simulate) { + vm.stopPrank(); + } + implementationRegistered = true; + console2.log("Treasury implementation registered successfully"); + } + + function approveTreasuryImplementation() internal { + // Skip if we didn't deploy TreasuryFactory (assuming it's already set up) + if (!treasuryFactoryDeployed || !keepWhatsRaisedDeployed) { + console2.log("Skipping approveTreasuryImplementation - using existing contracts"); + implementationApproved = true; + return; + } + + console2.log("Setting up: approveTreasuryImplementation"); + // Only use startPrank in simulation mode + if (simulate) { + vm.startPrank(deployerAddress); + } + + TreasuryFactory(treasuryFactory).approveTreasuryImplementation( + platformHash, + 0 // Implementation ID + ); + + if (simulate) { + vm.stopPrank(); + } + implementationApproved = true; + console2.log("Treasury implementation approved successfully"); + } + + function addPlatformDataKey() internal { + + console2.log("Setting up: addPlatformDataKey"); + + // Only use startPrank in simulation mode + if (simulate) { + vm.startPrank(deployerAddress); + } + + GlobalParams(globalParams).addPlatformData( + platformHash, + PLATFORM_FEE_KEY + ); + GlobalParams(globalParams).addPlatformData( + platformHash, + FLAT_FEE_KEY + ); + GlobalParams(globalParams).addPlatformData( + platformHash, + CUMULATIVE_FLAT_FEE_KEY + ); + GlobalParams(globalParams).addPlatformData( + platformHash, + PAYMENT_GATEWAY_FEE_KEY + ); + GlobalParams(globalParams).addPlatformData( + platformHash, + COLUMBIAN_CREATOR_TAX_KEY + ); + + if (simulate) { + vm.stopPrank(); + } + platformDataKeyAdded = true; + console2.log("Platform Data Key Added successfully"); + } + + function mintTokens() internal { + // Only mint tokens if we deployed TestUSD + if (!testUsdDeployed) { + console2.log("Skipping mintTokens - using existing TestUSD"); + return; + } + + if (backer1 != address(0) && backer2 != address(0)) { + console2.log("Minting tokens to test backers"); + TestUSD(testUSD).mint(backer1, tokenMintAmount); + if (backer1 != backer2) { + TestUSD(testUSD).mint(backer2, tokenMintAmount); + } + console2.log("Tokens minted successfully"); + } + } + + // Transfer admin rights to final addresses + function transferAdminRights() internal { + // Skip if we didn't deploy GlobalParams (assuming it's already set up) + if (!globalParamsDeployed) { + console2.log("Skipping transferAdminRights - using existing GlobalParams"); + adminRightsTransferred = true; + return; + } + + console2.log("Transferring admin rights to final addresses..."); + + // Only transfer if the final addresses are different from deployer + if (finalProtocolAdmin != deployerAddress) { + console2.log("Transferring protocol admin rights to:", finalProtocolAdmin); + GlobalParams(globalParams).updateProtocolAdminAddress(finalProtocolAdmin); + } + + if (finalPlatformAdmin != deployerAddress) { + console2.log("Updating platform admin address for platform hash:", vm.toString(platformHash)); + GlobalParams(globalParams).updatePlatformAdminAddress(platformHash, finalPlatformAdmin); + } + + adminRightsTransferred = true; + console2.log("Admin rights transferred successfully"); + } + + function run() external { + // Load configuration + setupParams(); + + uint256 deployerKey = vm.envUint("PRIVATE_KEY"); + + // Start broadcast with deployer key + vm.startBroadcast(deployerKey); + + // Deploy or reuse contracts + deployContracts(); + + // Setup the protocol with individual transactions in the correct order + // Since deployer is both protocol and platform admin initially, we can do all steps + enlistPlatform(); + registerTreasuryImplementation(); + approveTreasuryImplementation(); + addPlatformDataKey(); + + // Mint tokens if needed + mintTokens(); + + // Finally, transfer admin rights to the final addresses + transferAdminRights(); + + // Stop broadcast + vm.stopBroadcast(); + + // Output summary + console2.log("\n--- Deployment & Setup Summary ---"); + console2.log("Platform Name Hash:", vm.toString(platformHash)); + console2.log("TEST_USD_ADDRESS:", testUSD); + console2.log("GLOBAL_PARAMS_ADDRESS:", globalParams); + if (campaignInfo != address(0)) { + console2.log("CAMPAIGN_INFO_ADDRESS:", campaignInfo); + } + console2.log("TREASURY_FACTORY_ADDRESS:", treasuryFactory); + console2.log("CAMPAIGN_INFO_FACTORY_ADDRESS:", campaignInfoFactory); + console2.log("KEEP_WHATS_RAISED_IMPLEMENTATION_ADDRESS:", keepWhatsRaisedImplementation); + console2.log("Protocol Admin:", finalProtocolAdmin); + console2.log("Platform Admin:", finalPlatformAdmin); + + if (backer1 != address(0)) { + console2.log("Backer1 (tokens minted):", backer1); + } + if (backer2 != address(0) && backer1 != backer2) { + console2.log("Backer2 (tokens minted):", backer2); + } + + console2.log("\nDeployment status:"); + console2.log("- TestUSD:", testUsdDeployed ? "Newly deployed" : "Reused existing"); + console2.log("- GlobalParams:", globalParamsDeployed ? "Newly deployed" : "Reused existing"); + console2.log("- TreasuryFactory:", treasuryFactoryDeployed ? "Newly deployed" : "Reused existing"); + console2.log("- CampaignInfoFactory:", campaignInfoFactoryDeployed ? "Newly deployed" : "Reused existing"); + console2.log("- KeepWhatsRaised Implementation:", keepWhatsRaisedDeployed ? "Newly deployed" : "Reused existing"); + + console2.log("\nSetup steps:"); + console2.log("1. Platform enlisted:", platformEnlisted); + console2.log("2. Treasury implementation registered:", implementationRegistered); + console2.log("3. Treasury implementation approved:", implementationApproved); + console2.log("4. Admin rights transferred:", adminRightsTransferred); + console2.log("5. Added Platform Data Key:", platformDataKeyAdded); + + console2.log("\nDeployment and setup completed successfully!"); + } +} \ No newline at end of file diff --git a/script/DeployKeepWhatsRaised.s.sol b/script/DeployKeepWhatsRaised.s.sol new file mode 100644 index 00000000..ef1cfd9b --- /dev/null +++ b/script/DeployKeepWhatsRaised.s.sol @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.20; + +import "forge-std/Script.sol"; +import "forge-std/console.sol"; +import {KeepWhatsRaised} from "src/treasuries/KeepWhatsRaised.sol"; + +contract DeployKeepWhatsRaisedImplementation is Script { + function deploy() public returns (address) { + console.log("Deploying KeepWhatsRaisedImplementation..."); + KeepWhatsRaised KeepWhatsRaisedImplementation = new KeepWhatsRaised(); + console.log("KeepWhatsRaisedImplementation deployed at:", address(KeepWhatsRaisedImplementation)); + return address(KeepWhatsRaisedImplementation); + } + + function run() external { + uint256 deployerKey = vm.envUint("PRIVATE_KEY"); + bool simulate = vm.envOr("SIMULATE", false); + + if (!simulate) { + vm.startBroadcast(deployerKey); + } + + address implementationAddress = deploy(); + + if (!simulate) { + vm.stopBroadcast(); + } + + console.log("KEEP_WHATS_RAISED_IMPLEMENTATION_ADDRESS", implementationAddress); + } +} \ No newline at end of file From ff974998aaf8cf80aa3d4f8539e1a0a81932d45d Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Tue, 27 May 2025 12:14:07 +0600 Subject: [PATCH 20/63] Fix `KeepWhatsRaised` deployment script --- ...=> DeployAllAndSetupKeepWhatsRaised.s.sol} | 83 +++++++++++-------- 1 file changed, 49 insertions(+), 34 deletions(-) rename script/{DeployAllKeepWhatsRaisedAndSetup.s.sol => DeployAllAndSetupKeepWhatsRaised.s.sol} (85%) diff --git a/script/DeployAllKeepWhatsRaisedAndSetup.s.sol b/script/DeployAllAndSetupKeepWhatsRaised.s.sol similarity index 85% rename from script/DeployAllKeepWhatsRaisedAndSetup.s.sol rename to script/DeployAllAndSetupKeepWhatsRaised.s.sol index 465cdccc..b50b1653 100644 --- a/script/DeployAllKeepWhatsRaisedAndSetup.s.sol +++ b/script/DeployAllAndSetupKeepWhatsRaised.s.sol @@ -1,19 +1,19 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; -import "forge-std/Script.sol"; -import "forge-std/console2.sol"; -import "src/TestUSD.sol"; -import "src/GlobalParams.sol"; -import "src/CampaignInfoFactory.sol"; -import "src/CampaignInfo.sol"; -import "src/TreasuryFactory.sol"; -import "src/treasuries/KeepWhatsRaised.sol"; +import {Script} from "forge-std/Script.sol"; +import {console2} from "forge-std/console2.sol"; +import {TestToken} from "../test/mocks/TestToken.sol"; +import {GlobalParams} from "src/GlobalParams.sol"; +import {CampaignInfoFactory} from "src/CampaignInfoFactory.sol"; +import {CampaignInfo} from "src/CampaignInfo.sol"; +import {TreasuryFactory} from "src/TreasuryFactory.sol"; +import {KeepWhatsRaised} from "src/treasuries/KeepWhatsRaised.sol"; /** * @notice Script to deploy and setup all needed contracts for the keepWhatsRaised */ -contract DeployAllKeepWhatsRaisedAndSetup is Script { +contract DeployAllAndSetupKeepWhatsRaised is Script { // Customizable values (set through environment variables) bytes32 platformHash; uint256 protocolFeePercent; @@ -22,7 +22,7 @@ contract DeployAllKeepWhatsRaisedAndSetup is Script { bool simulate; // Contract addresses - address testUSD; + address testToken; address globalParams; address campaignInfo; address treasuryFactory; @@ -44,7 +44,7 @@ contract DeployAllKeepWhatsRaisedAndSetup is Script { bool platformDataKeyAdded = false; // Flags for contract deployment or reuse - bool testUsdDeployed = false; + bool testTokenDeployed = false; bool globalParamsDeployed = false; bool treasuryFactoryDeployed = false; bool campaignInfoFactoryDeployed = false; @@ -78,18 +78,29 @@ contract DeployAllKeepWhatsRaisedAndSetup is Script { backer2 = vm.envOr("BACKER2_ADDRESS", address(0)); // Check for existing contract addresses - testUSD = vm.envOr("TEST_USD_ADDRESS", address(0)); + testToken = vm.envOr("TEST_USD_ADDRESS", address(0)); globalParams = vm.envOr("GLOBAL_PARAMS_ADDRESS", address(0)); treasuryFactory = vm.envOr("TREASURY_FACTORY_ADDRESS", address(0)); campaignInfoFactory = vm.envOr("CAMPAIGN_INFO_FACTORY_ADDRESS", address(0)); keepWhatsRaisedImplementation = vm.envOr("KEEP_WHATS_RAISED_IMPLEMENTATION_ADDRESS", address(0)); //Get Treasury Keys - PLATFORM_FEE_KEY = keccak256(abi.encodePacked("platformFee")); - FLAT_FEE_KEY = keccak256(abi.encodePacked("flatFee")); - CUMULATIVE_FLAT_FEE_KEY = keccak256(abi.encodePacked("cumulativeFlatFee")); - PAYMENT_GATEWAY_FEE_KEY = keccak256(abi.encodePacked("paymentGatewayFee")); - COLUMBIAN_CREATOR_TAX_KEY = keccak256(abi.encodePacked("columbianCreatorTax")); + PLATFORM_FEE_KEY = bytes32("platformFee"); + FLAT_FEE_KEY = bytes32("flatFee"); + CUMULATIVE_FLAT_FEE_KEY = bytes32("cumulativeFlatFee"); + PAYMENT_GATEWAY_FEE_KEY = bytes32("paymentGatewayFee"); + COLUMBIAN_CREATOR_TAX_KEY = bytes32("columbianCreatorTax"); + + console2.log("Platform Fee Key:"); + console2.logBytes32(PLATFORM_FEE_KEY); + console2.log("Flat Fee Key:"); + console2.logBytes32(FLAT_FEE_KEY); + console2.log("Cumulative Fee Key:"); + console2.logBytes32(CUMULATIVE_FLAT_FEE_KEY); + console2.log("Payment Gateway Fee Key:"); + console2.logBytes32(PAYMENT_GATEWAY_FEE_KEY); + console2.log("Columbian Creator Tax Key:"); + console2.logBytes32(COLUMBIAN_CREATOR_TAX_KEY); console2.log("Using platform hash for:", platformName); console2.log("Protocol fee percent:", protocolFeePercent); @@ -104,20 +115,24 @@ contract DeployAllKeepWhatsRaisedAndSetup is Script { function deployContracts() internal { console2.log("Setting up contracts..."); - // Deploy or reuse TestUSD - if (testUSD == address(0)) { - testUSD = address(new TestUSD()); - testUsdDeployed = true; - console2.log("TestUSD deployed at:", testUSD); + // Deploy or reuse TestToken + + string memory tokenName = vm.envOr("TOKEN_NAME", string("TestToken")); + string memory tokenSymbol = vm.envOr("TOKEN_SYMBOL", string("TST")); + + if (testToken == address(0)) { + testToken = address(new TestToken(tokenName, tokenSymbol)); + testTokenDeployed = true; + console2.log("TestToken deployed at:", testToken); } else { - console2.log("Reusing TestUSD at:", testUSD); + console2.log("Reusing TestToken at:", testToken); } // Deploy or reuse GlobalParams if (globalParams == address(0)) { globalParams = address(new GlobalParams( deployerAddress, // Initially deployer is protocol admin - testUSD, + testToken, protocolFeePercent )); globalParamsDeployed = true; @@ -126,8 +141,8 @@ contract DeployAllKeepWhatsRaisedAndSetup is Script { console2.log("Reusing GlobalParams at:", globalParams); } - // We need at least TestUSD and GlobalParams to continue - require(testUSD != address(0), "TestUSD address is required"); + // We need at least TestToken and GlobalParams to continue + require(testToken != address(0), "TestToken address is required"); require(globalParams != address(0), "GlobalParams address is required"); // Deploy CampaignInfo implementation if needed for new deployments @@ -290,17 +305,17 @@ contract DeployAllKeepWhatsRaisedAndSetup is Script { } function mintTokens() internal { - // Only mint tokens if we deployed TestUSD - if (!testUsdDeployed) { - console2.log("Skipping mintTokens - using existing TestUSD"); + // Only mint tokens if we deployed TestToken + if (!testTokenDeployed) { + console2.log("Skipping mintTokens - using existing TestToken"); return; } if (backer1 != address(0) && backer2 != address(0)) { console2.log("Minting tokens to test backers"); - TestUSD(testUSD).mint(backer1, tokenMintAmount); + TestToken(testToken).mint(backer1, tokenMintAmount); if (backer1 != backer2) { - TestUSD(testUSD).mint(backer2, tokenMintAmount); + TestToken(testToken).mint(backer2, tokenMintAmount); } console2.log("Tokens minted successfully"); } @@ -363,7 +378,7 @@ contract DeployAllKeepWhatsRaisedAndSetup is Script { // Output summary console2.log("\n--- Deployment & Setup Summary ---"); console2.log("Platform Name Hash:", vm.toString(platformHash)); - console2.log("TEST_USD_ADDRESS:", testUSD); + console2.log("TEST_TOKEN_ADDRESS:", testToken); console2.log("GLOBAL_PARAMS_ADDRESS:", globalParams); if (campaignInfo != address(0)) { console2.log("CAMPAIGN_INFO_ADDRESS:", campaignInfo); @@ -382,7 +397,7 @@ contract DeployAllKeepWhatsRaisedAndSetup is Script { } console2.log("\nDeployment status:"); - console2.log("- TestUSD:", testUsdDeployed ? "Newly deployed" : "Reused existing"); + console2.log("- TestToken:", testTokenDeployed ? "Newly deployed" : "Reused existing"); console2.log("- GlobalParams:", globalParamsDeployed ? "Newly deployed" : "Reused existing"); console2.log("- TreasuryFactory:", treasuryFactoryDeployed ? "Newly deployed" : "Reused existing"); console2.log("- CampaignInfoFactory:", campaignInfoFactoryDeployed ? "Newly deployed" : "Reused existing"); From 7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56 Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Tue, 27 May 2025 12:25:23 +0600 Subject: [PATCH 21/63] Update `KeepWhatsRaised` treasury imports; Update license identifier --- src/treasuries/KeepWhatsRaised.sol | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index a5b22de6..90c464a5 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -1,14 +1,16 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; -import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; -import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol"; +import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; +import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol"; +import {ERC721Burnable} from "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol"; -import "../utils/Counters.sol"; -import "../utils/TimestampChecker.sol"; -import "../utils/BaseTreasury.sol"; -import "../interfaces/IReward.sol"; -import "../interfaces/ICampaignData.sol"; +import {Counters} from "../utils/Counters.sol"; +import {TimestampChecker} from "../utils/TimestampChecker.sol"; +import {BaseTreasury} from "../utils/BaseTreasury.sol"; +import {ICampaignTreasury} from "../interfaces/ICampaignTreasury.sol"; +import {IReward} from "../interfaces/IReward.sol"; +import {ICampaignData} from "../interfaces/ICampaignData.sol"; /** * @title KeepWhatsRaised From fe16c4486945a1e7191fb299e7c341fb4b8d5e1a Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Wed, 28 May 2025 18:23:44 +0600 Subject: [PATCH 22/63] Update docs --- docs/book.toml | 3 +- docs/src/README.md | 75 +- docs/src/SUMMARY.md | 2 +- .../CampaignInfo.sol/contract.CampaignInfo.md | 17 +- .../contract.CampaignInfoFactory.md | 2 +- .../GlobalParams.sol/contract.GlobalParams.md | 2 +- docs/src/src/README.md | 1 - docs/src/src/TestUSD.sol/contract.TestUSD.md | 6 +- .../contract.TreasuryFactory.md | 2 +- .../interface.ICampaignData.md | 2 +- .../interface.ICampaignInfo.md | 2 +- .../interface.ICampaignInfoFactory.md | 2 +- .../interface.ICampaignTreasury.md | 2 +- .../interface.IGlobalParams.md | 2 +- .../interfaces/IItem.sol/interface.IItem.md | 2 +- .../IReward.sol/interface.IReward.md | 2 +- .../interface.ITreasuryFactory.md | 2 +- .../AllOrNothing.sol/contract.AllOrNothing.md | 2 +- .../contract.KeepWhatsRaised.md | 891 +++++++++++++++++- docs/src/src/treasuries/README.md | 1 + .../abstract.AdminAccessChecker.md | 2 +- .../BaseTreasury.sol/abstract.BaseTreasury.md | 2 +- .../abstract.CampaignAccessChecker.md | 2 +- .../utils/Counters.sol/library.Counters.md | 2 +- .../FiatEnabled.sol/abstract.FiatEnabled.md | 2 +- .../ItemRegistry.sol/contract.ItemRegistry.md | 2 +- .../abstract.PausableCancellable.md | 2 +- .../abstract.TimestampChecker.md | 2 +- 28 files changed, 957 insertions(+), 79 deletions(-) diff --git a/docs/book.toml b/docs/book.toml index b93f4313..a1a4f706 100644 --- a/docs/book.toml +++ b/docs/book.toml @@ -6,8 +6,7 @@ title = "" no-section-label = true additional-js = ["solidity.min.js"] additional-css = ["book.css"] -mathjax-support = true -git-repository-url = "https://github.com/ccprotocol/reference-client-sc" +git-repository-url = "https://github.com/ccprotocol/ccprotocol-contracts-internal" [output.html.fold] enable = true diff --git a/docs/src/README.md b/docs/src/README.md index 5522623e..68de14d6 100644 --- a/docs/src/README.md +++ b/docs/src/README.md @@ -15,7 +15,6 @@ CC Protocol is a decentralized crowdfunding protocol designed to help creators l - [Foundry](https://book.getfoundry.sh/) - Solidity ^0.8.20 -- Node.js (recommended) ## Installation @@ -38,11 +37,7 @@ forge install cp .env.example .env ``` -4. Configure your `.env` file with: - -- Private key -- RPC URL -- (Optional) Contract addresses for reuse +4. Configure your `.env` file following the template in `.env.example` ## Documentation @@ -56,7 +51,6 @@ Comprehensive documentation is available in the `docs/` folder: To view the documentation: ```bash -# Navigate to docs folder cd docs ``` @@ -93,18 +87,17 @@ anvil forge script script/DeployAll.s.sol:DeployAll --rpc-url http://localhost:8545 --private-key $PRIVATE_KEY --broadcast ``` -#### Testnet Deployment +#### Network Deployment ```bash -# Deploy to testnet -forge script script/DeployAll.s.sol:DeployAll --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast -vvvv +# Deploy to any configured network +forge script script/DeployAll.s.sol:DeployAll --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast ``` ## Contract Architecture ### Core Contracts -- `TestUSD`: Mock ERC20 token for testing - `GlobalParams`: Protocol-wide parameter management - `CampaignInfoFactory`: Campaign creation and management - `TreasuryFactory`: Treasury contract deployment @@ -113,28 +106,66 @@ forge script script/DeployAll.s.sol:DeployAll --rpc-url $RPC_URL --private-key $ - `AllOrNothing`: Funds refunded if campaign goal not met +### Notes on Mock Contracts + +- `TestToken` is a mock ERC20 token used **only for testing and development purposes**. +- It is located in the `mocks/` directory and should **not be included in production deployments**. + ## Deployment Workflow -1. Deploy `TestUSD` -2. Deploy `GlobalParams` -3. Deploy `TreasuryFactory` -4. Deploy `CampaignInfoFactory` +1. Deploy `GlobalParams` +2. Deploy `TreasuryFactory` +3. Deploy `CampaignInfoFactory` + +> For local testing or development, the `TestToken` mock token needs to be deployed before interacting with contracts requiring an ERC20 token. ## Environment Variables -Key environment variables in `.env`: +Key environment variables to configure in `.env`: - `PRIVATE_KEY`: Deployment wallet private key -- `RPC_URL`: Network RPC endpoint +- `RPC_URL`: Network RPC endpoint (can be configured for any network) - `SIMULATE`: Toggle simulation mode - Contract address variables for reuse -## Troubleshooting +For a complete list of variables, refer to `.env.example`. + +## Security + +### Audits + +Security audit reports can be found in the [`audits/`](./audits/) folder. We regularly conduct security audits to ensure the safety and reliability of the protocol. + +## Contributing + +We welcome all contributions to the Creative Crowdfunding Protocol. If you're interested in helping, here's how you can contribute: + +- **Report bugs** by opening issues +- **Suggest enhancements** or new features +- **Submit pull requests** to improve the codebase +- **Improve documentation** to make the project more accessible + +Before contributing, please read our detailed [Contributing Guidelines](./CONTRIBUTING.md) for comprehensive information on: +- Development workflow +- Coding standards +- Testing requirements +- Pull request process +- Smart contract security considerations + +### Community + +Join our community on [Discord](https://discord.gg/4tR9rWc3QE) for questions and discussions. + +Read our [Code of Conduct](./CODE_OF_CONDUCT.md) to keep our community approachable and respectful. + +## Contributors + + + + -- Ensure sufficient network gas tokens -- Verify RPC URL connectivity -- Check contract dependencies +Made with [contrib.rocks](https://contrib.rocks). ## License -[SPDX-License-Identifier: MIT] +This project is licensed under the [MIT License](https://opensource.org/licenses/MIT). \ No newline at end of file diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index d2c85d09..dd2e1eab 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -12,6 +12,7 @@ - [ITreasuryFactory](src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md) - [❱ treasuries](src/treasuries/README.md) - [AllOrNothing](src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md) + - [KeepWhatsRaised](src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md) - [❱ utils](src/utils/README.md) - [AdminAccessChecker](src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md) - [BaseTreasury](src/utils/BaseTreasury.sol/abstract.BaseTreasury.md) @@ -24,5 +25,4 @@ - [CampaignInfo](src/CampaignInfo.sol/contract.CampaignInfo.md) - [CampaignInfoFactory](src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md) - [GlobalParams](src/GlobalParams.sol/contract.GlobalParams.md) - - [TestUSD](src/TestUSD.sol/contract.TestUSD.md) - [TreasuryFactory](src/TreasuryFactory.sol/contract.TreasuryFactory.md) diff --git a/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md b/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md index 7d1b5dd3..95cc4d89 100644 --- a/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md +++ b/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md @@ -1,5 +1,5 @@ # CampaignInfo -[Git Source](https://github.com/ccprotocol/reference-client-sc/blob/32b7b1617200d0c6f3248845ef972180411f1f65/src/CampaignInfo.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/CampaignInfo.sol) **Inherits:** [ICampaignData](/src/interfaces/ICampaignData.sol/interface.ICampaignData.md), [ICampaignInfo](/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md), Ownable, [PausableCancellable](/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md), [TimestampChecker](/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), [AdminAccessChecker](/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md), Initializable @@ -569,21 +569,6 @@ event CampaignInfoPlatformInfoUpdated(bytes32 indexed platformHash, address inde |`platformHash`|`bytes32`|The bytes32 identifier of the platform.| |`platformTreasury`|`address`|The address of the platform's treasury.| -### CampaignInfoOwnershipTransferred -*Emitted when ownership of the contract is transferred.* - - -```solidity -event CampaignInfoOwnershipTransferred(address indexed previousOwner, address indexed newOwner); -``` - -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`previousOwner`|`address`|The address of the previous owner.| -|`newOwner`|`address`|The address of the new owner.| - ## Errors ### CampaignInfoInvalidPlatformUpdate *Emitted when an invalid platform update is attempted.* diff --git a/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md b/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md index ecf45080..fdc01d75 100644 --- a/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md +++ b/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md @@ -1,5 +1,5 @@ # CampaignInfoFactory -[Git Source](https://github.com/ccprotocol/reference-client-sc/blob/32b7b1617200d0c6f3248845ef972180411f1f65/src/CampaignInfoFactory.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/CampaignInfoFactory.sol) **Inherits:** Initializable, [ICampaignInfoFactory](/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md), Ownable diff --git a/docs/src/src/GlobalParams.sol/contract.GlobalParams.md b/docs/src/src/GlobalParams.sol/contract.GlobalParams.md index 2cf9e304..9dd73907 100644 --- a/docs/src/src/GlobalParams.sol/contract.GlobalParams.md +++ b/docs/src/src/GlobalParams.sol/contract.GlobalParams.md @@ -1,5 +1,5 @@ # GlobalParams -[Git Source](https://github.com/ccprotocol/reference-client-sc/blob/32b7b1617200d0c6f3248845ef972180411f1f65/src/GlobalParams.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/GlobalParams.sol) **Inherits:** [IGlobalParams](/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md), Ownable diff --git a/docs/src/src/README.md b/docs/src/src/README.md index 7423e1d4..7592aab6 100644 --- a/docs/src/src/README.md +++ b/docs/src/src/README.md @@ -7,5 +7,4 @@ - [CampaignInfo](CampaignInfo.sol/contract.CampaignInfo.md) - [CampaignInfoFactory](CampaignInfoFactory.sol/contract.CampaignInfoFactory.md) - [GlobalParams](GlobalParams.sol/contract.GlobalParams.md) -- [TestUSD](TestUSD.sol/contract.TestUSD.md) - [TreasuryFactory](TreasuryFactory.sol/contract.TreasuryFactory.md) diff --git a/docs/src/src/TestUSD.sol/contract.TestUSD.md b/docs/src/src/TestUSD.sol/contract.TestUSD.md index e317536d..0d401e69 100644 --- a/docs/src/src/TestUSD.sol/contract.TestUSD.md +++ b/docs/src/src/TestUSD.sol/contract.TestUSD.md @@ -1,8 +1,12 @@ # TestUSD +<<<<<<< Updated upstream [Git Source](https://github.com/ccprotocol/reference-client-sc/blob/32b7b1617200d0c6f3248845ef972180411f1f65/src/TestUSD.sol) +======= +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/4245ef0ad7914158999986aa0d8b5d2614efc6c2/src/TestUSD.sol) +>>>>>>> Stashed changes **Inherits:** -ERC20, Ownable +[ERC20](/src/.deps/npm/@openzeppelin/contracts/token/ERC20/ERC20.sol/abstract.ERC20.md), [Ownable](/src/.deps/npm/@openzeppelin/contracts/access/Ownable.sol/abstract.Ownable.md) A test token `tUSD` which is used in the tests. diff --git a/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md b/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md index 7d26317c..8159863d 100644 --- a/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md +++ b/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md @@ -1,5 +1,5 @@ # TreasuryFactory -[Git Source](https://github.com/ccprotocol/reference-client-sc/blob/32b7b1617200d0c6f3248845ef972180411f1f65/src/TreasuryFactory.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/TreasuryFactory.sol) **Inherits:** [ITreasuryFactory](/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md), [AdminAccessChecker](/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md) diff --git a/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md b/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md index 00944837..c750b17c 100644 --- a/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md +++ b/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md @@ -1,5 +1,5 @@ # ICampaignData -[Git Source](https://github.com/ccprotocol/reference-client-sc/blob/32b7b1617200d0c6f3248845ef972180411f1f65/src/interfaces/ICampaignData.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/interfaces/ICampaignData.sol) An interface for managing campaign data in a CCP. diff --git a/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md b/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md index af5a884a..5b99629e 100644 --- a/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md +++ b/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md @@ -1,5 +1,5 @@ # ICampaignInfo -[Git Source](https://github.com/ccprotocol/reference-client-sc/blob/32b7b1617200d0c6f3248845ef972180411f1f65/src/interfaces/ICampaignInfo.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/interfaces/ICampaignInfo.sol) An interface for managing campaign information in a crowdfunding system. diff --git a/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md b/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md index e28f1138..48d8be15 100644 --- a/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md +++ b/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md @@ -1,5 +1,5 @@ # ICampaignInfoFactory -[Git Source](https://github.com/ccprotocol/reference-client-sc/blob/32b7b1617200d0c6f3248845ef972180411f1f65/src/interfaces/ICampaignInfoFactory.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/interfaces/ICampaignInfoFactory.sol) **Inherits:** [ICampaignData](/src/interfaces/ICampaignData.sol/interface.ICampaignData.md) diff --git a/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md b/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md index bcede9cd..77061baa 100644 --- a/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md +++ b/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md @@ -1,5 +1,5 @@ # ICampaignTreasury -[Git Source](https://github.com/ccprotocol/reference-client-sc/blob/32b7b1617200d0c6f3248845ef972180411f1f65/src/interfaces/ICampaignTreasury.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/interfaces/ICampaignTreasury.sol) An interface for managing campaign treasury contracts. diff --git a/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md b/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md index c23e2700..fc1631cc 100644 --- a/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md +++ b/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md @@ -1,5 +1,5 @@ # IGlobalParams -[Git Source](https://github.com/ccprotocol/reference-client-sc/blob/32b7b1617200d0c6f3248845ef972180411f1f65/src/interfaces/IGlobalParams.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/interfaces/IGlobalParams.sol) An interface for accessing and managing global parameters of the protocol. diff --git a/docs/src/src/interfaces/IItem.sol/interface.IItem.md b/docs/src/src/interfaces/IItem.sol/interface.IItem.md index 41b6afc0..db84d41a 100644 --- a/docs/src/src/interfaces/IItem.sol/interface.IItem.md +++ b/docs/src/src/interfaces/IItem.sol/interface.IItem.md @@ -1,5 +1,5 @@ # IItem -[Git Source](https://github.com/ccprotocol/reference-client-sc/blob/32b7b1617200d0c6f3248845ef972180411f1f65/src/interfaces/IItem.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/interfaces/IItem.sol) An interface for managing items and their attributes. diff --git a/docs/src/src/interfaces/IReward.sol/interface.IReward.md b/docs/src/src/interfaces/IReward.sol/interface.IReward.md index bfbd0aa2..9cf3569b 100644 --- a/docs/src/src/interfaces/IReward.sol/interface.IReward.md +++ b/docs/src/src/interfaces/IReward.sol/interface.IReward.md @@ -1,5 +1,5 @@ # IReward -[Git Source](https://github.com/ccprotocol/reference-client-sc/blob/32b7b1617200d0c6f3248845ef972180411f1f65/src/interfaces/IReward.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/interfaces/IReward.sol) An interface for managing rewards in a campaign. diff --git a/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md b/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md index 07b47fcf..76832933 100644 --- a/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md +++ b/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md @@ -1,5 +1,5 @@ # ITreasuryFactory -[Git Source](https://github.com/ccprotocol/reference-client-sc/blob/32b7b1617200d0c6f3248845ef972180411f1f65/src/interfaces/ITreasuryFactory.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/interfaces/ITreasuryFactory.sol) *Interface for the TreasuryFactory contract, which registers, approves, and deploys treasury clones.* diff --git a/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md b/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md index 21e280ad..e03bf729 100644 --- a/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md +++ b/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md @@ -1,5 +1,5 @@ # AllOrNothing -[Git Source](https://github.com/ccprotocol/reference-client-sc/blob/32b7b1617200d0c6f3248845ef972180411f1f65/src/treasuries/AllOrNothing.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/treasuries/AllOrNothing.sol) **Inherits:** [IReward](/src/interfaces/IReward.sol/interface.IReward.md), [BaseTreasury](/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md), [TimestampChecker](/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), ERC721Burnable diff --git a/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md b/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md index 7d89ed06..f631d037 100644 --- a/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md +++ b/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md @@ -1,41 +1,900 @@ # KeepWhatsRaised - -[Git Source](https://github.com/ccprotocol/campaign-utils-contracts-aggregator/blob/79d78188e565502f83e2c0309c9a4ea3b35cee91/src/treasuries/KeepWhatsRaised.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/treasuries/KeepWhatsRaised.sol) **Inherits:** -[AllOrNothing](/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md) +[IReward](/src/interfaces/IReward.sol/interface.IReward.md), [BaseTreasury](/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md), [TimestampChecker](/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), ERC721Burnable, [ICampaignData](/src/interfaces/ICampaignData.sol/interface.ICampaignData.md) A contract that keeps all the funds raised, regardless of the success condition. -_This contract inherits from the `AllOrNothing` contract and overrides the `_checkSuccessCondition` function to always return true._ + +## State Variables +### s_tokenToPledgedAmount + +```solidity +mapping(uint256 => uint256) private s_tokenToPledgedAmount; +``` + + +### s_tokenToTippedAmount + +```solidity +mapping(uint256 => uint256) private s_tokenToTippedAmount; +``` + + +### s_reward + +```solidity +mapping(bytes32 => Reward) private s_reward; +``` + + +### s_tokenIdCounter + +```solidity +Counters.Counter private s_tokenIdCounter; +``` + + +### s_rewardCounter + +```solidity +Counters.Counter private s_rewardCounter; +``` + + +### s_name + +```solidity +string private s_name; +``` + + +### s_symbol + +```solidity +string private s_symbol; +``` + + +### s_tip + +```solidity +uint256 private s_tip; +``` + + +### s_platformFee + +```solidity +uint256 private s_platformFee; +``` + + +### s_protocolFee + +```solidity +uint256 private s_protocolFee; +``` + + +### s_availablePledgedAmount + +```solidity +uint256 private s_availablePledgedAmount; +``` + + +### s_cancellationTime + +```solidity +uint256 private s_cancellationTime; +``` + + +### s_isWithdrawalApproved + +```solidity +bool private s_isWithdrawalApproved; +``` + + +### s_tipClaimed + +```solidity +bool private s_tipClaimed; +``` + + +### s_fundClaimed + +```solidity +bool private s_fundClaimed; +``` + + +### s_feeKeys + +```solidity +FeeKeys private s_feeKeys; +``` + + +### s_config + +```solidity +Config private s_config; +``` + + +### s_campaignData + +```solidity +CampaignData private s_campaignData; +``` + ## Functions +### withdrawalEnabled + +*Ensures that withdrawals are currently enabled. +Reverts with `KeepWhatsRaisedDisabled` if the withdrawal approval flag is not set.* + + +```solidity +modifier withdrawalEnabled(); +``` + +### onlyBeforeConfigLock + +*Restricts execution to only occur before the configuration lock period. +Reverts with `KeepWhatsRaisedConfigLocked` if called too close to or after the campaign deadline. +The lock period is defined as the duration before the deadline during which configuration changes are not allowed.* + + +```solidity +modifier onlyBeforeConfigLock(); +``` ### constructor -_Initializes the KeepWhatsRaised contract._ +*Constructor for the KeepWhatsRaised contract.* + ```solidity -constructor(bytes32 platformHash, address infoAddress) AllOrNothing(platformHash, infoAddress); +constructor() ERC721("", ""); ``` +### initialize + + +```solidity +function initialize(bytes32 _platformHash, address _infoAddress, string calldata _name, string calldata _symbol) + external + initializer; +``` + +### name + + +```solidity +function name() public view override returns (string memory); +``` + +### symbol + + +```solidity +function symbol() public view override returns (string memory); +``` + +### getWithdrawalApprovalStatus + +Retrieves the withdrawal approval status. + + +```solidity +function getWithdrawalApprovalStatus() public view returns (bool); +``` + +### getReward + +Retrieves the details of a reward. + + +```solidity +function getReward(bytes32 rewardName) external view returns (Reward memory reward); +``` **Parameters** -| Name | Type | Description | -| -------------- | --------- | ------------------------------------------------------------ | -| `platformHash` | `bytes32` | The unique identifier of the platform. | -| `infoAddress` | `address` | The address of the associated campaign information contract. | +|Name|Type|Description| +|----|----|-----------| +|`rewardName`|`bytes32`|The name of the reward.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`reward`|`Reward`|The details of the reward as a `Reward` struct.| + + +### getRaisedAmount + +Retrieves the total raised amount in the treasury. + + +```solidity +function getRaisedAmount() external view override returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The total raised amount as a uint256 value.| + + +### getAvailableRaisedAmount + +Retrieves the currently available raised amount in the treasury. + + +```solidity +function getAvailableRaisedAmount() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The current available raised amount as a uint256 value.| -### \_checkSuccessCondition -_Internal function to check the success condition for fee disbursement._ +### getLaunchTime + +Retrieves the campaign's launch time. + ```solidity -function _checkSuccessCondition() internal pure override returns (bool); +function getLaunchTime() public view returns (uint256); ``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The timestamp when the campaign was launched.| + +### getDeadline + +Retrieves the campaign's deadline. + + +```solidity +function getDeadline() public view returns (uint256); +``` **Returns** -| Name | Type | Description | -| -------- | ------ | ------------------------------------- | -| `` | `bool` | Whether the success condition is met. | +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The timestamp when the campaign ends.| + + +### getGoalAmount + +Retrieves the campaign's funding goal amount. + + +```solidity +function getGoalAmount() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The funding goal amount of the campaign.| + + +### approveWithdrawal + +Approves the withdrawal of the treasury by the platform admin. + + +```solidity +function approveWithdrawal() + external + onlyPlatformAdmin(PLATFORM_HASH) + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled; +``` + +### configureTreasury + +*Configures the treasury for a campaign by setting the system parameters, +campaign-specific data, and fee configuration keys.* + + +```solidity +function configureTreasury(Config memory config, CampaignData memory campaignData, FeeKeys memory feeKeys) + external + onlyPlatformAdmin(PLATFORM_HASH) + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`config`|`Config`|The configuration settings including withdrawal delay, refund delay, fee exemption threshold, and configuration lock period.| +|`campaignData`|`CampaignData`|The campaign-related metadata such as deadlines and funding goals.| +|`feeKeys`|`FeeKeys`|The set of keys used to reference applicable flat and percentage-based fees.| + + +### updateDeadline + +*Updates the campaign's deadline.* + + +```solidity +function updateDeadline(uint256 deadline) + external + onlyPlatformAdmin(PLATFORM_HASH) + onlyBeforeConfigLock + whenNotPaused + whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`deadline`|`uint256`|The new deadline timestamp for the campaign. Requirements: - Must be called before the configuration lock period (see `onlyBeforeConfigLock`). - The new deadline must be a future timestamp.| + + +### updateGoalAmount + +*Updates the funding goal amount for the campaign.* + + +```solidity +function updateGoalAmount(uint256 goalAmount) + external + onlyPlatformAdmin(PLATFORM_HASH) + onlyBeforeConfigLock + whenNotPaused + whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`goalAmount`|`uint256`|The new goal amount. Requirements: - Must be called before the configuration lock period (see `onlyBeforeConfigLock`).| + + +### addRewards + +Adds multiple rewards in a batch. + +*This function allows for both reward tiers and non-reward tiers. +For both types, rewards must have non-zero value. +If items are specified (non-empty arrays), the itemId, itemValue, and itemQuantity arrays must match in length. +Empty arrays are allowed for both reward tiers and non-reward tiers.* + + +```solidity +function addRewards(bytes32[] calldata rewardNames, Reward[] calldata rewards) + external + onlyCampaignOwner + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`rewardNames`|`bytes32[]`|An array of reward names.| +|`rewards`|`Reward[]`|An array of `Reward` structs containing reward details.| + + +### removeReward + +Removes a reward from the campaign. + + +```solidity +function removeReward(bytes32 rewardName) + external + onlyCampaignOwner + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`rewardName`|`bytes32`|The name of the reward.| + + +### pledgeForAReward + +Allows a backer to pledge for a reward. + +*The first element of the `reward` array must be a reward tier and the other elements can be either reward tiers or non-reward tiers. +The non-reward tiers cannot be pledged for without a reward.* + + +```solidity +function pledgeForAReward(address backer, uint256 tip, bytes32[] calldata reward) + external + currentTimeIsWithinRange(getLaunchTime(), getDeadline()) + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`backer`|`address`|The address of the backer making the pledge.| +|`tip`|`uint256`|An optional tip can be added during the process.| +|`reward`|`bytes32[]`|An array of reward names.| + + +### pledgeWithoutAReward + +Allows a backer to pledge without selecting a reward. + + +```solidity +function pledgeWithoutAReward(address backer, uint256 pledgeAmount, uint256 tip) + external + currentTimeIsWithinRange(getLaunchTime(), getDeadline()) + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`backer`|`address`|The address of the backer making the pledge.| +|`pledgeAmount`|`uint256`|The amount of the pledge.| +|`tip`|`uint256`|An optional tip can be added during the process.| + + +### withdraw + +Withdraws funds from the treasury. + + +```solidity +function withdraw() public view override whenNotPaused whenNotCancelled; +``` + +### withdraw + +*Allows a campaign owner or eligible party to withdraw a specified amount of funds.* + + +```solidity +function withdraw(uint256 amount) + public + currentTimeIsLess(getDeadline() + s_config.withdrawalDelay) + whenNotPaused + whenNotCancelled + withdrawalEnabled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`amount`|`uint256`|The amount to withdraw. Requirements: - Withdrawals must be approved (see `withdrawalEnabled` modifier). - Amount must not exceed the available balance after fees. - May apply and deduct a withdrawal fee.| + + +### claimRefund + +*Allows a backer to claim a refund associated with a specific pledge (token ID).* + + +```solidity +function claimRefund(uint256 tokenId) + external + currentTimeIsGreater(getLaunchTime()) + whenCampaignNotPaused + whenNotPaused; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|The ID of the token representing the backer's pledge. Requirements: - Refund delay must have passed. - The token must be eligible for a refund and not previously claimed.| + + +### disburseFees + +*Disburses all accumulated fees to the appropriate fee collector or treasury. +Requirements: +- Only callable when fees are available.* + + +```solidity +function disburseFees() public override whenNotPaused whenNotCancelled; +``` + +### claimTip + +*Allows an authorized claimer to collect tips contributed during the campaign. +Requirements: +- Caller must be authorized to claim tips. +- Tip amount must be non-zero.* + + +```solidity +function claimTip() external onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenNotPaused; +``` + +### claimFund + +*Allows a campaign owner or authorized user to claim remaining campaign funds. +Requirements: +- Claim period must have started and funds must be available. +- Cannot be previously claimed.* + + +```solidity +function claimFund() external onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenNotPaused; +``` + +### cancelTreasury + +*This function is overridden to allow the platform admin and the campaign owner to cancel a treasury.* + + +```solidity +function cancelTreasury(bytes32 message) public override; +``` + +### _checkSuccessCondition + +*Internal function to check the success condition for fee disbursement.* + + +```solidity +function _checkSuccessCondition() internal view virtual override returns (bool); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|Whether the success condition is met.| + + +### _pledge + + +```solidity +function _pledge( + address backer, + bytes32 reward, + uint256 pledgeAmount, + uint256 tip, + uint256 tokenId, + bytes32[] memory rewards +) private; +``` + +### supportsInterface + + +```solidity +function supportsInterface(bytes4 interfaceId) public view override returns (bool); +``` + +## Events +### Receipt +*Emitted when a backer makes a pledge.* + + +```solidity +event Receipt( + address indexed backer, + bytes32 indexed reward, + uint256 pledgeAmount, + uint256 tip, + uint256 tokenId, + bytes32[] rewards +); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`backer`|`address`|The address of the backer making the pledge.| +|`reward`|`bytes32`|The name of the reward.| +|`pledgeAmount`|`uint256`|The amount pledged.| +|`tip`|`uint256`|An optional tip can be added during the process.| +|`tokenId`|`uint256`|The ID of the token representing the pledge.| +|`rewards`|`bytes32[]`|An array of reward names.| + +### RewardsAdded +*Emitted when rewards are added to the campaign.* + + +```solidity +event RewardsAdded(bytes32[] rewardNames, Reward[] rewards); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`rewardNames`|`bytes32[]`|The names of the rewards.| +|`rewards`|`Reward[]`|The details of the rewards.| + +### RewardRemoved +*Emitted when a reward is removed from the campaign.* + + +```solidity +event RewardRemoved(bytes32 indexed rewardName); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`rewardName`|`bytes32`|The name of the reward.| + +### WithdrawalApproved +*Emitted when withdrawal functionality has been approved by the platform admin.* + + +```solidity +event WithdrawalApproved(); +``` + +### TreasuryConfigured +*Emitted when the treasury configuration is updated.* + + +```solidity +event TreasuryConfigured(Config config, CampaignData campaignData, FeeKeys feeKeys); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`config`|`Config`|The updated configuration parameters (e.g., delays, exemptions).| +|`campaignData`|`CampaignData`|The campaign-related data associated with the treasury setup.| +|`feeKeys`|`FeeKeys`|The set of keys used to determine applicable fees.| + +### WithdrawalWithFeeSuccessful +*Emitted when a withdrawal is successfully processed along with the applied fee.* + + +```solidity +event WithdrawalWithFeeSuccessful(address indexed to, uint256 amount, uint256 fee); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`to`|`address`|The recipient address receiving the funds.| +|`amount`|`uint256`|The total amount withdrawn (excluding fee).| +|`fee`|`uint256`|The fee amount deducted from the withdrawal.| + +### TipClaimed +*Emitted when a tip is claimed from the contract.* + + +```solidity +event TipClaimed(uint256 amount, address indexed claimer); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`amount`|`uint256`|The amount of tip claimed.| +|`claimer`|`address`|The address that claimed the tip.| + +### FundClaimed +*Emitted when campaign or user's remaining funds are successfully claimed by the platform admin.* + + +```solidity +event FundClaimed(uint256 amount, address indexed claimer); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`amount`|`uint256`|The amount of funds claimed.| +|`claimer`|`address`|The address that claimed the funds.| + +### RefundClaimed +*Emitted when a refund is claimed.* + + +```solidity +event RefundClaimed(uint256 indexed tokenId, uint256 refundAmount, address indexed claimer); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|The ID of the token representing the pledge.| +|`refundAmount`|`uint256`|The refund amount claimed.| +|`claimer`|`address`|The address of the claimer.| + +### KeepWhatsRaisedDeadlineUpdated +*Emitted when the deadline of the campaign is updated.* + + +```solidity +event KeepWhatsRaisedDeadlineUpdated(uint256 newDeadline); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`newDeadline`|`uint256`|The new deadline.| + +### KeepWhatsRaisedGoalAmountUpdated +*Emitted when the goal amount for a campaign is updated.* + + +```solidity +event KeepWhatsRaisedGoalAmountUpdated(uint256 newGoalAmount); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`newGoalAmount`|`uint256`|The new goal amount set for the campaign.| + +## Errors +### KeepWhatsRaisedUnAuthorized +*Emitted when an unauthorized action is attempted.* + + +```solidity +error KeepWhatsRaisedUnAuthorized(); +``` + +### KeepWhatsRaisedInvalidInput +*Emitted when an invalid input is detected.* + + +```solidity +error KeepWhatsRaisedInvalidInput(); +``` + +### KeepWhatsRaisedRewardExists +*Emitted when a `Reward` already exists for given input.* + + +```solidity +error KeepWhatsRaisedRewardExists(); +``` + +### KeepWhatsRaisedDisabled +*Emitted when anyone called a disabled function.* + + +```solidity +error KeepWhatsRaisedDisabled(); +``` + +### KeepWhatsRaisedAlreadyEnabled +*Emitted when any functionality is already enabled and cannot be re-enabled.* + + +```solidity +error KeepWhatsRaisedAlreadyEnabled(); +``` + +### KeepWhatsRaisedWithdrawalOverload +*Emitted when a withdrawal attempt exceeds the available funds after accounting for the fee.* + + +```solidity +error KeepWhatsRaisedWithdrawalOverload(uint256 availableAmount, uint256 withdrawalAmount, uint256 fee); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`availableAmount`|`uint256`|The maximum amount that can be withdrawn.| +|`withdrawalAmount`|`uint256`|The attempted withdrawal amount.| +|`fee`|`uint256`|The fee that would be applied to the withdrawal.| + +### KeepWhatsRaisedAlreadyWithdrawn +*Emitted when a withdrawal has already been made and cannot be repeated.* + + +```solidity +error KeepWhatsRaisedAlreadyWithdrawn(); +``` + +### KeepWhatsRaisedAlreadyClaimed +*Emitted when funds or rewards have already been claimed for the given context.* + + +```solidity +error KeepWhatsRaisedAlreadyClaimed(); +``` + +### KeepWhatsRaisedNotClaimable +*Emitted when a token or pledge is not eligible for claiming (e.g., claim period not reached or not valid).* + + +```solidity +error KeepWhatsRaisedNotClaimable(uint256 tokenId); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|The ID of the token that was attempted to be claimed.| + +### KeepWhatsRaisedNotClaimableAdmin +*Emitted when an admin attempts to claim funds that are not yet claimable according to the rules.* + + +```solidity +error KeepWhatsRaisedNotClaimableAdmin(); +``` + +### KeepWhatsRaisedConfigLocked +*Emitted when a configuration change is attempted during the lock period.* + + +```solidity +error KeepWhatsRaisedConfigLocked(); +``` + +## Structs +### FeeKeys +*Represents keys used to reference different fee configurations. +These keys are typically used to look up fee values stored in `s_platformData`.* + + +```solidity +struct FeeKeys { + bytes32 flatFeeKey; + bytes32 cumulativeFlatFeeKey; + bytes32[] grossPercentageFeeKeys; + bytes32[] netPercentageFeeKeys; +} +``` + +### Config +*System configuration parameters related to withdrawal and refund behavior.* + + +```solidity +struct Config { + uint256 minimumWithdrawalForFeeExemption; + uint256 withdrawalDelay; + uint256 refundDelay; + uint256 configLockPeriod; +} +``` + diff --git a/docs/src/src/treasuries/README.md b/docs/src/src/treasuries/README.md index c01d8d76..c591b575 100644 --- a/docs/src/src/treasuries/README.md +++ b/docs/src/src/treasuries/README.md @@ -2,3 +2,4 @@ # Contents - [AllOrNothing](AllOrNothing.sol/contract.AllOrNothing.md) +- [KeepWhatsRaised](KeepWhatsRaised.sol/contract.KeepWhatsRaised.md) diff --git a/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md b/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md index ea05746a..78f05214 100644 --- a/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md +++ b/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md @@ -1,5 +1,5 @@ # AdminAccessChecker -[Git Source](https://github.com/ccprotocol/reference-client-sc/blob/32b7b1617200d0c6f3248845ef972180411f1f65/src/utils/AdminAccessChecker.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/utils/AdminAccessChecker.sol) *This abstract contract provides access control mechanisms to restrict the execution of specific functions to authorized protocol administrators and platform administrators.* diff --git a/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md b/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md index de7920fe..b035f172 100644 --- a/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md +++ b/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md @@ -1,5 +1,5 @@ # BaseTreasury -[Git Source](https://github.com/ccprotocol/reference-client-sc/blob/32b7b1617200d0c6f3248845ef972180411f1f65/src/utils/BaseTreasury.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/utils/BaseTreasury.sol) **Inherits:** Initializable, [ICampaignTreasury](/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md), [CampaignAccessChecker](/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md), [PausableCancellable](/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md) diff --git a/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md b/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md index 05a8e870..9a1106e9 100644 --- a/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md +++ b/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md @@ -1,5 +1,5 @@ # CampaignAccessChecker -[Git Source](https://github.com/ccprotocol/reference-client-sc/blob/32b7b1617200d0c6f3248845ef972180411f1f65/src/utils/CampaignAccessChecker.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/utils/CampaignAccessChecker.sol) *This abstract contract provides access control mechanisms to restrict the execution of specific functions to authorized protocol administrators, platform administrators, and campaign owners.* diff --git a/docs/src/src/utils/Counters.sol/library.Counters.md b/docs/src/src/utils/Counters.sol/library.Counters.md index 2c667abe..4119f2e8 100644 --- a/docs/src/src/utils/Counters.sol/library.Counters.md +++ b/docs/src/src/utils/Counters.sol/library.Counters.md @@ -1,5 +1,5 @@ # Counters -[Git Source](https://github.com/ccprotocol/reference-client-sc/blob/32b7b1617200d0c6f3248845ef972180411f1f65/src/utils/Counters.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/utils/Counters.sol) ## Functions diff --git a/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md b/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md index 8a148bda..592982b1 100644 --- a/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md +++ b/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md @@ -1,5 +1,5 @@ # FiatEnabled -[Git Source](https://github.com/ccprotocol/reference-client-sc/blob/32b7b1617200d0c6f3248845ef972180411f1f65/src/utils/FiatEnabled.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/utils/FiatEnabled.sol) A contract that provides functionality for tracking and managing fiat transactions. This contract allows tracking the amount of fiat raised, individual fiat transactions, and the state of fiat fee disbursement. diff --git a/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md b/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md index 217effc5..2d0099b3 100644 --- a/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md +++ b/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md @@ -1,5 +1,5 @@ # ItemRegistry -[Git Source](https://github.com/ccprotocol/reference-client-sc/blob/32b7b1617200d0c6f3248845ef972180411f1f65/src/utils/ItemRegistry.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/utils/ItemRegistry.sol) **Inherits:** [IItem](/src/interfaces/IItem.sol/interface.IItem.md), Context diff --git a/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md b/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md index fda365d5..dbdb866a 100644 --- a/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md +++ b/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md @@ -1,5 +1,5 @@ # PausableCancellable -[Git Source](https://github.com/ccprotocol/reference-client-sc/blob/32b7b1617200d0c6f3248845ef972180411f1f65/src/utils/PausableCancellable.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/utils/PausableCancellable.sol) Abstract contract providing pause and cancel state management with events and modifiers diff --git a/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md b/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md index 0931066c..5252648e 100644 --- a/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md +++ b/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md @@ -1,5 +1,5 @@ # TimestampChecker -[Git Source](https://github.com/ccprotocol/reference-client-sc/blob/32b7b1617200d0c6f3248845ef972180411f1f65/src/utils/TimestampChecker.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/utils/TimestampChecker.sol) A contract that provides timestamp-related checks for contract functions. From b4cf08be254096c7001f5e8457b5b1c1414d763e Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Tue, 17 Jun 2025 17:28:02 +0600 Subject: [PATCH 23/63] Update `KeepWhatsRaised` treasury - Shift fee calculation from withdraw to pledge - Add new fee calculation logic - Block disburseFee functionality till refund period is over - Add campaign owner support for updating deadline and goal amount - Adjust claim refund and withdraw function according to the changes --- src/treasuries/KeepWhatsRaised.sol | 174 +++++++++++++++++++++-------- 1 file changed, 125 insertions(+), 49 deletions(-) diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index 90c464a5..b480fd8b 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -30,6 +30,8 @@ contract KeepWhatsRaised is mapping(uint256 => uint256) private s_tokenToPledgedAmount; // Mapping to store the tipped amount per token ID mapping(uint256 => uint256) private s_tokenToTippedAmount; + // Mapping to store the payment fee per token ID + mapping(uint256 => uint256) private s_tokenToPaymentFee; // Mapping to store reward details by name mapping(bytes32 => Reward) private s_reward; @@ -50,9 +52,6 @@ contract KeepWhatsRaised is /// @dev Keys for gross percentage-based fees (calculated before deductions). bytes32[] grossPercentageFeeKeys; - - /// @dev Keys for net percentage-based fees (calculated after deductions). - bytes32[] netPercentageFeeKeys; } /** * @dev System configuration parameters related to withdrawal and refund behavior. @@ -69,6 +68,9 @@ contract KeepWhatsRaised is /// @dev Duration (in timestamp) for which config changes are locked to prevent immediate updates. uint256 configLockPeriod; + + /// @dev True if the creator is Colombian, false otherwise. + bool isColumbianCreator; } string private s_name; @@ -232,6 +234,11 @@ contract KeepWhatsRaised is */ error KeepWhatsRaisedConfigLocked(); + /** + * @dev Emitted when a disbursement is attempted before the refund period has ended. + */ + error KeepWhatsRaisedDisbursementBlocked(); + /** * @dev Ensures that withdrawals are currently enabled. * Reverts with `KeepWhatsRaisedDisabled` if the withdrawal approval flag is not set. @@ -255,6 +262,19 @@ contract KeepWhatsRaised is _; } + /// @notice Restricts access to only the platform admin or the campaign owner. + /// @dev Checks if `msg.sender` is either the platform admin (via `INFO.getPlatformAdminAddress`) + /// or the campaign owner (via `INFO.owner()`). Reverts with `KeepWhatsRaisedUnAuthorized` if not authorized. + modifier onlyPlatformAdminOrCampaignOwner() { + if ( + msg.sender != INFO.getPlatformAdminAddress(PLATFORM_HASH) && + msg.sender != INFO.owner() + ) { + revert KeepWhatsRaisedUnAuthorized(); + } + _; + } + /** * @dev Constructor for the KeepWhatsRaised contract. */ @@ -404,7 +424,7 @@ contract KeepWhatsRaised is uint256 deadline ) external - onlyPlatformAdmin(PLATFORM_HASH) + onlyPlatformAdminOrCampaignOwner onlyBeforeConfigLock whenNotPaused whenNotCancelled @@ -429,7 +449,7 @@ contract KeepWhatsRaised is uint256 goalAmount ) external - onlyPlatformAdmin(PLATFORM_HASH) + onlyPlatformAdminOrCampaignOwner onlyBeforeConfigLock whenNotPaused whenNotCancelled @@ -647,29 +667,6 @@ contract KeepWhatsRaised is s_protocolFee += fee; totalFee += fee; - //Gross Percentage Fee Calculation - uint256 len = s_feeKeys.grossPercentageFeeKeys.length; - for(uint256 i = 0; i < len; i++){ - fee = (withdrawalAmount * uint256(INFO.getPlatformData(s_feeKeys.grossPercentageFeeKeys[i]))) / - PERCENT_DIVIDER; - s_platformFee += fee; - totalFee += fee; - } - - //Net Percentage Fee Calculation - if(totalFee > withdrawalAmount){ - revert KeepWhatsRaisedWithdrawalOverload(s_availablePledgedAmount, withdrawalAmount, totalFee); - } - uint256 availableBeforeNet = withdrawalAmount - totalFee; - len = s_feeKeys.netPercentageFeeKeys.length; - for(uint256 i = 0; i < len; i++){ - - fee = (availableBeforeNet * uint256(INFO.getPlatformData(s_feeKeys.netPercentageFeeKeys[i]))) / - PERCENT_DIVIDER; - s_platformFee += fee; - totalFee += fee; - } - if(totalFee > withdrawalAmount){ revert KeepWhatsRaisedWithdrawalOverload(s_availablePledgedAmount, withdrawalAmount, totalFee); } @@ -699,25 +696,23 @@ contract KeepWhatsRaised is whenCampaignNotPaused whenNotPaused { - uint256 deadline = getDeadline(); - - bool isCancelled = s_cancellationTime > 0; - bool refundWindowFromDeadline = !isCancelled && block.timestamp > deadline && block.timestamp <= deadline + s_config.refundDelay; - bool refundWindowFromCancellation = isCancelled && block.timestamp <= s_cancellationTime + s_config.refundDelay; - - if (!(refundWindowFromDeadline || refundWindowFromCancellation)) { + if (!_checkRefundPeriodStatus(false)) { revert KeepWhatsRaisedNotClaimable(tokenId); } uint256 amountToRefund = s_tokenToPledgedAmount[tokenId]; uint256 availablePledgedAmount = s_availablePledgedAmount; + uint256 paymentFee = s_tokenToPaymentFee[tokenId]; - if (amountToRefund == 0 || availablePledgedAmount < amountToRefund) { + if (amountToRefund == 0 || (availablePledgedAmount + paymentFee) < amountToRefund) { revert KeepWhatsRaisedNotClaimable(tokenId); } - s_tokenToPledgedAmount[tokenId] -= amountToRefund; + s_tokenToPledgedAmount[tokenId] = 0; s_pledgedAmount -= amountToRefund; - s_availablePledgedAmount -= amountToRefund; + s_availablePledgedAmount -= (amountToRefund - paymentFee); + s_tokenToPaymentFee[tokenId] = 0; + s_platformFee -= paymentFee; + burn(tokenId); TOKEN.safeTransfer(msg.sender, amountToRefund); emit RefundClaimed(tokenId, amountToRefund, msg.sender); @@ -735,6 +730,10 @@ contract KeepWhatsRaised is whenNotPaused whenNotCancelled { + if (!_checkRefundPeriodStatus(true)) { + revert KeepWhatsRaisedDisbursementBlocked(); + } + uint256 protocolShare = s_protocolFee; uint256 platformShare = s_platformFee; (s_protocolFee, s_platformFee) = (0, 0); @@ -797,7 +796,7 @@ contract KeepWhatsRaised is whenNotPaused { bool isCancelled = s_cancellationTime > 0; - uint256 cancelLimit = s_cancellationTime + s_config.withdrawalDelay; + uint256 cancelLimit = s_cancellationTime + s_config.refundDelay; uint256 deadlineLimit = getDeadline() + s_config.withdrawalDelay; if ((isCancelled && block.timestamp <= cancelLimit) || (!isCancelled && block.timestamp <= deadlineLimit)) { @@ -825,13 +824,7 @@ contract KeepWhatsRaised is * @inheritdoc BaseTreasury * @dev This function is overridden to allow the platform admin and the campaign owner to cancel a treasury. */ - function cancelTreasury(bytes32 message) public override { - if ( - msg.sender != INFO.getPlatformAdminAddress(PLATFORM_HASH) && - msg.sender != INFO.owner() - ) { - revert KeepWhatsRaisedUnAuthorized(); - } + function cancelTreasury(bytes32 message) public override onlyPlatformAdminOrCampaignOwner { s_cancellationTime = block.timestamp; _cancel(message); } @@ -858,13 +851,17 @@ contract KeepWhatsRaised is bytes32[] memory rewards ) private { uint256 totalAmount = pledgeAmount + tip; + TOKEN.safeTransferFrom(backer, address(this), totalAmount); + s_tokenIdCounter.increment(); s_tokenToPledgedAmount[tokenId] = pledgeAmount; s_tokenToTippedAmount[tokenId] = tip; s_pledgedAmount += pledgeAmount; - s_availablePledgedAmount += pledgeAmount; s_tip += tip; - TOKEN.safeTransferFrom(backer, address(this), totalAmount); - s_tokenIdCounter.increment(); + + //Fee Calculation + pledgeAmount = _calculateNetAvailable(tokenId, pledgeAmount); + s_availablePledgedAmount += pledgeAmount; + _safeMint(backer, tokenId, abi.encodePacked(backer, reward)); emit Receipt( backer, @@ -876,6 +873,85 @@ contract KeepWhatsRaised is ); } + /** + * @dev Calculates the net available amount after deducting platform fees and applicable taxes + * @param tokenId The ID of the token representing the pledge. + * @param pledgeAmount The total pledge amount before any deductions + * @return The net available amount after all fees and taxes are deducted + * + * @notice This function performs the following calculations: + * 1. Applies all gross percentage fees based on platform configuration + * 2. Calculates Colombian creator tax if applicable (0.4% effective rate) + * 3. Updates the total platform fee accumulator + */ + function _calculateNetAvailable(uint256 tokenId, uint256 pledgeAmount) internal returns (uint256) { + uint256 totalFee = 0; + + // Gross Percentage Fee Calculation + uint256 len = s_feeKeys.grossPercentageFeeKeys.length; + for (uint256 i = 0; i < len; i++) { + uint256 fee = (pledgeAmount * uint256(INFO.getPlatformData(s_feeKeys.grossPercentageFeeKeys[i]))) + / PERCENT_DIVIDER; + s_platformFee += fee; + totalFee += fee; + } + + uint256 availableBeforeTax = pledgeAmount - totalFee; + + // Colombian creator tax + if (s_config.isColumbianCreator) { + // Formula: (availableBeforeTax * 0.004) / 1.004 ≈ ((availableBeforeTax * 40) / 10040) + uint256 scaled = availableBeforeTax * PERCENT_DIVIDER; + uint256 numerator = scaled * 40; + uint256 denominator = 10040; + uint256 columbianCreatorTax = numerator / (denominator * PERCENT_DIVIDER); + + s_platformFee += columbianCreatorTax; + totalFee += columbianCreatorTax; + } + + s_tokenToPaymentFee[tokenId] = totalFee; + + return pledgeAmount - totalFee; + } + + /** + * @dev Checks the refund period status based on campaign state + * @param checkIfOver If true, returns whether refund period is over; if false, returns whether currently within refund period + * @return bool Status based on checkIfOver parameter + * + * @notice Refund period logic: + * - If campaign is cancelled: refund period is active until s_cancellationTime + s_config.refundDelay + * - If campaign is not cancelled: refund period is active until deadline + s_config.refundDelay + * - Before deadline (non-cancelled): not in refund period + * + * @dev This function handles both cancelled and non-cancelled campaign scenarios + */ + function _checkRefundPeriodStatus(bool checkIfOver) internal view returns (bool) { + uint256 deadline = getDeadline(); + bool isCancelled = s_cancellationTime > 0; + + bool refundPeriodOver; + + if (isCancelled) { + // If cancelled, refund period ends after s_config.refundDelay from cancellation time + refundPeriodOver = block.timestamp > s_cancellationTime + s_config.refundDelay; + } else { + // If not cancelled, refund period ends after s_config.refundDelay from deadline + refundPeriodOver = block.timestamp > deadline + s_config.refundDelay; + } + + if (checkIfOver) { + return refundPeriodOver; + } else { + // For non-cancelled campaigns, also check if we're after deadline + if (!isCancelled) { + return block.timestamp > deadline && !refundPeriodOver; + } + return !refundPeriodOver; + } + } + // The following functions are overrides required by Solidity. function supportsInterface( bytes4 interfaceId From f3cef36acbc7535781ec19da05fe556214b7e897 Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Tue, 17 Jun 2025 17:28:33 +0600 Subject: [PATCH 24/63] Update `KeepWhatsRaised` deployment script --- script/DeployAllAndSetupKeepWhatsRaised.s.sol | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/script/DeployAllAndSetupKeepWhatsRaised.s.sol b/script/DeployAllAndSetupKeepWhatsRaised.s.sol index b50b1653..106b05f5 100644 --- a/script/DeployAllAndSetupKeepWhatsRaised.s.sol +++ b/script/DeployAllAndSetupKeepWhatsRaised.s.sol @@ -88,8 +88,8 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { PLATFORM_FEE_KEY = bytes32("platformFee"); FLAT_FEE_KEY = bytes32("flatFee"); CUMULATIVE_FLAT_FEE_KEY = bytes32("cumulativeFlatFee"); - PAYMENT_GATEWAY_FEE_KEY = bytes32("paymentGatewayFee"); - COLUMBIAN_CREATOR_TAX_KEY = bytes32("columbianCreatorTax"); + //PAYMENT_GATEWAY_FEE_KEY = bytes32("paymentGatewayFee"); + //COLUMBIAN_CREATOR_TAX_KEY = bytes32("columbianCreatorTax"); console2.log("Platform Fee Key:"); console2.logBytes32(PLATFORM_FEE_KEY); @@ -97,10 +97,10 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { console2.logBytes32(FLAT_FEE_KEY); console2.log("Cumulative Fee Key:"); console2.logBytes32(CUMULATIVE_FLAT_FEE_KEY); - console2.log("Payment Gateway Fee Key:"); - console2.logBytes32(PAYMENT_GATEWAY_FEE_KEY); - console2.log("Columbian Creator Tax Key:"); - console2.logBytes32(COLUMBIAN_CREATOR_TAX_KEY); + // console2.log("Payment Gateway Fee Key:"); + // console2.logBytes32(PAYMENT_GATEWAY_FEE_KEY); + // console2.log("Columbian Creator Tax Key:"); + // console2.logBytes32(COLUMBIAN_CREATOR_TAX_KEY); console2.log("Using platform hash for:", platformName); console2.log("Protocol fee percent:", protocolFeePercent); @@ -288,14 +288,14 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { platformHash, CUMULATIVE_FLAT_FEE_KEY ); - GlobalParams(globalParams).addPlatformData( - platformHash, - PAYMENT_GATEWAY_FEE_KEY - ); - GlobalParams(globalParams).addPlatformData( - platformHash, - COLUMBIAN_CREATOR_TAX_KEY - ); + // GlobalParams(globalParams).addPlatformData( + // platformHash, + // PAYMENT_GATEWAY_FEE_KEY + // ); + // GlobalParams(globalParams).addPlatformData( + // platformHash, + // COLUMBIAN_CREATOR_TAX_KEY + // ); if (simulate) { vm.stopPrank(); From 7ba93df0a979ce4ef420098855e6b4bfadbb6ecd Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Wed, 18 Jun 2025 17:39:34 +0600 Subject: [PATCH 25/63] Add payment gateway fee calculation - Add support for setting the payment gateway fee by the platform admin - Add a facade function `setFeeAndPledge` to combine fee setting and pledge for the platform admin - Update pledge functionality to accommodate payment gateway fee calculation --- src/treasuries/KeepWhatsRaised.sol | 113 +++++++++++++++++++++++++++-- 1 file changed, 107 insertions(+), 6 deletions(-) diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index b480fd8b..0446e4c7 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -34,6 +34,10 @@ contract KeepWhatsRaised is mapping(uint256 => uint256) private s_tokenToPaymentFee; // Mapping to store reward details by name mapping(bytes32 => Reward) private s_reward; + /// Tracks whether a pledge with a specific ID has already been processed + mapping(bytes32 => bool) public s_processedPledges; + /// Mapping to store payment gateway fees by unique pledge ID + mapping(bytes32 => uint256) public s_paymentGatewayFees; // Counters for token IDs and rewards Counters.Counter private s_tokenIdCounter; @@ -175,6 +179,13 @@ contract KeepWhatsRaised is */ event KeepWhatsRaisedGoalAmountUpdated(uint256 newGoalAmount); + /** + * @dev Emitted when a gateway fee is set for a specific pledge. + * @param pledgeId The unique identifier of the pledge. + * @param fee The amount of the payment gateway fee set. + */ + event KeepWhatsRaisedPaymentGatewayFeeSet(bytes32 indexed pledgeId, uint256 fee); + /** * @dev Emitted when an unauthorized action is attempted. */ @@ -239,6 +250,12 @@ contract KeepWhatsRaised is */ error KeepWhatsRaisedDisbursementBlocked(); + /** + * @dev Emitted when a pledge is submitted using a pledgeId that has already been processed. + * @param pledgeId The unique identifier of the pledge that was already used. + */ + error KeepWhatsRaisedPledgeAlreadyProcessed(bytes32 pledgeId); + /** * @dev Ensures that withdrawals are currently enabled. * Reverts with `KeepWhatsRaisedDisabled` if the withdrawal approval flag is not set. @@ -359,6 +376,33 @@ contract KeepWhatsRaised is return s_campaignData.goalAmount; } + /** + * @notice Retrieves the payment gateway fee for a given pledge ID. + * @param pledgeId The unique identifier of the pledge. + * @return The fixed gateway fee amount associated with the pledge ID. + */ + function getPaymentGatewayFee(bytes32 pledgeId) public view returns (uint256) { + return s_paymentGatewayFees[pledgeId]; + } + + /** + * @notice Sets the fixed payment gateway fee for a specific pledge. + * @param pledgeId The unique identifier of the pledge. + * @param fee The gateway fee amount to be associated with the given pledge ID. + */ + function setPaymentGatewayFee(bytes32 pledgeId, uint256 fee) + public + onlyPlatformAdmin(PLATFORM_HASH) + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled + { + s_paymentGatewayFees[pledgeId] = fee; + + emit KeepWhatsRaisedPaymentGatewayFeeSet(pledgeId, fee); + } + /** * @notice Approves the withdrawal of the treasury by the platform admin. */ @@ -535,26 +579,69 @@ contract KeepWhatsRaised is emit RewardRemoved(rewardName); } + /** + * @notice Sets the payment gateway fee and executes a pledge in a single transaction. + * @param pledgeId The unique identifier of the pledge. + * @param backer The address of the backer making the pledge. + * @param pledgeAmount The amount of the pledge. + * @param tip An optional tip can be added during the process. + * @param fee The payment gateway fee to associate with this pledge. + * @param reward An array of reward names. + * @param isPledgeForAReward A boolean indicating whether this pledge is for a reward or without.. + */ + function setFeeAndPledge( + bytes32 pledgeId, + address backer, + uint256 pledgeAmount, + uint256 tip, + uint256 fee, + bytes32[] calldata reward, + bool isPledgeForAReward + ) + external + onlyPlatformAdmin(PLATFORM_HASH) + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled + { + //Set Payment Gateway Fee + setPaymentGatewayFee(pledgeId, fee); + + if(isPledgeForAReward){ + pledgeForAReward(pledgeId, backer, tip, reward); + }else { + pledgeWithoutAReward(pledgeId, backer, pledgeAmount, tip); + } + } + /** * @notice Allows a backer to pledge for a reward. * @dev The first element of the `reward` array must be a reward tier and the other elements can be either reward tiers or non-reward tiers. * The non-reward tiers cannot be pledged for without a reward. + * @param pledgeId The unique identifier of the pledge. * @param backer The address of the backer making the pledge. * @param tip An optional tip can be added during the process. * @param reward An array of reward names. */ function pledgeForAReward( + bytes32 pledgeId, address backer, uint256 tip, bytes32[] calldata reward ) - external + public currentTimeIsWithinRange(getLaunchTime(), getDeadline()) whenCampaignNotPaused whenNotPaused whenCampaignNotCancelled whenNotCancelled { + if(s_processedPledges[pledgeId]){ + revert KeepWhatsRaisedPledgeAlreadyProcessed(pledgeId); + } + s_processedPledges[pledgeId] = true; + uint256 tokenId = s_tokenIdCounter.current(); uint256 rewardLen = reward.length; Reward memory tempReward = s_reward[reward[0]]; @@ -573,31 +660,38 @@ contract KeepWhatsRaised is } pledgeAmount += s_reward[reward[i]].rewardValue; } - _pledge(backer, reward[0], pledgeAmount, tip, tokenId, reward); + _pledge(pledgeId, backer, reward[0], pledgeAmount, tip, tokenId, reward); } /** * @notice Allows a backer to pledge without selecting a reward. + * @param pledgeId The unique identifier of the pledge. * @param backer The address of the backer making the pledge. * @param pledgeAmount The amount of the pledge. * @param tip An optional tip can be added during the process. */ function pledgeWithoutAReward( + bytes32 pledgeId, address backer, uint256 pledgeAmount, uint256 tip ) - external + public currentTimeIsWithinRange(getLaunchTime(), getDeadline()) whenCampaignNotPaused whenNotPaused whenCampaignNotCancelled whenNotCancelled { + if(s_processedPledges[pledgeId]){ + revert KeepWhatsRaisedPledgeAlreadyProcessed(pledgeId); + } + s_processedPledges[pledgeId] = true; + uint256 tokenId = s_tokenIdCounter.current(); bytes32[] memory emptyByteArray = new bytes32[](0); - _pledge(backer, ZERO_BYTES, pledgeAmount, tip, tokenId, emptyByteArray); + _pledge(pledgeId, backer, ZERO_BYTES, pledgeAmount, tip, tokenId, emptyByteArray); } /** @@ -843,6 +937,7 @@ contract KeepWhatsRaised is } function _pledge( + bytes32 pledgeId, address backer, bytes32 reward, uint256 pledgeAmount, @@ -859,7 +954,7 @@ contract KeepWhatsRaised is s_tip += tip; //Fee Calculation - pledgeAmount = _calculateNetAvailable(tokenId, pledgeAmount); + pledgeAmount = _calculateNetAvailable(pledgeId, tokenId, pledgeAmount); s_availablePledgedAmount += pledgeAmount; _safeMint(backer, tokenId, abi.encodePacked(backer, reward)); @@ -875,6 +970,7 @@ contract KeepWhatsRaised is /** * @dev Calculates the net available amount after deducting platform fees and applicable taxes + * @param pledgeId The unique identifier of the pledge. * @param tokenId The ID of the token representing the pledge. * @param pledgeAmount The total pledge amount before any deductions * @return The net available amount after all fees and taxes are deducted @@ -884,7 +980,7 @@ contract KeepWhatsRaised is * 2. Calculates Colombian creator tax if applicable (0.4% effective rate) * 3. Updates the total platform fee accumulator */ - function _calculateNetAvailable(uint256 tokenId, uint256 pledgeAmount) internal returns (uint256) { + function _calculateNetAvailable(bytes32 pledgeId, uint256 tokenId, uint256 pledgeAmount) internal returns (uint256) { uint256 totalFee = 0; // Gross Percentage Fee Calculation @@ -896,6 +992,11 @@ contract KeepWhatsRaised is totalFee += fee; } + //Payment Gateway Fee Calculation + uint256 paymentGatewayFee = getPaymentGatewayFee(pledgeId); + s_platformFee += paymentGatewayFee; + totalFee += paymentGatewayFee; + uint256 availableBeforeTax = pledgeAmount - totalFee; // Colombian creator tax From df8a737e3168a099ea536b0a6dbdcd7c6c483756 Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Wed, 18 Jun 2025 17:42:46 +0600 Subject: [PATCH 26/63] Update doc --- .../CampaignInfo.sol/contract.CampaignInfo.md | 2 +- .../contract.CampaignInfoFactory.md | 2 +- .../GlobalParams.sol/contract.GlobalParams.md | 2 +- .../contract.TreasuryFactory.md | 2 +- .../interface.ICampaignData.md | 2 +- .../interface.ICampaignInfo.md | 2 +- .../interface.ICampaignInfoFactory.md | 2 +- .../interface.ICampaignTreasury.md | 2 +- .../interface.IGlobalParams.md | 2 +- .../interfaces/IItem.sol/interface.IItem.md | 2 +- .../IReward.sol/interface.IReward.md | 2 +- .../interface.ITreasuryFactory.md | 2 +- .../AllOrNothing.sol/contract.AllOrNothing.md | 2 +- .../contract.KeepWhatsRaised.md | 229 +++++++++++++++++- .../abstract.AdminAccessChecker.md | 2 +- .../BaseTreasury.sol/abstract.BaseTreasury.md | 2 +- .../abstract.CampaignAccessChecker.md | 2 +- .../utils/Counters.sol/library.Counters.md | 2 +- .../FiatEnabled.sol/abstract.FiatEnabled.md | 2 +- .../ItemRegistry.sol/contract.ItemRegistry.md | 2 +- .../abstract.PausableCancellable.md | 2 +- .../abstract.TimestampChecker.md | 2 +- 22 files changed, 241 insertions(+), 30 deletions(-) diff --git a/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md b/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md index 95cc4d89..fa856637 100644 --- a/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md +++ b/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md @@ -1,5 +1,5 @@ # CampaignInfo -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/CampaignInfo.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/CampaignInfo.sol) **Inherits:** [ICampaignData](/src/interfaces/ICampaignData.sol/interface.ICampaignData.md), [ICampaignInfo](/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md), Ownable, [PausableCancellable](/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md), [TimestampChecker](/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), [AdminAccessChecker](/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md), Initializable diff --git a/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md b/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md index fdc01d75..9ae1b6f6 100644 --- a/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md +++ b/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md @@ -1,5 +1,5 @@ # CampaignInfoFactory -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/CampaignInfoFactory.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/CampaignInfoFactory.sol) **Inherits:** Initializable, [ICampaignInfoFactory](/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md), Ownable diff --git a/docs/src/src/GlobalParams.sol/contract.GlobalParams.md b/docs/src/src/GlobalParams.sol/contract.GlobalParams.md index 9dd73907..597a882a 100644 --- a/docs/src/src/GlobalParams.sol/contract.GlobalParams.md +++ b/docs/src/src/GlobalParams.sol/contract.GlobalParams.md @@ -1,5 +1,5 @@ # GlobalParams -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/GlobalParams.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/GlobalParams.sol) **Inherits:** [IGlobalParams](/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md), Ownable diff --git a/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md b/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md index 8159863d..b18d8e9a 100644 --- a/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md +++ b/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md @@ -1,5 +1,5 @@ # TreasuryFactory -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/TreasuryFactory.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/TreasuryFactory.sol) **Inherits:** [ITreasuryFactory](/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md), [AdminAccessChecker](/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md) diff --git a/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md b/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md index c750b17c..ba386fea 100644 --- a/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md +++ b/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md @@ -1,5 +1,5 @@ # ICampaignData -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/interfaces/ICampaignData.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/interfaces/ICampaignData.sol) An interface for managing campaign data in a CCP. diff --git a/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md b/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md index 5b99629e..92515c8e 100644 --- a/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md +++ b/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md @@ -1,5 +1,5 @@ # ICampaignInfo -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/interfaces/ICampaignInfo.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/interfaces/ICampaignInfo.sol) An interface for managing campaign information in a crowdfunding system. diff --git a/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md b/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md index 48d8be15..83fdb398 100644 --- a/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md +++ b/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md @@ -1,5 +1,5 @@ # ICampaignInfoFactory -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/interfaces/ICampaignInfoFactory.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/interfaces/ICampaignInfoFactory.sol) **Inherits:** [ICampaignData](/src/interfaces/ICampaignData.sol/interface.ICampaignData.md) diff --git a/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md b/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md index 77061baa..9d3a5eb6 100644 --- a/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md +++ b/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md @@ -1,5 +1,5 @@ # ICampaignTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/interfaces/ICampaignTreasury.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/interfaces/ICampaignTreasury.sol) An interface for managing campaign treasury contracts. diff --git a/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md b/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md index fc1631cc..da479844 100644 --- a/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md +++ b/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md @@ -1,5 +1,5 @@ # IGlobalParams -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/interfaces/IGlobalParams.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/interfaces/IGlobalParams.sol) An interface for accessing and managing global parameters of the protocol. diff --git a/docs/src/src/interfaces/IItem.sol/interface.IItem.md b/docs/src/src/interfaces/IItem.sol/interface.IItem.md index db84d41a..c0a88b8d 100644 --- a/docs/src/src/interfaces/IItem.sol/interface.IItem.md +++ b/docs/src/src/interfaces/IItem.sol/interface.IItem.md @@ -1,5 +1,5 @@ # IItem -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/interfaces/IItem.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/interfaces/IItem.sol) An interface for managing items and their attributes. diff --git a/docs/src/src/interfaces/IReward.sol/interface.IReward.md b/docs/src/src/interfaces/IReward.sol/interface.IReward.md index 9cf3569b..19f51a56 100644 --- a/docs/src/src/interfaces/IReward.sol/interface.IReward.md +++ b/docs/src/src/interfaces/IReward.sol/interface.IReward.md @@ -1,5 +1,5 @@ # IReward -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/interfaces/IReward.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/interfaces/IReward.sol) An interface for managing rewards in a campaign. diff --git a/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md b/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md index 76832933..e95ad0c5 100644 --- a/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md +++ b/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md @@ -1,5 +1,5 @@ # ITreasuryFactory -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/interfaces/ITreasuryFactory.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/interfaces/ITreasuryFactory.sol) *Interface for the TreasuryFactory contract, which registers, approves, and deploys treasury clones.* diff --git a/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md b/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md index e03bf729..8382b7c6 100644 --- a/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md +++ b/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md @@ -1,5 +1,5 @@ # AllOrNothing -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/treasuries/AllOrNothing.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/treasuries/AllOrNothing.sol) **Inherits:** [IReward](/src/interfaces/IReward.sol/interface.IReward.md), [BaseTreasury](/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md), [TimestampChecker](/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), ERC721Burnable diff --git a/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md b/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md index f631d037..3c6d69cb 100644 --- a/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md +++ b/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md @@ -1,5 +1,5 @@ # KeepWhatsRaised -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/treasuries/KeepWhatsRaised.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/treasuries/KeepWhatsRaised.sol) **Inherits:** [IReward](/src/interfaces/IReward.sol/interface.IReward.md), [BaseTreasury](/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md), [TimestampChecker](/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), ERC721Burnable, [ICampaignData](/src/interfaces/ICampaignData.sol/interface.ICampaignData.md) @@ -22,6 +22,13 @@ mapping(uint256 => uint256) private s_tokenToTippedAmount; ``` +### s_tokenToPaymentFee + +```solidity +mapping(uint256 => uint256) private s_tokenToPaymentFee; +``` + + ### s_reward ```solidity @@ -29,6 +36,24 @@ mapping(bytes32 => Reward) private s_reward; ``` +### s_processedPledges +Tracks whether a pledge with a specific ID has already been processed + + +```solidity +mapping(bytes32 => bool) public s_processedPledges; +``` + + +### s_paymentGatewayFees +Mapping to store payment gateway fees by unique pledge ID + + +```solidity +mapping(bytes32 => uint256) public s_paymentGatewayFees; +``` + + ### s_tokenIdCounter ```solidity @@ -156,6 +181,18 @@ The lock period is defined as the duration before the deadline during which conf modifier onlyBeforeConfigLock(); ``` +### onlyPlatformAdminOrCampaignOwner + +Restricts access to only the platform admin or the campaign owner. + +*Checks if `msg.sender` is either the platform admin (via `INFO.getPlatformAdminAddress`) +or the campaign owner (via `INFO.owner()`). Reverts with `KeepWhatsRaisedUnAuthorized` if not authorized.* + + +```solidity +modifier onlyPlatformAdminOrCampaignOwner(); +``` + ### constructor *Constructor for the KeepWhatsRaised contract.* @@ -293,6 +330,49 @@ function getGoalAmount() external view returns (uint256); |``|`uint256`|The funding goal amount of the campaign.| +### getPaymentGatewayFee + +Retrieves the payment gateway fee for a given pledge ID. + + +```solidity +function getPaymentGatewayFee(bytes32 pledgeId) public view returns (uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`pledgeId`|`bytes32`|The unique identifier of the pledge.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The fixed gateway fee amount associated with the pledge ID.| + + +### setPaymentGatewayFee + +Sets the fixed payment gateway fee for a specific pledge. + + +```solidity +function setPaymentGatewayFee(bytes32 pledgeId, uint256 fee) + public + onlyPlatformAdmin(PLATFORM_HASH) + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`pledgeId`|`bytes32`|The unique identifier of the pledge.| +|`fee`|`uint256`|The gateway fee amount to be associated with the given pledge ID.| + + ### approveWithdrawal Approves the withdrawal of the treasury by the platform admin. @@ -340,7 +420,7 @@ function configureTreasury(Config memory config, CampaignData memory campaignDat ```solidity function updateDeadline(uint256 deadline) external - onlyPlatformAdmin(PLATFORM_HASH) + onlyPlatformAdminOrCampaignOwner onlyBeforeConfigLock whenNotPaused whenNotCancelled; @@ -360,7 +440,7 @@ function updateDeadline(uint256 deadline) ```solidity function updateGoalAmount(uint256 goalAmount) external - onlyPlatformAdmin(PLATFORM_HASH) + onlyPlatformAdminOrCampaignOwner onlyBeforeConfigLock whenNotPaused whenNotCancelled; @@ -420,6 +500,41 @@ function removeReward(bytes32 rewardName) |`rewardName`|`bytes32`|The name of the reward.| +### setFeeAndPledge + +Sets the payment gateway fee and executes a pledge in a single transaction. + + +```solidity +function setFeeAndPledge( + bytes32 pledgeId, + address backer, + uint256 pledgeAmount, + uint256 tip, + uint256 fee, + bytes32[] calldata reward, + bool isPledgeForAReward +) + external + onlyPlatformAdmin(PLATFORM_HASH) + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`pledgeId`|`bytes32`|The unique identifier of the pledge.| +|`backer`|`address`|The address of the backer making the pledge.| +|`pledgeAmount`|`uint256`|The amount of the pledge.| +|`tip`|`uint256`|An optional tip can be added during the process.| +|`fee`|`uint256`|The payment gateway fee to associate with this pledge.| +|`reward`|`bytes32[]`|An array of reward names.| +|`isPledgeForAReward`|`bool`|A boolean indicating whether this pledge is for a reward or without..| + + ### pledgeForAReward Allows a backer to pledge for a reward. @@ -429,8 +544,8 @@ The non-reward tiers cannot be pledged for without a reward.* ```solidity -function pledgeForAReward(address backer, uint256 tip, bytes32[] calldata reward) - external +function pledgeForAReward(bytes32 pledgeId, address backer, uint256 tip, bytes32[] calldata reward) + public currentTimeIsWithinRange(getLaunchTime(), getDeadline()) whenCampaignNotPaused whenNotPaused @@ -441,6 +556,7 @@ function pledgeForAReward(address backer, uint256 tip, bytes32[] calldata reward |Name|Type|Description| |----|----|-----------| +|`pledgeId`|`bytes32`|The unique identifier of the pledge.| |`backer`|`address`|The address of the backer making the pledge.| |`tip`|`uint256`|An optional tip can be added during the process.| |`reward`|`bytes32[]`|An array of reward names.| @@ -452,8 +568,8 @@ Allows a backer to pledge without selecting a reward. ```solidity -function pledgeWithoutAReward(address backer, uint256 pledgeAmount, uint256 tip) - external +function pledgeWithoutAReward(bytes32 pledgeId, address backer, uint256 pledgeAmount, uint256 tip) + public currentTimeIsWithinRange(getLaunchTime(), getDeadline()) whenCampaignNotPaused whenNotPaused @@ -464,6 +580,7 @@ function pledgeWithoutAReward(address backer, uint256 pledgeAmount, uint256 tip) |Name|Type|Description| |----|----|-----------| +|`pledgeId`|`bytes32`|The unique identifier of the pledge.| |`backer`|`address`|The address of the backer making the pledge.| |`pledgeAmount`|`uint256`|The amount of the pledge.| |`tip`|`uint256`|An optional tip can be added during the process.| @@ -558,7 +675,7 @@ function claimFund() external onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPa ```solidity -function cancelTreasury(bytes32 message) public override; +function cancelTreasury(bytes32 message) public override onlyPlatformAdminOrCampaignOwner; ``` ### _checkSuccessCondition @@ -581,6 +698,7 @@ function _checkSuccessCondition() internal view virtual override returns (bool); ```solidity function _pledge( + bytes32 pledgeId, address backer, bytes32 reward, uint256 pledgeAmount, @@ -590,6 +708,62 @@ function _pledge( ) private; ``` +### _calculateNetAvailable + +This function performs the following calculations: +1. Applies all gross percentage fees based on platform configuration +2. Calculates Colombian creator tax if applicable (0.4% effective rate) +3. Updates the total platform fee accumulator + +*Calculates the net available amount after deducting platform fees and applicable taxes* + + +```solidity +function _calculateNetAvailable(bytes32 pledgeId, uint256 tokenId, uint256 pledgeAmount) internal returns (uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`pledgeId`|`bytes32`|The unique identifier of the pledge.| +|`tokenId`|`uint256`|The ID of the token representing the pledge.| +|`pledgeAmount`|`uint256`|The total pledge amount before any deductions| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The net available amount after all fees and taxes are deducted| + + +### _checkRefundPeriodStatus + +Refund period logic: +- If campaign is cancelled: refund period is active until s_cancellationTime + s_config.refundDelay +- If campaign is not cancelled: refund period is active until deadline + s_config.refundDelay +- Before deadline (non-cancelled): not in refund period + +*Checks the refund period status based on campaign state* + +*This function handles both cancelled and non-cancelled campaign scenarios* + + +```solidity +function _checkRefundPeriodStatus(bool checkIfOver) internal view returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`checkIfOver`|`bool`|If true, returns whether refund period is over; if false, returns whether currently within refund period| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|bool Status based on checkIfOver parameter| + + ### supportsInterface @@ -767,6 +941,21 @@ event KeepWhatsRaisedGoalAmountUpdated(uint256 newGoalAmount); |----|----|-----------| |`newGoalAmount`|`uint256`|The new goal amount set for the campaign.| +### KeepWhatsRaisedPaymentGatewayFeeSet +*Emitted when a gateway fee is set for a specific pledge.* + + +```solidity +event KeepWhatsRaisedPaymentGatewayFeeSet(bytes32 indexed pledgeId, uint256 fee); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`pledgeId`|`bytes32`|The unique identifier of the pledge.| +|`fee`|`uint256`|The amount of the payment gateway fee set.| + ## Errors ### KeepWhatsRaisedUnAuthorized *Emitted when an unauthorized action is attempted.* @@ -870,6 +1059,28 @@ error KeepWhatsRaisedNotClaimableAdmin(); error KeepWhatsRaisedConfigLocked(); ``` +### KeepWhatsRaisedDisbursementBlocked +*Emitted when a disbursement is attempted before the refund period has ended.* + + +```solidity +error KeepWhatsRaisedDisbursementBlocked(); +``` + +### KeepWhatsRaisedPledgeAlreadyProcessed +*Emitted when a pledge is submitted using a pledgeId that has already been processed.* + + +```solidity +error KeepWhatsRaisedPledgeAlreadyProcessed(bytes32 pledgeId); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`pledgeId`|`bytes32`|The unique identifier of the pledge that was already used.| + ## Structs ### FeeKeys *Represents keys used to reference different fee configurations. @@ -881,7 +1092,6 @@ struct FeeKeys { bytes32 flatFeeKey; bytes32 cumulativeFlatFeeKey; bytes32[] grossPercentageFeeKeys; - bytes32[] netPercentageFeeKeys; } ``` @@ -895,6 +1105,7 @@ struct Config { uint256 withdrawalDelay; uint256 refundDelay; uint256 configLockPeriod; + bool isColumbianCreator; } ``` diff --git a/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md b/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md index 78f05214..c8c5e343 100644 --- a/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md +++ b/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md @@ -1,5 +1,5 @@ # AdminAccessChecker -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/utils/AdminAccessChecker.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/utils/AdminAccessChecker.sol) *This abstract contract provides access control mechanisms to restrict the execution of specific functions to authorized protocol administrators and platform administrators.* diff --git a/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md b/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md index b035f172..2696fddf 100644 --- a/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md +++ b/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md @@ -1,5 +1,5 @@ # BaseTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/utils/BaseTreasury.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/utils/BaseTreasury.sol) **Inherits:** Initializable, [ICampaignTreasury](/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md), [CampaignAccessChecker](/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md), [PausableCancellable](/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md) diff --git a/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md b/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md index 9a1106e9..5e7e86f3 100644 --- a/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md +++ b/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md @@ -1,5 +1,5 @@ # CampaignAccessChecker -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/utils/CampaignAccessChecker.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/utils/CampaignAccessChecker.sol) *This abstract contract provides access control mechanisms to restrict the execution of specific functions to authorized protocol administrators, platform administrators, and campaign owners.* diff --git a/docs/src/src/utils/Counters.sol/library.Counters.md b/docs/src/src/utils/Counters.sol/library.Counters.md index 4119f2e8..e77e31ec 100644 --- a/docs/src/src/utils/Counters.sol/library.Counters.md +++ b/docs/src/src/utils/Counters.sol/library.Counters.md @@ -1,5 +1,5 @@ # Counters -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/utils/Counters.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/utils/Counters.sol) ## Functions diff --git a/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md b/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md index 592982b1..931e48e2 100644 --- a/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md +++ b/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md @@ -1,5 +1,5 @@ # FiatEnabled -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/utils/FiatEnabled.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/utils/FiatEnabled.sol) A contract that provides functionality for tracking and managing fiat transactions. This contract allows tracking the amount of fiat raised, individual fiat transactions, and the state of fiat fee disbursement. diff --git a/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md b/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md index 2d0099b3..daf05851 100644 --- a/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md +++ b/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md @@ -1,5 +1,5 @@ # ItemRegistry -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/utils/ItemRegistry.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/utils/ItemRegistry.sol) **Inherits:** [IItem](/src/interfaces/IItem.sol/interface.IItem.md), Context diff --git a/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md b/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md index dbdb866a..971399a6 100644 --- a/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md +++ b/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md @@ -1,5 +1,5 @@ # PausableCancellable -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/utils/PausableCancellable.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/utils/PausableCancellable.sol) Abstract contract providing pause and cancel state management with events and modifiers diff --git a/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md b/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md index 5252648e..07857448 100644 --- a/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md +++ b/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md @@ -1,5 +1,5 @@ # TimestampChecker -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ac353e6507e46c7ee7bc7cb49a3fb20dfde2b56/src/utils/TimestampChecker.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/utils/TimestampChecker.sol) A contract that provides timestamp-related checks for contract functions. From c1008fa1956629f20ecf4e509f8a762ce0b2219e Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Mon, 23 Jun 2025 17:57:27 +0600 Subject: [PATCH 27/63] Fix `KeepWhatsRaised` deployment issue --- script/DeployAllAndSetupKeepWhatsRaised.s.sol | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/script/DeployAllAndSetupKeepWhatsRaised.s.sol b/script/DeployAllAndSetupKeepWhatsRaised.s.sol index 106b05f5..4dd2d31e 100644 --- a/script/DeployAllAndSetupKeepWhatsRaised.s.sol +++ b/script/DeployAllAndSetupKeepWhatsRaised.s.sol @@ -85,11 +85,9 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { keepWhatsRaisedImplementation = vm.envOr("KEEP_WHATS_RAISED_IMPLEMENTATION_ADDRESS", address(0)); //Get Treasury Keys - PLATFORM_FEE_KEY = bytes32("platformFee"); - FLAT_FEE_KEY = bytes32("flatFee"); - CUMULATIVE_FLAT_FEE_KEY = bytes32("cumulativeFlatFee"); - //PAYMENT_GATEWAY_FEE_KEY = bytes32("paymentGatewayFee"); - //COLUMBIAN_CREATOR_TAX_KEY = bytes32("columbianCreatorTax"); + PLATFORM_FEE_KEY = keccak256(abi.encodePacked("platformFee")); + FLAT_FEE_KEY = keccak256(abi.encodePacked("flatFee")); + CUMULATIVE_FLAT_FEE_KEY = keccak256(abi.encodePacked("cumulativeFlatFee")); console2.log("Platform Fee Key:"); console2.logBytes32(PLATFORM_FEE_KEY); @@ -97,10 +95,6 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { console2.logBytes32(FLAT_FEE_KEY); console2.log("Cumulative Fee Key:"); console2.logBytes32(CUMULATIVE_FLAT_FEE_KEY); - // console2.log("Payment Gateway Fee Key:"); - // console2.logBytes32(PAYMENT_GATEWAY_FEE_KEY); - // console2.log("Columbian Creator Tax Key:"); - // console2.logBytes32(COLUMBIAN_CREATOR_TAX_KEY); console2.log("Using platform hash for:", platformName); console2.log("Protocol fee percent:", protocolFeePercent); @@ -288,14 +282,6 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { platformHash, CUMULATIVE_FLAT_FEE_KEY ); - // GlobalParams(globalParams).addPlatformData( - // platformHash, - // PAYMENT_GATEWAY_FEE_KEY - // ); - // GlobalParams(globalParams).addPlatformData( - // platformHash, - // COLUMBIAN_CREATOR_TAX_KEY - // ); if (simulate) { vm.stopPrank(); From 1cce474cfcdbc8bf0e4e83cb0bfcca620a975e85 Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Mon, 23 Jun 2025 20:00:01 +0600 Subject: [PATCH 28/63] Add non-refundable fee feature --- src/treasuries/KeepWhatsRaised.sol | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index 0446e4c7..807ee46b 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -797,19 +797,19 @@ contract KeepWhatsRaised is uint256 amountToRefund = s_tokenToPledgedAmount[tokenId]; uint256 availablePledgedAmount = s_availablePledgedAmount; uint256 paymentFee = s_tokenToPaymentFee[tokenId]; + uint256 netRefundAmount = amountToRefund - paymentFee; - if (amountToRefund == 0 || (availablePledgedAmount + paymentFee) < amountToRefund) { + if (netRefundAmount == 0 || availablePledgedAmount < netRefundAmount) { revert KeepWhatsRaisedNotClaimable(tokenId); } s_tokenToPledgedAmount[tokenId] = 0; s_pledgedAmount -= amountToRefund; - s_availablePledgedAmount -= (amountToRefund - paymentFee); + s_availablePledgedAmount -= netRefundAmount; s_tokenToPaymentFee[tokenId] = 0; - s_platformFee -= paymentFee; burn(tokenId); - TOKEN.safeTransfer(msg.sender, amountToRefund); - emit RefundClaimed(tokenId, amountToRefund, msg.sender); + TOKEN.safeTransfer(msg.sender, netRefundAmount); + emit RefundClaimed(tokenId, netRefundAmount, msg.sender); } /** From 81772c5141a3561b6cadd546f98dbb155a0296cb Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Wed, 25 Jun 2025 11:11:32 +0600 Subject: [PATCH 29/63] Remove time limit restriction for disbursement fee period --- src/treasuries/KeepWhatsRaised.sol | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index 807ee46b..d326aa75 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -824,10 +824,6 @@ contract KeepWhatsRaised is whenNotPaused whenNotCancelled { - if (!_checkRefundPeriodStatus(true)) { - revert KeepWhatsRaisedDisbursementBlocked(); - } - uint256 protocolShare = s_protocolFee; uint256 platformShare = s_platformFee; (s_protocolFee, s_platformFee) = (0, 0); From 3ab694bc5ce5037adb836a85fe710f413c2c20cc Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Wed, 25 Jun 2025 15:58:58 +0600 Subject: [PATCH 30/63] Update Colombian creator tax calculation to apply at withdrawal time --- src/treasuries/KeepWhatsRaised.sol | 32 +++++++++++++++++------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index d326aa75..6405cc5a 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -765,6 +765,24 @@ contract KeepWhatsRaised is revert KeepWhatsRaisedWithdrawalOverload(s_availablePledgedAmount, withdrawalAmount, totalFee); } + uint256 availableBeforeTax = withdrawalAmount - totalFee; + + // Colombian creator tax + if (s_config.isColumbianCreator) { + // Formula: (availableBeforeTax * 0.004) / 1.004 ≈ ((availableBeforeTax * 40) / 10040) + uint256 scaled = availableBeforeTax * PERCENT_DIVIDER; + uint256 numerator = scaled * 40; + uint256 denominator = 10040; + uint256 columbianCreatorTax = numerator / (denominator * PERCENT_DIVIDER); + + s_platformFee += columbianCreatorTax; + totalFee += columbianCreatorTax; + + if(totalFee > withdrawalAmount){ + revert KeepWhatsRaisedWithdrawalOverload(s_availablePledgedAmount, withdrawalAmount, totalFee); + } + } + s_availablePledgedAmount -= withdrawalAmount; withdrawalAmount -= totalFee; @@ -993,20 +1011,6 @@ contract KeepWhatsRaised is s_platformFee += paymentGatewayFee; totalFee += paymentGatewayFee; - uint256 availableBeforeTax = pledgeAmount - totalFee; - - // Colombian creator tax - if (s_config.isColumbianCreator) { - // Formula: (availableBeforeTax * 0.004) / 1.004 ≈ ((availableBeforeTax * 40) / 10040) - uint256 scaled = availableBeforeTax * PERCENT_DIVIDER; - uint256 numerator = scaled * 40; - uint256 denominator = 10040; - uint256 columbianCreatorTax = numerator / (denominator * PERCENT_DIVIDER); - - s_platformFee += columbianCreatorTax; - totalFee += columbianCreatorTax; - } - s_tokenToPaymentFee[tokenId] = totalFee; return pledgeAmount - totalFee; From 50f853a312e9ee01c856297695b071fdd7ee428e Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Wed, 25 Jun 2025 19:32:42 +0600 Subject: [PATCH 31/63] Fix variable naming --- src/treasuries/KeepWhatsRaised.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index 6405cc5a..38ed74bb 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -74,7 +74,7 @@ contract KeepWhatsRaised is uint256 configLockPeriod; /// @dev True if the creator is Colombian, false otherwise. - bool isColumbianCreator; + bool isColombianCreator; } string private s_name; @@ -768,7 +768,7 @@ contract KeepWhatsRaised is uint256 availableBeforeTax = withdrawalAmount - totalFee; // Colombian creator tax - if (s_config.isColumbianCreator) { + if (s_config.isColombianCreator) { // Formula: (availableBeforeTax * 0.004) / 1.004 ≈ ((availableBeforeTax * 40) / 10040) uint256 scaled = availableBeforeTax * PERCENT_DIVIDER; uint256 numerator = scaled * 40; From e44a2d34429de9ba8f5fc9a984ee600dada6289b Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Wed, 25 Jun 2025 19:34:12 +0600 Subject: [PATCH 32/63] Update `KeepWhatsRaised` contract doc --- .../KeepWhatsRaised.sol/contract.KeepWhatsRaised.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md b/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md index 3c6d69cb..0f1896c3 100644 --- a/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md +++ b/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md @@ -1,5 +1,5 @@ # KeepWhatsRaised -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/treasuries/KeepWhatsRaised.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/3ab694bc5ce5037adb836a85fe710f413c2c20cc/src/treasuries/KeepWhatsRaised.sol) **Inherits:** [IReward](/src/interfaces/IReward.sol/interface.IReward.md), [BaseTreasury](/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md), [TimestampChecker](/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), ERC721Burnable, [ICampaignData](/src/interfaces/ICampaignData.sol/interface.ICampaignData.md) @@ -1105,7 +1105,7 @@ struct Config { uint256 withdrawalDelay; uint256 refundDelay; uint256 configLockPeriod; - bool isColumbianCreator; + bool isColombianCreator; } ``` From ef41702e236d4d13d3608efb7cd2a3e600dfc3f2 Mon Sep 17 00:00:00 2001 From: AdnanHKx Date: Mon, 4 Aug 2025 19:44:32 +0600 Subject: [PATCH 33/63] Add tests for KeepWhatsRaised (#4) --- test/foundry/Base.t.sol | 5 +- .../KeepWhatsRaised/KeepWhatsRaised.t.sol | 481 ++++++ .../KeepWhatsRaisedFunction.t.sol | 580 +++++++ test/foundry/unit/KeepWhatsRaised.t.sol | 1326 +++++++++++++++++ test/foundry/utils/Defaults.sol | 104 +- 5 files changed, 2478 insertions(+), 18 deletions(-) create mode 100644 test/foundry/integration/KeepWhatsRaised/KeepWhatsRaised.t.sol create mode 100644 test/foundry/integration/KeepWhatsRaised/KeepWhatsRaisedFunction.t.sol create mode 100644 test/foundry/unit/KeepWhatsRaised.t.sol diff --git a/test/foundry/Base.t.sol b/test/foundry/Base.t.sol index ad771340..d7373a06 100644 --- a/test/foundry/Base.t.sol +++ b/test/foundry/Base.t.sol @@ -10,6 +10,7 @@ import {CampaignInfoFactory} from "src/CampaignInfoFactory.sol"; import {CampaignInfo} from "src/CampaignInfo.sol"; import {TreasuryFactory} from "src/TreasuryFactory.sol"; import {AllOrNothing} from "src/treasuries/AllOrNothing.sol"; +import {KeepWhatsRaised} from "src/treasuries/KeepWhatsRaised.sol"; /// @notice Base test contract with common logic needed by all tests. abstract contract Base_Test is Test, Defaults { @@ -22,6 +23,7 @@ abstract contract Base_Test is Test, Defaults { CampaignInfoFactory internal campaignInfoFactory; TreasuryFactory internal treasuryFactory; AllOrNothing internal allOrNothingImplementation; + KeepWhatsRaised internal keepWhatsRaisedImplementation; CampaignInfo internal campaignInfo; function setUp() public virtual { @@ -62,6 +64,7 @@ abstract contract Base_Test is Test, Defaults { ); allOrNothingImplementation = new AllOrNothing(); + keepWhatsRaisedImplementation = new KeepWhatsRaised(); //Mint token to the backer testToken.mint(users.backer1Address, TOKEN_MINT_AMOUNT); testToken.mint(users.backer2Address, TOKEN_MINT_AMOUNT); @@ -93,4 +96,4 @@ abstract contract Base_Test is Test, Defaults { vm.deal({account: user, newBalance: 100 ether}); return user; } -} +} \ No newline at end of file diff --git a/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaised.t.sol b/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaised.t.sol new file mode 100644 index 00000000..59ba173e --- /dev/null +++ b/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaised.t.sol @@ -0,0 +1,481 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.20; + +import "forge-std/Vm.sol"; +import "forge-std/console.sol"; +import {KeepWhatsRaised} from "src/treasuries/KeepWhatsRaised.sol"; +import {CampaignInfo} from "src/CampaignInfo.sol"; +import {IReward} from "src/interfaces/IReward.sol"; +import {ICampaignData} from "src/interfaces/ICampaignData.sol"; +import {LogDecoder} from "../../utils/LogDecoder.sol"; +import {Base_Test} from "../../Base.t.sol"; + +/// @notice Common testing logic needed by all KeepWhatsRaised integration tests. +abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder, Base_Test { + address campaignAddress; + address treasuryAddress; + KeepWhatsRaised internal keepWhatsRaised; + + uint256 pledgeForARewardTokenId; + + /// @dev Initial dependent functions setup included for KeepWhatsRaised Integration Tests. + function setUp() public virtual override { + super.setUp(); + console.log("setUp: enlistPlatform"); + + // Enlist Platform + enlistPlatform(PLATFORM_2_HASH); + console.log("enlisted platform"); + + registerTreasuryImplementation(PLATFORM_2_HASH); + console.log("registered treasury"); + + approveTreasuryImplementation(PLATFORM_2_HASH); + console.log("approved treasury"); + + // Add platform data keys + addPlatformData(PLATFORM_2_HASH); + console.log("added platform data"); + + // Create Campaign + createCampaign(PLATFORM_2_HASH); + console.log("created campaign"); + + // Deploy Treasury Contract + deploy(PLATFORM_2_HASH); + console.log("deployed treasury"); + + // Configure Treasury + configureTreasury(users.platform2AdminAddress, treasuryAddress, CONFIG, CAMPAIGN_DATA, FEE_KEYS); + console.log("configured treasury"); + } + + /** + * @notice Implements enlistPlatform helper function. + * @param platformHash The platform bytes. + */ + function enlistPlatform(bytes32 platformHash) internal { + vm.startPrank(users.protocolAdminAddress); + globalParams.enlistPlatform(platformHash, users.platform2AdminAddress, PLATFORM_FEE_PERCENT); + vm.stopPrank(); + } + + /** + * @notice Adds platform data keys. + * @param platformHash The platform bytes. + */ + function addPlatformData(bytes32 platformHash) internal { + vm.startPrank(users.platform2AdminAddress); + + // Add platform data keys (flat fees only, percentage fees are in GROSS_PERCENTAGE_FEE_KEYS) + globalParams.addPlatformData(platformHash, FLAT_FEE_KEY); + globalParams.addPlatformData(platformHash, CUMULATIVE_FLAT_FEE_KEY); + + // Add gross percentage fee keys (includes PLATFORM_FEE_KEY and VAKI_COMMISSION_KEY) + for (uint256 i = 0; i < GROSS_PERCENTAGE_FEE_KEYS.length; i++) { + globalParams.addPlatformData(platformHash, GROSS_PERCENTAGE_FEE_KEYS[i]); + } + + vm.stopPrank(); + } + + function registerTreasuryImplementation(bytes32 platformHash) internal { + vm.startPrank(users.platform2AdminAddress); + treasuryFactory.registerTreasuryImplementation(platformHash, 1, address(keepWhatsRaisedImplementation)); + vm.stopPrank(); + } + + function approveTreasuryImplementation(bytes32 platformHash) internal { + vm.startPrank(users.protocolAdminAddress); + treasuryFactory.approveTreasuryImplementation(platformHash, 1); + vm.stopPrank(); + } + + /** + * @notice Implements createCampaign helper function. It creates new campaign info contract + * @param platformHash The platform bytes. + */ + function createCampaign(bytes32 platformHash) internal { + bytes32 identifierHash = keccak256(abi.encodePacked(platformHash)); + bytes32[] memory selectedPlatformHash = new bytes32[](1); + selectedPlatformHash[0] = platformHash; + + // Calculate total size needed + uint256 totalSize = GROSS_PERCENTAGE_FEE_KEYS.length + 2; // +2 for flat fees + + // Create arrays for platform data keys and values + bytes32[] memory platformDataKey = new bytes32[](totalSize); + bytes32[] memory platformDataValue = new bytes32[](totalSize); + + // Add the individual fee key-value pairs + platformDataKey[0] = FLAT_FEE_KEY; + platformDataValue[0] = FLAT_FEE_VALUE; + + platformDataKey[1] = CUMULATIVE_FLAT_FEE_KEY; + platformDataValue[1] = CUMULATIVE_FLAT_FEE_VALUE; + + // Add gross percentage fees + uint256 currentIndex = 2; + for (uint256 i = 0; i < GROSS_PERCENTAGE_FEE_KEYS.length; i++) { + platformDataKey[currentIndex] = GROSS_PERCENTAGE_FEE_KEYS[i]; + platformDataValue[currentIndex] = GROSS_PERCENTAGE_FEE_VALUES[i]; + currentIndex++; + } + + vm.startPrank(users.creator1Address); + vm.recordLogs(); + + campaignInfoFactory.createCampaign( + users.creator1Address, + identifierHash, + selectedPlatformHash, + platformDataKey, + platformDataValue, + CAMPAIGN_DATA + ); + + Vm.Log[] memory entries = vm.getRecordedLogs(); + vm.stopPrank(); + + (bytes32[] memory topics,) = decodeTopicsAndData( + entries, "CampaignInfoFactoryCampaignCreated(bytes32,address)", address(campaignInfoFactory) + ); + + require(topics.length == 3, "Unexpected topic length for event"); + + campaignAddress = address(uint160(uint256(topics[2]))); + } + + /** + * @notice Implements deploy helper function. It deploys treasury contract. + */ + function deploy(bytes32 platformHash) internal { + vm.startPrank(users.platform2AdminAddress); + vm.recordLogs(); + + // Deploy the treasury contract + treasuryFactory.deploy(platformHash, campaignAddress, 1, NAME, SYMBOL); + + Vm.Log[] memory entries = vm.getRecordedLogs(); + vm.stopPrank(); + + // Decode the TreasuryDeployed event + (bytes32[] memory topics, bytes memory data) = decodeTopicsAndData( + entries, "TreasuryFactoryTreasuryDeployed(bytes32,uint256,address,address)", address(treasuryFactory) + ); + + require(topics.length >= 3, "Expected indexed params missing"); + + treasuryAddress = abi.decode(data, (address)); + + keepWhatsRaised = KeepWhatsRaised(treasuryAddress); + } + + /** + * @notice Implements configureTreasury helper function. + */ + function configureTreasury( + address caller, + address treasury, + KeepWhatsRaised.Config memory _config, + ICampaignData.CampaignData memory campaignData, + KeepWhatsRaised.FeeKeys memory _feeKeys + ) internal { + vm.startPrank(caller); + KeepWhatsRaised(treasury).configureTreasury(_config, campaignData, _feeKeys); + vm.stopPrank(); + } + + /** + * @notice Approves withdrawal for the treasury. + */ + function approveWithdrawal(address caller, address treasury) internal { + vm.startPrank(caller); + KeepWhatsRaised(treasury).approveWithdrawal(); + vm.stopPrank(); + } + + /** + * @notice Updates the deadline of the campaign. + */ + function updateDeadline(address caller, address treasury, uint256 newDeadline) internal { + vm.startPrank(caller); + KeepWhatsRaised(treasury).updateDeadline(newDeadline); + vm.stopPrank(); + } + + /** + * @notice Updates the goal amount of the campaign. + */ + function updateGoalAmount(address caller, address treasury, uint256 newGoalAmount) internal { + vm.startPrank(caller); + KeepWhatsRaised(treasury).updateGoalAmount(newGoalAmount); + vm.stopPrank(); + } + + /** + * @notice Adds rewards to the campaign. + */ + function addRewards(address caller, address treasury, bytes32[] memory rewardNames, Reward[] memory rewards) + internal + { + vm.startPrank(caller); + KeepWhatsRaised(treasury).addRewards(rewardNames, rewards); + vm.stopPrank(); + } + + /** + * @notice Removes a reward from the campaign. + */ + function removeReward(address caller, address treasury, bytes32 rewardName) internal { + vm.startPrank(caller); + KeepWhatsRaised(treasury).removeReward(rewardName); + vm.stopPrank(); + } + + /** + * @notice Sets payment gateway fee for a pledge. + */ + function setPaymentGatewayFee(address caller, address treasury, bytes32 pledgeId, uint256 fee) internal { + vm.startPrank(caller); + KeepWhatsRaised(treasury).setPaymentGatewayFee(pledgeId, fee); + vm.stopPrank(); + } + + /** + * @notice Implements setFeeAndPledge helper function. + */ + function setFeeAndPledge( + address caller, + address treasury, + bytes32 pledgeId, + address backer, + uint256 pledgeAmount, + uint256 tip, + uint256 fee, + bytes32[] memory reward, + bool isPledgeForAReward + ) internal returns (Vm.Log[] memory logs, uint256 tokenId, bytes32[] memory rewards) { + vm.startPrank(caller); + vm.recordLogs(); + + // Approve tokens from backer first + vm.stopPrank(); + vm.startPrank(backer); + + if (isPledgeForAReward) { + // Calculate total pledge amount from rewards + uint256 totalPledgeAmount = 0; + for (uint256 i = 0; i < reward.length; i++) { + totalPledgeAmount += KeepWhatsRaised(treasury).getReward(reward[i]).rewardValue; + } + testToken.approve(treasury, totalPledgeAmount + tip); + } else { + testToken.approve(treasury, pledgeAmount + tip); + } + + vm.stopPrank(); + vm.startPrank(caller); + + KeepWhatsRaised(treasury).setFeeAndPledge(pledgeId, backer, pledgeAmount, tip, fee, reward, isPledgeForAReward); + + logs = vm.getRecordedLogs(); + + bytes memory data = decodeEventFromLogs( + logs, "Receipt(address,bytes32,uint256,uint256,uint256,bytes32[])", treasury + ); + + (,, tokenId, rewards) = abi.decode(data, (uint256, uint256, uint256, bytes32[])); + + vm.stopPrank(); + } + + /** + * @notice Implements pledgeForAReward helper function with tip. + */ + function pledgeForAReward( + address caller, + address token, + address keepWhatsRaisedAddress, + bytes32 pledgeId, + uint256 pledgeAmount, + uint256 tip, + uint256 launchTime, + bytes32 rewardName + ) internal returns (Vm.Log[] memory logs, uint256 tokenId, bytes32[] memory rewards) { + vm.startPrank(caller); + vm.recordLogs(); + + testToken.approve(keepWhatsRaisedAddress, pledgeAmount + tip); + vm.warp(launchTime); + + bytes32[] memory reward = new bytes32[](1); + reward[0] = rewardName; + + KeepWhatsRaised(keepWhatsRaisedAddress).pledgeForAReward(pledgeId, caller, tip, reward); + + logs = vm.getRecordedLogs(); + + bytes memory data = decodeEventFromLogs( + logs, "Receipt(address,bytes32,uint256,uint256,uint256,bytes32[])", keepWhatsRaisedAddress + ); + + (,, tokenId, rewards) = abi.decode(data, (uint256, uint256, uint256, bytes32[])); + + vm.stopPrank(); + } + + /** + * @notice Implements pledgeWithoutAReward helper function with tip. + */ + function pledgeWithoutAReward( + address caller, + address token, + address keepWhatsRaisedAddress, + bytes32 pledgeId, + uint256 pledgeAmount, + uint256 tip, + uint256 launchTime + ) internal returns (Vm.Log[] memory logs, uint256 tokenId) { + vm.startPrank(caller); + vm.recordLogs(); + + testToken.approve(keepWhatsRaisedAddress, pledgeAmount + tip); + vm.warp(launchTime); + + KeepWhatsRaised(keepWhatsRaisedAddress).pledgeWithoutAReward(pledgeId, caller, pledgeAmount, tip); + + logs = vm.getRecordedLogs(); + + bytes memory data = decodeEventFromLogs( + logs, "Receipt(address,bytes32,uint256,uint256,uint256,bytes32[])", keepWhatsRaisedAddress + ); + + (,, tokenId,) = abi.decode(data, (uint256, uint256, uint256, bytes32[])); + vm.stopPrank(); + } + + /** + * @notice Implements withdraw helper function with amount parameter. + */ + function withdraw(address keepWhatsRaisedAddress, uint256 amount, uint256 warpTime) + internal + returns (Vm.Log[] memory logs, address to, uint256 withdrawalAmount, uint256 fee) + { + vm.warp(warpTime); + vm.recordLogs(); + + KeepWhatsRaised(keepWhatsRaisedAddress).withdraw(amount); + + logs = vm.getRecordedLogs(); + + (bytes32[] memory topics, bytes memory data) = + decodeTopicsAndData(logs, "WithdrawalWithFeeSuccessful(address,uint256,uint256)", keepWhatsRaisedAddress); + + to = address(uint160(uint256(topics[1]))); + + (withdrawalAmount, fee) = abi.decode(data, (uint256, uint256)); + } + + /** + * @notice Implements claimRefund helper function. + */ + function claimRefund(address caller, address keepWhatsRaisedAddress, uint256 tokenId) + internal + returns (Vm.Log[] memory logs, uint256 refundedTokenId, uint256 refundAmount, address claimer) + { + vm.startPrank(caller); + vm.recordLogs(); + + KeepWhatsRaised(keepWhatsRaisedAddress).claimRefund(tokenId); + + logs = vm.getRecordedLogs(); + + (bytes32[] memory topics, bytes memory data) = + decodeTopicsAndData(logs, "RefundClaimed(uint256,uint256,address)", keepWhatsRaisedAddress); + + refundedTokenId = uint256(topics[1]); + claimer = address(uint160(uint256(topics[2]))); + + refundAmount = abi.decode(data, (uint256)); + + vm.stopPrank(); + } + + /** + * @notice Implements claimTip helper function. + */ + function claimTip(address caller, address keepWhatsRaisedAddress, uint256 warpTime) + internal + returns (Vm.Log[] memory logs, uint256 amount, address claimer) + { + vm.warp(warpTime); + vm.startPrank(caller); + vm.recordLogs(); + + KeepWhatsRaised(keepWhatsRaisedAddress).claimTip(); + + logs = vm.getRecordedLogs(); + + (bytes32[] memory topics, bytes memory data) = + decodeTopicsAndData(logs, "TipClaimed(uint256,address)", keepWhatsRaisedAddress); + + claimer = address(uint160(uint256(topics[1]))); + amount = abi.decode(data, (uint256)); + + vm.stopPrank(); + } + + /** + * @notice Implements claimFund helper function. + */ + function claimFund(address caller, address keepWhatsRaisedAddress, uint256 warpTime) + internal + returns (Vm.Log[] memory logs, uint256 amount, address claimer) + { + vm.warp(warpTime); + vm.startPrank(caller); + vm.recordLogs(); + + KeepWhatsRaised(keepWhatsRaisedAddress).claimFund(); + + logs = vm.getRecordedLogs(); + + (bytes32[] memory topics, bytes memory data) = + decodeTopicsAndData(logs, "FundClaimed(uint256,address)", keepWhatsRaisedAddress); + + claimer = address(uint160(uint256(topics[1]))); + + amount = abi.decode(data, (uint256)); + + vm.stopPrank(); + } + + /** + * @notice Implements disburseFees helper function. + */ + function disburseFees(address keepWhatsRaisedAddress, uint256 warpTime) + internal + returns (Vm.Log[] memory logs, uint256 protocolShare, uint256 platformShare) + { + vm.warp(warpTime); + vm.recordLogs(); + + KeepWhatsRaised(keepWhatsRaisedAddress).disburseFees(); + + logs = vm.getRecordedLogs(); + + bytes memory data = decodeEventFromLogs(logs, "FeesDisbursed(uint256,uint256)", keepWhatsRaisedAddress); + + (protocolShare, platformShare) = abi.decode(data, (uint256, uint256)); + } + + /** + * @notice Helper to cancel treasury. + */ + function cancelTreasury(address caller, address treasury, bytes32 message) internal { + vm.startPrank(caller); + KeepWhatsRaised(treasury).cancelTreasury(message); + vm.stopPrank(); + } +} \ No newline at end of file diff --git a/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaisedFunction.t.sol b/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaisedFunction.t.sol new file mode 100644 index 00000000..a8b7e46d --- /dev/null +++ b/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaisedFunction.t.sol @@ -0,0 +1,580 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.20; + +import "./KeepWhatsRaised.t.sol"; +import "forge-std/Vm.sol"; +import "forge-std/Test.sol"; +import {Defaults} from "../../utils/Defaults.sol"; +import {Constants} from "../../utils/Constants.sol"; +import {Users} from "../../utils/Types.sol"; +import {IReward} from "src/interfaces/IReward.sol"; +import {KeepWhatsRaised} from "src/treasuries/KeepWhatsRaised.sol"; +import {CampaignInfo} from "src/CampaignInfo.sol"; + +contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Integration_Shared_Test { + function setUp() public virtual override { + super.setUp(); + + // Fund test users with tokens + deal(address(testToken), users.backer1Address, 1_000_000e18); + deal(address(testToken), users.backer2Address, 1_000_000e18); + deal(address(testToken), users.creator1Address, 1_000_000e18); + deal(address(testToken), users.platform2AdminAddress, 1_000_000e18); + } + + function test_addRewards() external { + addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); + + // First reward + Reward memory resultReward1 = keepWhatsRaised.getReward(REWARD_NAMES[0]); + assertEq(REWARDS[0].rewardValue, resultReward1.rewardValue); + assertEq(REWARDS[0].isRewardTier, resultReward1.isRewardTier); + assertEq(REWARDS[0].itemId[0], resultReward1.itemId[0]); + assertEq(REWARDS[0].itemValue[0], resultReward1.itemValue[0]); + assertEq(REWARDS[0].itemQuantity[0], resultReward1.itemQuantity[0]); + + // Second reward + Reward memory resultReward2 = keepWhatsRaised.getReward(REWARD_NAMES[1]); + assertEq(REWARDS[1].rewardValue, resultReward2.rewardValue); + assertEq(REWARDS[1].isRewardTier, resultReward2.isRewardTier); + assertEq(REWARDS[1].itemId.length, resultReward2.itemId.length); + assertEq(REWARDS[1].itemId[0], resultReward2.itemId[0]); + assertEq(REWARDS[1].itemId[1], resultReward2.itemId[1]); + assertEq(REWARDS[1].itemValue[0], resultReward2.itemValue[0]); + assertEq(REWARDS[1].itemValue[1], resultReward2.itemValue[1]); + assertEq(REWARDS[1].itemQuantity[0], resultReward2.itemQuantity[0]); + assertEq(REWARDS[1].itemQuantity[1], resultReward2.itemQuantity[1]); + + // Third reward + Reward memory resultReward3 = keepWhatsRaised.getReward(REWARD_NAMES[2]); + assertEq(REWARDS[2].rewardValue, resultReward3.rewardValue); + assertEq(REWARDS[2].isRewardTier, resultReward3.isRewardTier); + assertEq(REWARDS[2].itemId.length, resultReward3.itemId.length); + } + + function test_setPaymentGatewayFee() external { + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); + + uint256 fee = keepWhatsRaised.getPaymentGatewayFee(TEST_PLEDGE_ID_1); + assertEq(fee, PAYMENT_GATEWAY_FEE); + } + + function test_pledgeForARewardWithGatewayFee() external { + addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); + + // Set gateway fee first + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); + + (Vm.Log[] memory logs, uint256 tokenId, bytes32[] memory rewards) = pledgeForAReward( + users.backer1Address, + address(testToken), + address(keepWhatsRaised), + TEST_PLEDGE_ID_1, + PLEDGE_AMOUNT, + TIP_AMOUNT, + LAUNCH_TIME, + REWARD_NAME_1_HASH + ); + + uint256 backerBalance = testToken.balanceOf(users.backer1Address); + uint256 treasuryBalance = testToken.balanceOf(address(keepWhatsRaised)); + uint256 backerNftBalance = keepWhatsRaised.balanceOf(users.backer1Address); + address nftOwnerAddress = keepWhatsRaised.ownerOf(tokenId); + + assertEq(users.backer1Address, nftOwnerAddress); + assertEq(PLEDGE_AMOUNT + TIP_AMOUNT, treasuryBalance); + assertEq(1, backerNftBalance); + assertEq(keepWhatsRaised.getRaisedAmount(), PLEDGE_AMOUNT); + + assertTrue(keepWhatsRaised.getAvailableRaisedAmount() < PLEDGE_AMOUNT); + } + + function test_pledgeWithoutARewardWithGatewayFee() external { + addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); + + // Set gateway fee first + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); + + (, uint256 tokenId) = pledgeWithoutAReward( + users.backer1Address, address(testToken), address(keepWhatsRaised), TEST_PLEDGE_ID_1, PLEDGE_AMOUNT, TIP_AMOUNT, LAUNCH_TIME + ); + + uint256 treasuryBalance = testToken.balanceOf(address(keepWhatsRaised)); + uint256 backerNftBalance = keepWhatsRaised.balanceOf(users.backer1Address); + address nftOwnerAddress = keepWhatsRaised.ownerOf(tokenId); + + assertEq(users.backer1Address, nftOwnerAddress); + assertEq(PLEDGE_AMOUNT + TIP_AMOUNT, treasuryBalance); + assertEq(1, backerNftBalance); + assertEq(keepWhatsRaised.getRaisedAmount(), PLEDGE_AMOUNT); + + assertTrue(keepWhatsRaised.getAvailableRaisedAmount() < PLEDGE_AMOUNT); + } + + function test_setFeeAndPledgeForReward() external { + addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); + + vm.warp(LAUNCH_TIME); + + bytes32[] memory reward = new bytes32[](1); + reward[0] = REWARD_NAME_1_HASH; + + (Vm.Log[] memory logs, uint256 tokenId, bytes32[] memory rewards) = setFeeAndPledge( + users.platform2AdminAddress, + address(keepWhatsRaised), + TEST_PLEDGE_ID_1, + users.backer1Address, + 0, // pledgeAmount is ignored for reward pledges + TIP_AMOUNT, + PAYMENT_GATEWAY_FEE, + reward, + true + ); + + // Verify fee was set + assertEq(keepWhatsRaised.getPaymentGatewayFee(TEST_PLEDGE_ID_1), PAYMENT_GATEWAY_FEE); + + // Verify pledge was made + address nftOwnerAddress = keepWhatsRaised.ownerOf(tokenId); + assertEq(users.backer1Address, nftOwnerAddress); + } + + function test_setFeeAndPledgeWithoutReward() external { + vm.warp(LAUNCH_TIME); + + bytes32[] memory emptyReward = new bytes32[](0); + + (Vm.Log[] memory logs, uint256 tokenId, bytes32[] memory rewards) = setFeeAndPledge( + users.platform2AdminAddress, + address(keepWhatsRaised), + TEST_PLEDGE_ID_1, + users.backer1Address, + PLEDGE_AMOUNT, + TIP_AMOUNT, + PAYMENT_GATEWAY_FEE, + emptyReward, + false + ); + + // Verify fee was set + assertEq(keepWhatsRaised.getPaymentGatewayFee(TEST_PLEDGE_ID_1), PAYMENT_GATEWAY_FEE); + + // Verify pledge was made + address nftOwnerAddress = keepWhatsRaised.ownerOf(tokenId); + assertEq(users.backer1Address, nftOwnerAddress); + } + + function test_withdrawWithColombianCreatorTax() external { + // Configure with Colombian creator + configureTreasury(users.platform2AdminAddress, address(keepWhatsRaised), CONFIG_COLOMBIAN, CAMPAIGN_DATA, FEE_KEYS); + + addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); + + // Make pledges with gateway fees + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); + pledgeForAReward( + users.backer1Address, + address(testToken), + address(keepWhatsRaised), + TEST_PLEDGE_ID_1, + PLEDGE_AMOUNT, + TIP_AMOUNT, + LAUNCH_TIME, + REWARD_NAME_1_HASH + ); + + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_2, PAYMENT_GATEWAY_FEE); + pledgeWithoutAReward( + users.backer2Address, address(testToken), address(keepWhatsRaised), TEST_PLEDGE_ID_2, GOAL_AMOUNT, TIP_AMOUNT, LAUNCH_TIME + ); + + approveWithdrawal(users.platform2AdminAddress, address(keepWhatsRaised)); + + uint256 totalPledged = GOAL_AMOUNT + PLEDGE_AMOUNT; + address actualOwner = CampaignInfo(campaignAddress).owner(); + uint256 ownerBalanceBefore = testToken.balanceOf(actualOwner); + + (Vm.Log[] memory logs, address to, uint256 withdrawalAmount, uint256 fee) = + withdraw(address(keepWhatsRaised), 0, DEADLINE + 1 days); + + uint256 ownerBalanceAfter = testToken.balanceOf(actualOwner); + + assertEq(to, actualOwner, "Incorrect address receiving the funds"); + assertTrue(withdrawalAmount < totalPledged, "Withdrawal should be less than total pledged due to fees"); + assertEq(ownerBalanceAfter - ownerBalanceBefore, withdrawalAmount, "Incorrect balance change"); + assertEq(keepWhatsRaised.getAvailableRaisedAmount(), 0, "Available amount should be zero"); + } + + function test_refundWithPaymentFees() external { + addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); + + // Make pledge with gateway fee + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); + (, uint256 tokenId,) = pledgeForAReward( + users.backer1Address, + address(testToken), + address(keepWhatsRaised), + TEST_PLEDGE_ID_1, + PLEDGE_AMOUNT, + TIP_AMOUNT, + LAUNCH_TIME, + REWARD_NAME_1_HASH + ); + + uint256 backerBalanceBefore = testToken.balanceOf(users.backer1Address); + + vm.warp(DEADLINE + 1 days); + (Vm.Log[] memory refundLogs, uint256 refundedTokenId, uint256 refundAmount, address claimer) = + claimRefund(users.backer1Address, address(keepWhatsRaised), tokenId); + + uint256 backerBalanceAfter = testToken.balanceOf(users.backer1Address); + + assertEq(refundedTokenId, tokenId); + + uint256 platformFee = (PLEDGE_AMOUNT * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 vakiCommission = (PLEDGE_AMOUNT * uint256(VAKI_COMMISSION_VALUE)) / PERCENT_DIVIDER; + uint256 expectedRefund = PLEDGE_AMOUNT - PAYMENT_GATEWAY_FEE - platformFee - vakiCommission; + + assertEq(refundAmount, expectedRefund); + assertEq(claimer, users.backer1Address); + assertEq(backerBalanceAfter - backerBalanceBefore, refundAmount); + } + + function test_disburseFees() external { + addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); + + // Make pledges with gateway fees + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); + pledgeForAReward( + users.backer1Address, + address(testToken), + address(keepWhatsRaised), + TEST_PLEDGE_ID_1, + PLEDGE_AMOUNT, + TIP_AMOUNT, + LAUNCH_TIME, + REWARD_NAME_1_HASH + ); + + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_2, PAYMENT_GATEWAY_FEE); + pledgeWithoutAReward( + users.backer2Address, address(testToken), address(keepWhatsRaised), TEST_PLEDGE_ID_2, PLEDGE_AMOUNT, 0, LAUNCH_TIME + ); + + // Approve and withdraw + approveWithdrawal(users.platform2AdminAddress, address(keepWhatsRaised)); + withdraw(address(keepWhatsRaised), PLEDGE_AMOUNT, DEADLINE - 1 days); + + uint256 protocolAdminBalanceBefore = testToken.balanceOf(users.protocolAdminAddress); + uint256 platformAdminBalanceBefore = testToken.balanceOf(users.platform2AdminAddress); + + (Vm.Log[] memory logs, uint256 protocolShare, uint256 platformShare) = + disburseFees(address(keepWhatsRaised), block.timestamp); + + uint256 protocolAdminBalanceAfter = testToken.balanceOf(users.protocolAdminAddress); + uint256 platformAdminBalanceAfter = testToken.balanceOf(users.platform2AdminAddress); + + assertEq( + protocolAdminBalanceAfter - protocolAdminBalanceBefore, protocolShare, "Incorrect protocol fee disbursed" + ); + assertEq( + platformAdminBalanceAfter - platformAdminBalanceBefore, platformShare, "Incorrect platform fee disbursed" + ); + assertTrue(protocolShare > 0, "Protocol share should be greater than zero"); + assertTrue(platformShare > 0, "Platform share should be greater than zero"); + } + + function test_updateDeadlineByPlatformAdmin() external { + vm.warp(LAUNCH_TIME + 1 days); + + uint256 originalDeadline = keepWhatsRaised.getDeadline(); + uint256 newDeadline = originalDeadline + 14 days; + + updateDeadline(users.platform2AdminAddress, address(keepWhatsRaised), newDeadline); + + assertEq(keepWhatsRaised.getDeadline(), newDeadline); + } + + function test_updateDeadlineByCampaignOwner() external { + vm.warp(LAUNCH_TIME + 1 days); + + uint256 originalDeadline = keepWhatsRaised.getDeadline(); + uint256 newDeadline = originalDeadline + 14 days; + + address campaignOwner = CampaignInfo(campaignAddress).owner(); + updateDeadline(campaignOwner, address(keepWhatsRaised), newDeadline); + + assertEq(keepWhatsRaised.getDeadline(), newDeadline); + } + + function test_updateGoalAmountByPlatformAdmin() external { + vm.warp(LAUNCH_TIME + 1 days); + + uint256 originalGoal = keepWhatsRaised.getGoalAmount(); + uint256 newGoal = originalGoal * 3; + + updateGoalAmount(users.platform2AdminAddress, address(keepWhatsRaised), newGoal); + + assertEq(keepWhatsRaised.getGoalAmount(), newGoal); + } + + function test_updateGoalAmountByCampaignOwner() external { + vm.warp(LAUNCH_TIME + 1 days); + + uint256 originalGoal = keepWhatsRaised.getGoalAmount(); + uint256 newGoal = originalGoal * 3; + + address campaignOwner = CampaignInfo(campaignAddress).owner(); + updateGoalAmount(campaignOwner, address(keepWhatsRaised), newGoal); + + assertEq(keepWhatsRaised.getGoalAmount(), newGoal); + } + + function test_approveWithdrawal() external { + assertFalse(keepWhatsRaised.getWithdrawalApprovalStatus()); + + approveWithdrawal(users.platform2AdminAddress, address(keepWhatsRaised)); + + assertTrue(keepWhatsRaised.getWithdrawalApprovalStatus()); + } + + function test_withdraw() external { + addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); + + // Make pledges + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); + pledgeForAReward( + users.backer1Address, + address(testToken), + address(keepWhatsRaised), + TEST_PLEDGE_ID_1, + PLEDGE_AMOUNT, + TIP_AMOUNT, + LAUNCH_TIME, + REWARD_NAME_1_HASH + ); + + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_2, PAYMENT_GATEWAY_FEE); + pledgeWithoutAReward( + users.backer2Address, address(testToken), address(keepWhatsRaised), TEST_PLEDGE_ID_2, GOAL_AMOUNT, TIP_AMOUNT, LAUNCH_TIME + ); + + approveWithdrawal(users.platform2AdminAddress, address(keepWhatsRaised)); + + uint256 totalPledged = GOAL_AMOUNT + PLEDGE_AMOUNT; + address actualOwner = CampaignInfo(campaignAddress).owner(); + uint256 ownerBalanceBefore = testToken.balanceOf(actualOwner); + + (Vm.Log[] memory logs, address to, uint256 withdrawalAmount, uint256 fee) = + withdraw(address(keepWhatsRaised), 0, DEADLINE + 1 days); + + uint256 ownerBalanceAfter = testToken.balanceOf(actualOwner); + + assertEq(to, actualOwner, "Incorrect address receiving the funds"); + assertTrue(withdrawalAmount < totalPledged, "Should have fees deducted"); + assertEq(ownerBalanceAfter - ownerBalanceBefore, withdrawalAmount, "Incorrect balance change"); + assertEq(keepWhatsRaised.getAvailableRaisedAmount(), 0, "Available amount should be zero"); + } + + function test_withdrawPartial() external { + addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); + + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); + pledgeWithoutAReward( + users.backer1Address, address(testToken), address(keepWhatsRaised), TEST_PLEDGE_ID_1, PLEDGE_AMOUNT, 0, LAUNCH_TIME + ); + + // Approve withdrawal + approveWithdrawal(users.platform2AdminAddress, address(keepWhatsRaised)); + + uint256 partialAmount = 500e18; // Withdraw less than full amount + uint256 availableBefore = keepWhatsRaised.getAvailableRaisedAmount(); + + (Vm.Log[] memory logs, address to, uint256 withdrawalAmount, uint256 fee) = + withdraw(address(keepWhatsRaised), partialAmount, DEADLINE - 1 days); + + uint256 availableAfter = keepWhatsRaised.getAvailableRaisedAmount(); + + assertEq(withdrawalAmount + fee, partialAmount, "Incorrect partial withdrawal"); + assertTrue(availableAfter < availableBefore, "Available amount should be reduced"); + } + + function test_claimTip() external { + addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); + + // Make pledges with tips + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); + pledgeForAReward( + users.backer1Address, + address(testToken), + address(keepWhatsRaised), + TEST_PLEDGE_ID_1, + PLEDGE_AMOUNT, + TIP_AMOUNT, + LAUNCH_TIME, + REWARD_NAME_1_HASH + ); + + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_2, PAYMENT_GATEWAY_FEE); + pledgeWithoutAReward( + users.backer2Address, address(testToken), address(keepWhatsRaised), TEST_PLEDGE_ID_2, GOAL_AMOUNT, TIP_AMOUNT * 2, LAUNCH_TIME + ); + + uint256 totalTips = TIP_AMOUNT + (TIP_AMOUNT * 2); + uint256 platformAdminBalanceBefore = testToken.balanceOf(users.platform2AdminAddress); + + // Claim tips after deadline + (Vm.Log[] memory logs, uint256 amount, address claimer) = + claimTip(users.platform2AdminAddress, address(keepWhatsRaised), DEADLINE + 1 days); + + uint256 platformAdminBalanceAfter = testToken.balanceOf(users.platform2AdminAddress); + + assertEq(amount, totalTips, "Incorrect tip amount"); + assertEq(claimer, users.platform2AdminAddress, "Incorrect claimer"); + assertEq(platformAdminBalanceAfter - platformAdminBalanceBefore, totalTips); + } + + function test_claimFund() external { + addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); + + // Make a pledge + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); + pledgeForAReward( + users.backer1Address, + address(testToken), + address(keepWhatsRaised), + TEST_PLEDGE_ID_1, + PLEDGE_AMOUNT, + TIP_AMOUNT, + LAUNCH_TIME, + REWARD_NAME_1_HASH + ); + + uint256 platformAdminBalanceBefore = testToken.balanceOf(users.platform2AdminAddress); + uint256 expectedAmount = keepWhatsRaised.getAvailableRaisedAmount(); + + // Claim fund after withdrawal delay has passed + (Vm.Log[] memory logs, uint256 amount, address claimer) = + claimFund(users.platform2AdminAddress, address(keepWhatsRaised), DEADLINE + WITHDRAWAL_DELAY + 1 days); + + uint256 platformAdminBalanceAfter = testToken.balanceOf(users.platform2AdminAddress); + + assertEq(amount, expectedAmount, "Incorrect fund amount"); + assertEq(claimer, users.platform2AdminAddress, "Incorrect claimer"); + assertEq(platformAdminBalanceAfter - platformAdminBalanceBefore, expectedAmount); + assertEq(keepWhatsRaised.getAvailableRaisedAmount(), 0); + } + + function test_removeReward() external { + addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); + + // Verify reward exists before removal + Reward memory rewardBefore = keepWhatsRaised.getReward(REWARD_NAMES[1]); + assertEq(rewardBefore.rewardValue, REWARDS[1].rewardValue); + + // Remove the reward + removeReward(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES[1]); + + // Verify reward is removed + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedInvalidInput.selector); + keepWhatsRaised.getReward(REWARD_NAMES[1]); + } + + function test_cancelTreasuryByPlatformAdmin() external { + addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); + + // Make a pledge + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); + pledgeForAReward( + users.backer1Address, + address(testToken), + address(keepWhatsRaised), + TEST_PLEDGE_ID_1, + PLEDGE_AMOUNT, + TIP_AMOUNT, + LAUNCH_TIME, + REWARD_NAME_1_HASH + ); + + bytes32 cancellationMessage = keccak256(abi.encodePacked("Platform cancellation")); + + // Cancel by platform admin + cancelTreasury(users.platform2AdminAddress, address(keepWhatsRaised), cancellationMessage); + + // Verify campaign is cancelled + vm.startPrank(users.backer2Address); + testToken.approve(address(keepWhatsRaised), PLEDGE_AMOUNT); + vm.expectRevert(); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID_2, users.backer2Address, PLEDGE_AMOUNT, 0); + vm.stopPrank(); + } + + function test_cancelTreasuryByCampaignOwner() external { + addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); + + // Make a pledge + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); + pledgeForAReward( + users.backer1Address, + address(testToken), + address(keepWhatsRaised), + TEST_PLEDGE_ID_1, + PLEDGE_AMOUNT, + TIP_AMOUNT, + LAUNCH_TIME, + REWARD_NAME_1_HASH + ); + + bytes32 cancellationMessage = keccak256(abi.encodePacked("Owner cancellation")); + address campaignOwner = CampaignInfo(campaignAddress).owner(); + + // Cancel by campaign owner + cancelTreasury(campaignOwner, address(keepWhatsRaised), cancellationMessage); + + // Verify campaign is cancelled + vm.startPrank(users.backer2Address); + testToken.approve(address(keepWhatsRaised), PLEDGE_AMOUNT); + vm.expectRevert(); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID_2, users.backer2Address, PLEDGE_AMOUNT, 0); + vm.stopPrank(); + } + + function test_refundAfterCancellation() external { + addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); + + // Make pledge with gateway fee + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); + (, uint256 tokenId,) = pledgeForAReward( + users.backer1Address, + address(testToken), + address(keepWhatsRaised), + TEST_PLEDGE_ID_1, + PLEDGE_AMOUNT, + TIP_AMOUNT, + LAUNCH_TIME, + REWARD_NAME_1_HASH + ); + + // Cancel campaign + cancelTreasury(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("cancelled")); + + uint256 backerBalanceBefore = testToken.balanceOf(users.backer1Address); + + // Try to claim refund immediately after cancellation + vm.warp(block.timestamp + 1); + (Vm.Log[] memory refundLogs, uint256 refundedTokenId, uint256 refundAmount, address claimer) = + claimRefund(users.backer1Address, address(keepWhatsRaised), tokenId); + + uint256 backerBalanceAfter = testToken.balanceOf(users.backer1Address); + + assertEq(refundedTokenId, tokenId); + + uint256 platformFee = (PLEDGE_AMOUNT * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 vakiCommission = (PLEDGE_AMOUNT * uint256(VAKI_COMMISSION_VALUE)) / PERCENT_DIVIDER; + uint256 expectedRefund = PLEDGE_AMOUNT - PAYMENT_GATEWAY_FEE - platformFee - vakiCommission; + + assertEq(refundAmount, expectedRefund, "Refund amount should be pledge minus fees"); + assertEq(claimer, users.backer1Address); + assertEq(backerBalanceAfter - backerBalanceBefore, refundAmount); + } +} \ No newline at end of file diff --git a/test/foundry/unit/KeepWhatsRaised.t.sol b/test/foundry/unit/KeepWhatsRaised.t.sol new file mode 100644 index 00000000..e6b27037 --- /dev/null +++ b/test/foundry/unit/KeepWhatsRaised.t.sol @@ -0,0 +1,1326 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.20; + +import "../integration/KeepWhatsRaised/KeepWhatsRaised.t.sol"; +import "forge-std/Test.sol"; +import {KeepWhatsRaised} from "src/treasuries/KeepWhatsRaised.sol"; +import {GlobalParams} from "src/GlobalParams.sol"; +import {CampaignInfo} from "src/CampaignInfo.sol"; +import {CampaignInfoFactory} from "src/CampaignInfoFactory.sol"; +import {TreasuryFactory} from "src/TreasuryFactory.sol"; +import {TestToken} from "../../mocks/TestToken.sol"; +import {Defaults} from "../Base.t.sol"; +import {IReward} from "src/interfaces/IReward.sol"; +import {ICampaignData} from "src/interfaces/ICampaignData.sol"; + +contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Test { + + // Test constants + uint256 internal constant TEST_PLEDGE_AMOUNT = 1000e18; + uint256 internal constant TEST_TIP_AMOUNT = 50e18; + bytes32 internal constant TEST_REWARD_NAME = keccak256("testReward"); + bytes32 internal constant TEST_PLEDGE_ID = keccak256("testPledgeId"); + + function setUp() public virtual override { + super.setUp(); + deal(address(testToken), users.backer1Address, 100_000e18); + deal(address(testToken), users.backer2Address, 100_000e18); + + // Label addresses + vm.label(users.protocolAdminAddress, "ProtocolAdmin"); + vm.label(users.platform2AdminAddress, "PlatformAdmin"); + vm.label(users.contractOwner, "CampaignOwner"); + vm.label(users.backer1Address, "Backer1"); + vm.label(users.backer2Address, "Backer2"); + vm.label(address(keepWhatsRaised), "KeepWhatsRaised"); + vm.label(address(globalParams), "GlobalParams"); + } + + /*////////////////////////////////////////////////////////////// + INITIALIZATION + //////////////////////////////////////////////////////////////*/ + + function testInitialize() public { + bytes32 newIdentifierHash = keccak256(abi.encodePacked("newCampaign")); + bytes32[] memory selectedPlatformHash = new bytes32[](1); + selectedPlatformHash[0] = PLATFORM_2_HASH; + + // Create arrays for platform data keys and values + uint256 totalSize = 2 + GROSS_PERCENTAGE_FEE_KEYS.length; + bytes32[] memory platformDataKey = new bytes32[](totalSize); + bytes32[] memory platformDataValue = new bytes32[](totalSize); + + // Add the individual fee key-value pairs + platformDataKey[0] = FLAT_FEE_KEY; + platformDataValue[0] = FLAT_FEE_VALUE; + platformDataKey[1] = CUMULATIVE_FLAT_FEE_KEY; + platformDataValue[1] = CUMULATIVE_FLAT_FEE_VALUE; + + // Add gross percentage fees + uint256 currentIndex = 2; + for (uint256 i = 0; i < GROSS_PERCENTAGE_FEE_KEYS.length; i++) { + platformDataKey[currentIndex] = GROSS_PERCENTAGE_FEE_KEYS[i]; + platformDataValue[currentIndex] = GROSS_PERCENTAGE_FEE_VALUES[i]; + currentIndex++; + } + + vm.prank(users.creator1Address); + campaignInfoFactory.createCampaign( + users.creator1Address, + newIdentifierHash, + selectedPlatformHash, + platformDataKey, + platformDataValue, + CAMPAIGN_DATA + ); + + address newCampaignAddress = campaignInfoFactory.identifierToCampaignInfo(newIdentifierHash); + + // Deploy + vm.prank(users.platform2AdminAddress); + address newTreasury = treasuryFactory.deploy( + PLATFORM_2_HASH, + newCampaignAddress, + 1, + "NewCampaign", + "NC" + ); + + KeepWhatsRaised newContract = KeepWhatsRaised(newTreasury); + + assertEq(newContract.name(), "NewCampaign"); + assertEq(newContract.symbol(), "NC"); + } + + /*////////////////////////////////////////////////////////////// + TREASURY CONFIGURATION + //////////////////////////////////////////////////////////////*/ + + function testConfigureTreasury() public { + ICampaignData.CampaignData memory newCampaignData = ICampaignData.CampaignData({ + launchTime: block.timestamp + 1 days, + deadline: block.timestamp + 31 days, + goalAmount: 5000 + }); + + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.configureTreasury(CONFIG, newCampaignData, FEE_KEYS); + + assertEq(keepWhatsRaised.getLaunchTime(), newCampaignData.launchTime); + assertEq(keepWhatsRaised.getDeadline(), newCampaignData.deadline); + assertEq(keepWhatsRaised.getGoalAmount(), newCampaignData.goalAmount); + } + + function testConfigureTreasuryWithColombianCreator() public { + ICampaignData.CampaignData memory newCampaignData = ICampaignData.CampaignData({ + launchTime: block.timestamp + 1 days, + deadline: block.timestamp + 31 days, + goalAmount: 5000 + }); + + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.configureTreasury(CONFIG_COLOMBIAN, newCampaignData, FEE_KEYS); + + // Test that Colombian creator tax is not applied in pledges + _setupReward(); + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, 0); + + vm.warp(keepWhatsRaised.getLaunchTime()); + vm.startPrank(users.backer1Address); + testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); + + bytes32[] memory rewardSelection = new bytes32[](1); + rewardSelection[0] = TEST_REWARD_NAME; + + keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, 0, rewardSelection); + vm.stopPrank(); + + // Available amount should not include Colombian tax deduction at pledge time + uint256 availableAmount = keepWhatsRaised.getAvailableRaisedAmount(); + uint256 expectedWithoutColombianTax = TEST_PLEDGE_AMOUNT - (TEST_PLEDGE_AMOUNT * PLATFORM_FEE_PERCENT / PERCENT_DIVIDER) - (TEST_PLEDGE_AMOUNT * 6 * 100 / PERCENT_DIVIDER); + assertEq(availableAmount, expectedWithoutColombianTax, "Colombian tax should not be applied at pledge time"); + } + + function testConfigureTreasuryRevertWhenNotPlatformAdmin() public { + vm.expectRevert(); + vm.prank(users.backer1Address); + keepWhatsRaised.configureTreasury(CONFIG, CAMPAIGN_DATA, FEE_KEYS); + } + + /*////////////////////////////////////////////////////////////// + PAYMENT GATEWAY FEES + //////////////////////////////////////////////////////////////*/ + + function testSetPaymentGatewayFee() public { + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.setPaymentGatewayFee(TEST_PLEDGE_ID, PAYMENT_GATEWAY_FEE); + + assertEq(keepWhatsRaised.getPaymentGatewayFee(TEST_PLEDGE_ID), PAYMENT_GATEWAY_FEE); + } + + function testSetPaymentGatewayFeeRevertWhenNotPlatformAdmin() public { + vm.expectRevert(); + vm.prank(users.backer1Address); + keepWhatsRaised.setPaymentGatewayFee(TEST_PLEDGE_ID, PAYMENT_GATEWAY_FEE); + } + + function testSetPaymentGatewayFeeRevertWhenPaused() public { + _pauseTreasury(); + + vm.expectRevert(); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.setPaymentGatewayFee(TEST_PLEDGE_ID, PAYMENT_GATEWAY_FEE); + } + + /*////////////////////////////////////////////////////////////// + WITHDRAWAL APPROVAL + //////////////////////////////////////////////////////////////*/ + + function testApproveWithdrawal() public { + assertFalse(keepWhatsRaised.getWithdrawalApprovalStatus()); + + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.approveWithdrawal(); + + assertTrue(keepWhatsRaised.getWithdrawalApprovalStatus()); + } + + function testApproveWithdrawalRevertWhenAlreadyApproved() public { + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.approveWithdrawal(); + + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedAlreadyEnabled.selector); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.approveWithdrawal(); + } + + function testApproveWithdrawalRevertWhenNotPlatformAdmin() public { + vm.expectRevert(); + vm.prank(users.backer1Address); + keepWhatsRaised.approveWithdrawal(); + } + + /*////////////////////////////////////////////////////////////// + DEADLINE AND GOAL UPDATES + //////////////////////////////////////////////////////////////*/ + + function testUpdateDeadlineByPlatformAdmin() public { + uint256 newDeadline = DEADLINE + 10 days; + + vm.warp(LAUNCH_TIME + 1 days); // Within config lock period + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.updateDeadline(newDeadline); + + assertEq(keepWhatsRaised.getDeadline(), newDeadline); + } + + function testUpdateDeadlineByCampaignOwner() public { + uint256 newDeadline = DEADLINE + 10 days; + address campaignOwner = CampaignInfo(campaignAddress).owner(); + + vm.warp(LAUNCH_TIME + 1 days); + vm.prank(campaignOwner); + keepWhatsRaised.updateDeadline(newDeadline); + + assertEq(keepWhatsRaised.getDeadline(), newDeadline); + } + + function testUpdateDeadlineRevertWhenNotAuthorized() public { + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedUnAuthorized.selector); + vm.prank(users.backer1Address); + keepWhatsRaised.updateDeadline(DEADLINE + 10 days); + } + + function testUpdateDeadlineRevertWhenPastConfigLock() public { + // Warp to past config lock period + vm.warp(DEADLINE - CONFIG_LOCK_PERIOD + 1); + + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedConfigLocked.selector); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.updateDeadline(DEADLINE + 10 days); + } + + function testUpdateDeadlineRevertWhenDeadlineBeforeLaunchTime() public { + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedInvalidInput.selector); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.updateDeadline(LAUNCH_TIME - 1); + } + + function testUpdateDeadlineRevertWhenPaused() public { + _pauseTreasury(); + + // Try to update deadline + vm.warp(LAUNCH_TIME + 1 days); + vm.expectRevert(); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.updateDeadline(DEADLINE + 10 days); + } + + function testUpdateGoalAmountByPlatformAdmin() public { + uint256 newGoal = GOAL_AMOUNT * 2; + + vm.warp(LAUNCH_TIME + 1 days); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.updateGoalAmount(newGoal); + + assertEq(keepWhatsRaised.getGoalAmount(), newGoal); + } + + function testUpdateGoalAmountByCampaignOwner() public { + uint256 newGoal = GOAL_AMOUNT * 2; + address campaignOwner = CampaignInfo(campaignAddress).owner(); + + vm.warp(LAUNCH_TIME + 1 days); + vm.prank(campaignOwner); + keepWhatsRaised.updateGoalAmount(newGoal); + + assertEq(keepWhatsRaised.getGoalAmount(), newGoal); + } + + function testUpdateGoalAmountRevertWhenNotAuthorized() public { + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedUnAuthorized.selector); + vm.prank(users.backer1Address); + keepWhatsRaised.updateGoalAmount(GOAL_AMOUNT * 2); + } + + function testUpdateGoalAmountRevertWhenZero() public { + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedInvalidInput.selector); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.updateGoalAmount(0); + } + + /*////////////////////////////////////////////////////////////// + REWARDS MANAGEMENT + //////////////////////////////////////////////////////////////*/ + + function testAddRewards() public { + bytes32[] memory rewardNames = new bytes32[](1); + rewardNames[0] = TEST_REWARD_NAME; + + Reward[] memory rewards = new Reward[](1); + rewards[0] = _createTestReward(TEST_PLEDGE_AMOUNT, true); + + vm.prank(users.creator1Address); + keepWhatsRaised.addRewards(rewardNames, rewards); + + Reward memory retrievedReward = keepWhatsRaised.getReward(TEST_REWARD_NAME); + assertEq(retrievedReward.rewardValue, TEST_PLEDGE_AMOUNT); + assertTrue(retrievedReward.isRewardTier); + } + + function testAddRewardsRevertWhenMismatchedArrays() public { + bytes32[] memory rewardNames = new bytes32[](2); + Reward[] memory rewards = new Reward[](1); + + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedInvalidInput.selector); + vm.prank(users.creator1Address); + keepWhatsRaised.addRewards(rewardNames, rewards); + } + + function testAddRewardsRevertWhenDuplicateReward() public { + bytes32[] memory rewardNames = new bytes32[](1); + rewardNames[0] = TEST_REWARD_NAME; + + Reward[] memory rewards = new Reward[](1); + rewards[0] = _createTestReward(TEST_PLEDGE_AMOUNT, true); + + // Add first time + vm.prank(users.creator1Address); + keepWhatsRaised.addRewards(rewardNames, rewards); + + // Try to add again + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedRewardExists.selector); + vm.prank(users.creator1Address); + keepWhatsRaised.addRewards(rewardNames, rewards); + } + + function testRemoveReward() public { + // First add a reward + bytes32[] memory rewardNames = new bytes32[](1); + rewardNames[0] = TEST_REWARD_NAME; + + Reward[] memory rewards = new Reward[](1); + rewards[0] = _createTestReward(TEST_PLEDGE_AMOUNT, true); + + vm.prank(users.creator1Address); + keepWhatsRaised.addRewards(rewardNames, rewards); + + // Remove reward + vm.prank(users.creator1Address); + keepWhatsRaised.removeReward(TEST_REWARD_NAME); + + // Verify removal + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedInvalidInput.selector); + keepWhatsRaised.getReward(TEST_REWARD_NAME); + } + + function testRemoveRewardRevertWhenRewardDoesNotExist() public { + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedInvalidInput.selector); + vm.prank(users.creator1Address); + keepWhatsRaised.removeReward(TEST_REWARD_NAME); + } + + function testAddRewardsRevertWhenPaused() public { + _pauseTreasury(); + + // Try to add rewards + bytes32[] memory rewardNames = new bytes32[](1); + rewardNames[0] = TEST_REWARD_NAME; + + Reward[] memory rewards = new Reward[](1); + rewards[0] = _createTestReward(TEST_PLEDGE_AMOUNT, true); + + vm.expectRevert(); + vm.prank(users.creator1Address); + keepWhatsRaised.addRewards(rewardNames, rewards); + } + + function testRemoveRewardRevertWhenPaused() public { + // First add a reward + bytes32[] memory rewardNames = new bytes32[](1); + rewardNames[0] = TEST_REWARD_NAME; + + Reward[] memory rewards = new Reward[](1); + rewards[0] = _createTestReward(TEST_PLEDGE_AMOUNT, true); + + vm.prank(users.creator1Address); + keepWhatsRaised.addRewards(rewardNames, rewards); + + _pauseTreasury(); + + // Try to remove reward - should revert + vm.expectRevert(); + vm.prank(users.creator1Address); + keepWhatsRaised.removeReward(TEST_REWARD_NAME); + } + + /*////////////////////////////////////////////////////////////// + PLEDGING + //////////////////////////////////////////////////////////////*/ + + function testPledgeForAReward() public { + // Add reward first + _setupReward(); + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, PAYMENT_GATEWAY_FEE); + + uint256 balanceBefore = testToken.balanceOf(users.backer1Address); + + // Pledge + vm.warp(LAUNCH_TIME); + vm.startPrank(users.backer1Address); + testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT + TEST_TIP_AMOUNT); + + bytes32[] memory rewardSelection = new bytes32[](1); + rewardSelection[0] = TEST_REWARD_NAME; + + keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_TIP_AMOUNT, rewardSelection); + vm.stopPrank(); + + // Verify + assertEq(testToken.balanceOf(users.backer1Address), balanceBefore - TEST_PLEDGE_AMOUNT - TEST_TIP_AMOUNT); + assertEq(keepWhatsRaised.getRaisedAmount(), TEST_PLEDGE_AMOUNT); + assertTrue(keepWhatsRaised.getAvailableRaisedAmount() < TEST_PLEDGE_AMOUNT); // Less due to fees (no Colombian tax yet) + assertEq(keepWhatsRaised.balanceOf(users.backer1Address), 1); + } + + function testPledgeForARewardRevertWhenDuplicatePledgeId() public { + _setupReward(); + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, PAYMENT_GATEWAY_FEE); + + vm.warp(LAUNCH_TIME); + vm.startPrank(users.backer1Address); + testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT * 2); + + bytes32[] memory rewardSelection = new bytes32[](1); + rewardSelection[0] = TEST_REWARD_NAME; + + // First pledge + keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, 0, rewardSelection); + + // Try to pledge with same ID + vm.expectRevert(abi.encodeWithSelector(KeepWhatsRaised.KeepWhatsRaisedPledgeAlreadyProcessed.selector, TEST_PLEDGE_ID)); + keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, 0, rewardSelection); + vm.stopPrank(); + } + + function testPledgeForARewardRevertWhenNotRewardTier() public { + // Add non-reward tier + bytes32[] memory rewardNames = new bytes32[](1); + rewardNames[0] = TEST_REWARD_NAME; + + Reward[] memory rewards = new Reward[](1); + rewards[0] = _createTestReward(TEST_PLEDGE_AMOUNT, false); + + vm.prank(users.creator1Address); + keepWhatsRaised.addRewards(rewardNames, rewards); + + // Try to pledge + vm.warp(LAUNCH_TIME); + vm.startPrank(users.backer1Address); + testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); + + bytes32[] memory rewardSelection = new bytes32[](1); + rewardSelection[0] = TEST_REWARD_NAME; + + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedInvalidInput.selector); + keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, 0, rewardSelection); + vm.stopPrank(); + } + + function testPledgeWithoutAReward() public { + uint256 pledgeAmount = 500e18; + uint256 balanceBefore = testToken.balanceOf(users.backer1Address); + + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, PAYMENT_GATEWAY_FEE); + + // Pledge + vm.warp(LAUNCH_TIME); + vm.startPrank(users.backer1Address); + testToken.approve(address(keepWhatsRaised), pledgeAmount + TEST_TIP_AMOUNT); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, pledgeAmount, TEST_TIP_AMOUNT); + vm.stopPrank(); + + // Verify + assertEq(testToken.balanceOf(users.backer1Address), balanceBefore - pledgeAmount - TEST_TIP_AMOUNT); + assertEq(keepWhatsRaised.getRaisedAmount(), pledgeAmount); + assertTrue(keepWhatsRaised.getAvailableRaisedAmount() < pledgeAmount); // Less due to fees + assertEq(keepWhatsRaised.balanceOf(users.backer1Address), 1); + } + + function testPledgeWithoutARewardRevertWhenDuplicatePledgeId() public { + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, 0); + + vm.warp(LAUNCH_TIME); + vm.startPrank(users.backer1Address); + testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT * 2); + + // First pledge + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + + // Try to pledge with same ID + vm.expectRevert(abi.encodeWithSelector(KeepWhatsRaised.KeepWhatsRaisedPledgeAlreadyProcessed.selector, TEST_PLEDGE_ID)); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + vm.stopPrank(); + } + + function testPledgeRevertWhenOutsideCampaignPeriod() public { + // Before launch + vm.warp(LAUNCH_TIME - 1); + vm.expectRevert(); + vm.prank(users.backer1Address); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + + // After deadline + vm.warp(DEADLINE + 1); + vm.expectRevert(); + vm.prank(users.backer1Address); + keepWhatsRaised.pledgeWithoutAReward(keccak256("newPledge"), users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + } + + function testPledgeForARewardRevertWhenPaused() public { + // Add reward first + _setupReward(); + + _pauseTreasury(); + + // Try to pledge + vm.warp(LAUNCH_TIME); + vm.startPrank(users.backer1Address); + testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT + TEST_TIP_AMOUNT); + + bytes32[] memory rewardSelection = new bytes32[](1); + rewardSelection[0] = TEST_REWARD_NAME; + + vm.expectRevert(); + keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_TIP_AMOUNT, rewardSelection); + vm.stopPrank(); + } + + function testSetFeeAndPledge() public { + _setupReward(); + + vm.warp(LAUNCH_TIME); + + bytes32[] memory rewardSelection = new bytes32[](1); + rewardSelection[0] = TEST_REWARD_NAME; + + vm.startPrank(users.backer1Address); + testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT + TEST_TIP_AMOUNT); + vm.stopPrank(); + + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.setFeeAndPledge( + TEST_PLEDGE_ID, + users.backer1Address, + 0, // ignored for reward pledges + TEST_TIP_AMOUNT, + PAYMENT_GATEWAY_FEE, + rewardSelection, + true + ); + + // Verify fee was set + assertEq(keepWhatsRaised.getPaymentGatewayFee(TEST_PLEDGE_ID), PAYMENT_GATEWAY_FEE); + + // Verify pledge was made + assertEq(keepWhatsRaised.getRaisedAmount(), TEST_PLEDGE_AMOUNT); + assertEq(keepWhatsRaised.balanceOf(users.backer1Address), 1); + } + + /*////////////////////////////////////////////////////////////// + WITHDRAWALS + //////////////////////////////////////////////////////////////*/ + + function testWithdrawFullAmountAfterDeadline() public { + // Setup pledges + _setupPledges(); + + // Approve withdrawal + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.approveWithdrawal(); + + address owner = CampaignInfo(campaignAddress).owner(); + uint256 ownerBalanceBefore = testToken.balanceOf(owner); + + // Withdraw after deadline + vm.warp(DEADLINE + 1); + keepWhatsRaised.withdraw(0); + + uint256 ownerBalanceAfter = testToken.balanceOf(owner); + + // Verify (accounting for fees) + assertTrue(ownerBalanceAfter > ownerBalanceBefore); + assertEq(keepWhatsRaised.getAvailableRaisedAmount(), 0); + } + + function testWithdrawPartialAmountBeforeDeadline() public { + // Setup pledges + _setupPledges(); + + // Approve withdrawal + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.approveWithdrawal(); + + uint256 partialAmount = 500e18; + uint256 availableBefore = keepWhatsRaised.getAvailableRaisedAmount(); + + // Withdraw partial amount before deadline + vm.warp(LAUNCH_TIME + 1 days); + keepWhatsRaised.withdraw(partialAmount); + + uint256 availableAfter = keepWhatsRaised.getAvailableRaisedAmount(); + + // Verify + assertTrue(availableAfter < availableBefore); + } + + function testWithdrawRevertWhenNotApproved() public { + _setupPledges(); + + vm.warp(DEADLINE + 1); + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedDisabled.selector); + keepWhatsRaised.withdraw(0); + } + + function testWithdrawRevertWhenAmountExceedsAvailable() public { + _setupPledges(); + + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.approveWithdrawal(); + + uint256 available = keepWhatsRaised.getAvailableRaisedAmount(); + + vm.warp(LAUNCH_TIME + 1 days); + vm.expectRevert(); + keepWhatsRaised.withdraw(available + 1e18); + } + + function testWithdrawRevertWhenAlreadyWithdrawn() public { + _setupPledges(); + + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.approveWithdrawal(); + + // First withdrawal + vm.warp(DEADLINE + 1); + keepWhatsRaised.withdraw(0); + + // Second withdrawal attempt + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedAlreadyWithdrawn.selector); + keepWhatsRaised.withdraw(0); + } + + function testWithdrawRevertWhenPaused() public { + // Setup pledges and approve withdrawal first + _setupPledges(); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.approveWithdrawal(); + + _pauseTreasury(); + + // Try to withdraw + vm.warp(DEADLINE + 1); + vm.expectRevert(); + keepWhatsRaised.withdraw(0); + } + + function testWithdrawWithMinimumFeeExemption() public { + // Calculate pledge amount needed to have available amount above exemption after fees + // We need: pledgeAmount * (1 - totalFeePercentage) > MINIMUM_WITHDRAWAL_FOR_FEE_EXEMPTION + // totalFeePercentage = platformFee (10%) + vakiCommission (6%) = 16% + // So: pledgeAmount > MINIMUM_WITHDRAWAL_FOR_FEE_EXEMPTION / 0.84 + uint256 largePledge = (MINIMUM_WITHDRAWAL_FOR_FEE_EXEMPTION * 100) / 84 + 1000e18; // ~60,000e18 + + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, 0); + + vm.warp(LAUNCH_TIME); + vm.startPrank(users.backer1Address); + testToken.approve(address(keepWhatsRaised), largePledge); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, largePledge, 0); + vm.stopPrank(); + + uint256 availableAfterPledge = keepWhatsRaised.getAvailableRaisedAmount(); + + // Verify available amount is above exemption threshold + assertTrue(availableAfterPledge > MINIMUM_WITHDRAWAL_FOR_FEE_EXEMPTION, "Available amount should be above exemption threshold"); + + // Approve and withdraw + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.approveWithdrawal(); + + address owner = CampaignInfo(campaignAddress).owner(); + uint256 ownerBalanceBefore = testToken.balanceOf(owner); + + vm.warp(DEADLINE + 1); + keepWhatsRaised.withdraw(0); + + uint256 ownerBalanceAfter = testToken.balanceOf(owner); + uint256 received = ownerBalanceAfter - ownerBalanceBefore; + + // Should only have protocol fee deducted, not flat fee + uint256 expectedProtocolFee = (availableAfterPledge * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 expectedAmount = availableAfterPledge - expectedProtocolFee; + + assertApproxEqAbs(received, expectedAmount, 10, "Should receive amount minus only protocol fee"); + } + + function testWithdrawWithColombianCreatorTax() public { + // Configure with Colombian creator + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.configureTreasury(CONFIG_COLOMBIAN, CAMPAIGN_DATA, FEE_KEYS); + + // Make a pledge + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, PAYMENT_GATEWAY_FEE); + + vm.warp(LAUNCH_TIME); + vm.startPrank(users.backer1Address); + testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + vm.stopPrank(); + + // Approve withdrawal + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.approveWithdrawal(); + + address owner = CampaignInfo(campaignAddress).owner(); + uint256 ownerBalanceBefore = testToken.balanceOf(owner); + uint256 availableBeforeWithdraw = keepWhatsRaised.getAvailableRaisedAmount(); + + // Withdraw after deadline + vm.warp(DEADLINE + 1); + keepWhatsRaised.withdraw(0); + + uint256 ownerBalanceAfter = testToken.balanceOf(owner); + uint256 received = ownerBalanceAfter - ownerBalanceBefore; + + // Calculate expected amount after Colombian tax + uint256 flatFee = uint256(FLAT_FEE_VALUE); + uint256 protocolFee = (availableBeforeWithdraw * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 amountAfterFees = availableBeforeWithdraw - flatFee - protocolFee; + + // Colombian tax: (amountAfterFees * 0.004) / 1.004 + uint256 colombianTax = (amountAfterFees * 40) / 10040; + uint256 expectedAmount = amountAfterFees - colombianTax; + + assertApproxEqAbs(received, expectedAmount, 10, "Should receive amount minus fees and Colombian tax"); + } + + /*////////////////////////////////////////////////////////////// + REFUNDS + //////////////////////////////////////////////////////////////*/ + + function testClaimRefundAfterDeadline() public { + // Make pledge + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, PAYMENT_GATEWAY_FEE); + + vm.warp(LAUNCH_TIME); + vm.startPrank(users.backer1Address); + testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + uint256 tokenId = 0; + vm.stopPrank(); + + uint256 balanceBefore = testToken.balanceOf(users.backer1Address); + + // Claim refund within refund window + vm.warp(DEADLINE + 1 days); + vm.prank(users.backer1Address); + keepWhatsRaised.claimRefund(tokenId); + + // Calculate expected refund (pledge minus fees) + uint256 platformFee = (TEST_PLEDGE_AMOUNT * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 vakiCommission = (TEST_PLEDGE_AMOUNT * uint256(VAKI_COMMISSION_VALUE)) / PERCENT_DIVIDER; + uint256 expectedRefund = TEST_PLEDGE_AMOUNT - PAYMENT_GATEWAY_FEE - platformFee - vakiCommission; + + // Verify refund amount is pledge minus fees + assertEq(testToken.balanceOf(users.backer1Address), balanceBefore + expectedRefund); + vm.expectRevert(); + keepWhatsRaised.ownerOf(tokenId); // Token should be burned + } + + function testClaimRefundRevertWhenOutsideRefundWindow() public { + // Make pledge + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, 0); + + vm.warp(LAUNCH_TIME); + vm.startPrank(users.backer1Address); + testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + uint256 tokenId = 0; + vm.stopPrank(); + + // Try to claim after refund window + vm.warp(DEADLINE + REFUND_DELAY + 1); + vm.expectRevert(); + vm.prank(users.backer1Address); + keepWhatsRaised.claimRefund(tokenId); + } + + function testClaimRefundAfterCancellation() public { + // Make pledge + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, PAYMENT_GATEWAY_FEE); + + vm.warp(LAUNCH_TIME); + vm.startPrank(users.backer1Address); + testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + uint256 tokenId = 0; + vm.stopPrank(); + + // Cancel campaign + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.cancelTreasury(keccak256("cancelled")); + + uint256 balanceBefore = testToken.balanceOf(users.backer1Address); + + // Claim refund + vm.warp(block.timestamp + 1); + vm.prank(users.backer1Address); + keepWhatsRaised.claimRefund(tokenId); + + // Calculate expected refund (pledge minus fees) + uint256 platformFee = (TEST_PLEDGE_AMOUNT * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 vakiCommission = (TEST_PLEDGE_AMOUNT * uint256(VAKI_COMMISSION_VALUE)) / PERCENT_DIVIDER; + uint256 expectedRefund = TEST_PLEDGE_AMOUNT - PAYMENT_GATEWAY_FEE - platformFee - vakiCommission; + + // Verify refund amount is pledge minus fees + assertEq(testToken.balanceOf(users.backer1Address), balanceBefore + expectedRefund); + } + + function testClaimRefundRevertWhenPaused() public { + // Make pledge first + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, 0); + + vm.warp(LAUNCH_TIME); + vm.startPrank(users.backer1Address); + testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + uint256 tokenId = 0; + vm.stopPrank(); + + _pauseTreasury(); + + // Try to claim refund + vm.warp(DEADLINE + 1 days); + vm.expectRevert(); + vm.prank(users.backer1Address); + keepWhatsRaised.claimRefund(tokenId); + } + + function testClaimRefundRevertWhenInsufficientFunds() public { + // Make pledge + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, 0); + + vm.warp(LAUNCH_TIME); + vm.startPrank(users.backer1Address); + testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + uint256 tokenId = 0; + vm.stopPrank(); + + // Withdraw all funds + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.approveWithdrawal(); + vm.warp(DEADLINE + 1); + keepWhatsRaised.withdraw(0); + + // Try to claim refund + vm.warp(DEADLINE + 1 days); + vm.expectRevert(); + vm.prank(users.backer1Address); + keepWhatsRaised.claimRefund(tokenId); + } + + /*////////////////////////////////////////////////////////////// + TIPS AND FUNDS CLAIMING + //////////////////////////////////////////////////////////////*/ + + function testClaimTipAfterDeadline() public { + // Setup pledges with tips + _setupPledges(); + + uint256 platformBalanceBefore = testToken.balanceOf(users.platform2AdminAddress); + uint256 totalTips = TEST_TIP_AMOUNT * 2; + + // Claim tips after deadline + vm.warp(DEADLINE + 1); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.claimTip(); + + // Verify + assertEq(testToken.balanceOf(users.platform2AdminAddress), platformBalanceBefore + totalTips); + } + + function testClaimTipRevertWhenBeforeDeadline() public { + _setupPledges(); + + vm.warp(DEADLINE - 1); + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedNotClaimableAdmin.selector); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.claimTip(); + } + + function testClaimTipRevertWhenAlreadyClaimed() public { + _setupPledges(); + + vm.warp(DEADLINE + 1); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.claimTip(); + + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedAlreadyClaimed.selector); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.claimTip(); + } + + function testClaimTipRevertWhenPaused() public { + // Setup pledges with tips + _setupPledges(); + _pauseTreasury(); + + vm.warp(DEADLINE + 1); + vm.expectRevert(); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.claimTip(); + } + + function testClaimFundAfterWithdrawalDelay() public { + // Setup pledges + _setupPledges(); + + uint256 platformBalanceBefore = testToken.balanceOf(users.platform2AdminAddress); + uint256 availableFunds = keepWhatsRaised.getAvailableRaisedAmount(); + + // Claim funds after withdrawal delay + vm.warp(DEADLINE + WITHDRAWAL_DELAY + 1); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.claimFund(); + + // Verify + assertEq(testToken.balanceOf(users.platform2AdminAddress), platformBalanceBefore + availableFunds); + assertEq(keepWhatsRaised.getAvailableRaisedAmount(), 0); + } + + function testClaimFundAfterCancellation() public { + // Setup pledges + _setupPledges(); + + uint256 platformBalanceBefore = testToken.balanceOf(users.platform2AdminAddress); + uint256 availableFunds = keepWhatsRaised.getAvailableRaisedAmount(); + + // Cancel treasury + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.cancelTreasury(keccak256("cancelled")); + + // Claim funds after refund delay from cancellation + vm.warp(block.timestamp + REFUND_DELAY + 1); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.claimFund(); + + // Verify + assertEq(testToken.balanceOf(users.platform2AdminAddress), platformBalanceBefore + availableFunds); + assertEq(keepWhatsRaised.getAvailableRaisedAmount(), 0); + } + + function testClaimFundRevertWhenBeforeWithdrawalDelay() public { + _setupPledges(); + + vm.warp(DEADLINE + WITHDRAWAL_DELAY - 1); + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedNotClaimableAdmin.selector); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.claimFund(); + } + + function testClaimFundRevertWhenAlreadyClaimed() public { + _setupPledges(); + + vm.warp(DEADLINE + WITHDRAWAL_DELAY + 1); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.claimFund(); + + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedAlreadyClaimed.selector); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.claimFund(); + } + + function testClaimFundRevertWhenPaused() public { + // Setup pledges + _setupPledges(); + _pauseTreasury(); + + vm.warp(DEADLINE + WITHDRAWAL_DELAY + 1); + vm.expectRevert(); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.claimFund(); + } + + /*////////////////////////////////////////////////////////////// + FEE DISBURSEMENT + //////////////////////////////////////////////////////////////*/ + + function testDisburseFees() public { + // Setup pledges and withdraw to generate fees + _setupPledges(); + + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.approveWithdrawal(); + + vm.warp(DEADLINE + 1); + keepWhatsRaised.withdraw(0); + + uint256 protocolBalanceBefore = testToken.balanceOf(users.protocolAdminAddress); + uint256 platformBalanceBefore = testToken.balanceOf(users.platform2AdminAddress); + + // Disburse fees immediately + keepWhatsRaised.disburseFees(); + + // Verify fees were distributed + assertTrue(testToken.balanceOf(users.protocolAdminAddress) > protocolBalanceBefore); + assertTrue(testToken.balanceOf(users.platform2AdminAddress) > platformBalanceBefore); + } + + function testDisburseFeesRevertWhenPaused() public { + // Setup pledges and withdraw to generate fees + _setupPledges(); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.approveWithdrawal(); + vm.warp(DEADLINE + 1); + keepWhatsRaised.withdraw(0); + + _pauseTreasury(); + + // Try to disburse fees - should revert + vm.expectRevert(); + keepWhatsRaised.disburseFees(); + } + + /*////////////////////////////////////////////////////////////// + CANCEL TREASURY + //////////////////////////////////////////////////////////////*/ + + function testCancelTreasuryByPlatformAdmin() public { + bytes32 message = keccak256("Platform cancellation"); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.cancelTreasury(message); + + // Verify campaign is cancelled + vm.warp(LAUNCH_TIME); + vm.expectRevert(); + vm.prank(users.backer1Address); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + } + + function testCancelTreasuryByCampaignOwner() public { + bytes32 message = keccak256("Owner cancellation"); + address campaignOwner = CampaignInfo(campaignAddress).owner(); + + vm.prank(campaignOwner); + keepWhatsRaised.cancelTreasury(message); + + // Verify campaign is cancelled + vm.warp(LAUNCH_TIME); + vm.expectRevert(); + vm.prank(users.backer1Address); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + } + + function testCancelTreasuryRevertWhenUnauthorized() public { + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedUnAuthorized.selector); + vm.prank(users.backer1Address); + keepWhatsRaised.cancelTreasury(keccak256("unauthorized")); + } + + /*////////////////////////////////////////////////////////////// + EDGE CASES + //////////////////////////////////////////////////////////////*/ + + function testMultiplePartialWithdrawals() public { + _setupPledges(); + + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.approveWithdrawal(); + + uint256 available = keepWhatsRaised.getAvailableRaisedAmount(); + + // First withdrawal: small amount that will incur cumulative fee + uint256 firstWithdrawal = 500e18; + // Second withdrawal: medium amount that will still incur cumulative fee + uint256 secondWithdrawal = 1000e18; + + // First withdrawal + vm.warp(LAUNCH_TIME + 1 days); + uint256 availableBefore1 = keepWhatsRaised.getAvailableRaisedAmount(); + keepWhatsRaised.withdraw(firstWithdrawal); + uint256 availableAfter1 = keepWhatsRaised.getAvailableRaisedAmount(); + + // Verify first withdrawal reduced available amount + assertTrue(availableAfter1 < availableBefore1, "First withdrawal should reduce available"); + + // Second withdrawal + vm.warp(LAUNCH_TIME + 2 days); + uint256 availableBefore2 = keepWhatsRaised.getAvailableRaisedAmount(); + keepWhatsRaised.withdraw(secondWithdrawal); + uint256 availableAfter2 = keepWhatsRaised.getAvailableRaisedAmount(); + + // Verify second withdrawal reduced available amount + assertTrue(availableAfter2 < availableBefore2, "Second withdrawal should reduce available"); + + // Verify remaining amount + assertTrue(keepWhatsRaised.getAvailableRaisedAmount() > 0, "Should still have funds available"); + } + + function testWithdrawalRevertWhenFeesExceedAmount() public { + // Make a small pledge + uint256 smallPledge = 2500e18; + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, 0); + + vm.warp(LAUNCH_TIME); + vm.startPrank(users.backer1Address); + testToken.approve(address(keepWhatsRaised), smallPledge); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, smallPledge, 0); + vm.stopPrank(); + + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.approveWithdrawal(); + + vm.warp(LAUNCH_TIME + 1 days); + vm.expectRevert(); + keepWhatsRaised.withdraw(190e18); + } + + function testZeroTipPledge() public { + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, 0); + + vm.warp(LAUNCH_TIME); + vm.startPrank(users.backer1Address); + testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + vm.stopPrank(); + + assertEq(keepWhatsRaised.getRaisedAmount(), TEST_PLEDGE_AMOUNT); + } + + function testFeeCalculationWithoutColombianTax() public { + // Make a pledge (non-Colombian) + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, PAYMENT_GATEWAY_FEE); + + vm.warp(LAUNCH_TIME); + vm.startPrank(users.backer1Address); + testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + vm.stopPrank(); + + uint256 available = keepWhatsRaised.getAvailableRaisedAmount(); + uint256 platformFee = (TEST_PLEDGE_AMOUNT * uint256(PLATFORM_FEE_VALUE)) / PERCENT_DIVIDER; + uint256 vakiCommission = (TEST_PLEDGE_AMOUNT * uint256(VAKI_COMMISSION_VALUE)) / PERCENT_DIVIDER; + uint256 totalFees = platformFee + vakiCommission + PAYMENT_GATEWAY_FEE; + + uint256 expectedAvailable = TEST_PLEDGE_AMOUNT - totalFees; + + assertEq(available, expectedAvailable); + } + + function testGetRewardRevertWhenNotExists() public { + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedInvalidInput.selector); + keepWhatsRaised.getReward(keccak256("nonexistent")); + } + + function testWithdrawRevertWhenZeroAfterDeadline() public { + // No pledges made + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.approveWithdrawal(); + + vm.warp(DEADLINE + 1); + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedAlreadyWithdrawn.selector); + keepWhatsRaised.withdraw(0); + } + + /*////////////////////////////////////////////////////////////// + COMPREHENSIVE FEE TESTS + //////////////////////////////////////////////////////////////*/ + + function testComplexFeeScenario() public { + // Testing multiple pledges with different fee structures + + // Configure Colombian creator for complex fee testing + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.configureTreasury(CONFIG_COLOMBIAN, CAMPAIGN_DATA, FEE_KEYS); + + // Add rewards + _setupReward(); + + // Pledge 1: With reward and tip + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("pledge1"), PAYMENT_GATEWAY_FEE); + vm.warp(LAUNCH_TIME); + vm.startPrank(users.backer1Address); + testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT + TEST_TIP_AMOUNT); + bytes32[] memory rewardSelection = new bytes32[](1); + rewardSelection[0] = TEST_REWARD_NAME; + keepWhatsRaised.pledgeForAReward(keccak256("pledge1"), users.backer1Address, TEST_TIP_AMOUNT, rewardSelection); + vm.stopPrank(); + + // Pledge 2: Without reward, different gateway fee + uint256 differentGatewayFee = 20e18; + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("pledge2"), differentGatewayFee); + vm.startPrank(users.backer2Address); + testToken.approve(address(keepWhatsRaised), 2000e18); + keepWhatsRaised.pledgeWithoutAReward(keccak256("pledge2"), users.backer2Address, 2000e18, 0); + vm.stopPrank(); + + // Verify total raised and available amounts + uint256 totalRaised = keepWhatsRaised.getRaisedAmount(); + uint256 totalAvailable = keepWhatsRaised.getAvailableRaisedAmount(); + + assertEq(totalRaised, TEST_PLEDGE_AMOUNT + 2000e18); + assertTrue(totalAvailable < totalRaised); // No colombian tax yet + + // Test partial withdrawal with Colombian tax applied + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.approveWithdrawal(); + + uint256 partialWithdrawAmount = 1000e18; + address owner = CampaignInfo(campaignAddress).owner(); + uint256 ownerBalanceBefore = testToken.balanceOf(owner); + + vm.warp(LAUNCH_TIME + 1 days); + keepWhatsRaised.withdraw(partialWithdrawAmount); + + uint256 ownerBalanceAfter = testToken.balanceOf(owner); + uint256 netReceived = ownerBalanceAfter - ownerBalanceBefore; + + // Verify withdrawal amount minus fees and Colombian tax + assertTrue(netReceived < partialWithdrawAmount); + } + + function testWithdrawalFeeStructure() public { + // Testing different withdrawal scenarios and their fee implications + + // Small withdrawal (below exemption) before deadline + uint256 smallAmount = 1000e18; + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("small"), 0); + + vm.warp(LAUNCH_TIME); + vm.startPrank(users.backer1Address); + testToken.approve(address(keepWhatsRaised), smallAmount); + keepWhatsRaised.pledgeWithoutAReward(keccak256("small"), users.backer1Address, smallAmount, 0); + vm.stopPrank(); + + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.approveWithdrawal(); + + address owner = CampaignInfo(campaignAddress).owner(); + uint256 balanceBefore = testToken.balanceOf(owner); + + // Withdraw before deadline - should apply cumulative fee + vm.warp(LAUNCH_TIME + 1 days); + keepWhatsRaised.withdraw(keepWhatsRaised.getAvailableRaisedAmount()); + + uint256 received = testToken.balanceOf(owner) - balanceBefore; + + assertTrue(received > 0, "Should receive something"); + } + + /*////////////////////////////////////////////////////////////// + HELPER FUNCTIONS + //////////////////////////////////////////////////////////////*/ + + function _createTestReward(uint256 value, bool isRewardTier) internal pure returns (Reward memory) { + bytes32[] memory itemIds = new bytes32[](1); + uint256[] memory itemValues = new uint256[](1); + uint256[] memory itemQuantities = new uint256[](1); + + itemIds[0] = keccak256("testItem"); + itemValues[0] = value; + itemQuantities[0] = 1; + + return Reward({ + rewardValue: value, + isRewardTier: isRewardTier, + itemId: itemIds, + itemValue: itemValues, + itemQuantity: itemQuantities + }); + } + + function _setupReward() internal { + bytes32[] memory rewardNames = new bytes32[](1); + rewardNames[0] = TEST_REWARD_NAME; + + Reward[] memory rewards = new Reward[](1); + rewards[0] = _createTestReward(TEST_PLEDGE_AMOUNT, true); + + vm.prank(users.creator1Address); + keepWhatsRaised.addRewards(rewardNames, rewards); + } + + function _setupPledges() internal { + _setupReward(); + + // Set gateway fees for pledges + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("pledge1"), PAYMENT_GATEWAY_FEE); + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("pledge2"), PAYMENT_GATEWAY_FEE); + + // Make pledges from two backers + vm.warp(LAUNCH_TIME); + + // Backer 1 pledge with reward + vm.startPrank(users.backer1Address); + testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT + TEST_TIP_AMOUNT); + bytes32[] memory rewardSelection = new bytes32[](1); + rewardSelection[0] = TEST_REWARD_NAME; + keepWhatsRaised.pledgeForAReward(keccak256("pledge1"), users.backer1Address, TEST_TIP_AMOUNT, rewardSelection); + vm.stopPrank(); + + // Backer 2 pledge without reward + vm.startPrank(users.backer2Address); + testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT + TEST_TIP_AMOUNT); + keepWhatsRaised.pledgeWithoutAReward(keccak256("pledge2"), users.backer2Address, TEST_PLEDGE_AMOUNT, TEST_TIP_AMOUNT); + vm.stopPrank(); + } + + function _pauseTreasury() internal { + // Pause treasury + bytes32 message = keccak256("Pause"); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.pauseTreasury(message); + } +} \ No newline at end of file diff --git a/test/foundry/utils/Defaults.sol b/test/foundry/utils/Defaults.sol index c77b2ea5..ddbaaa90 100644 --- a/test/foundry/utils/Defaults.sol +++ b/test/foundry/utils/Defaults.sol @@ -1,27 +1,26 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.20; import {Constants} from "./Constants.sol"; import {ICampaignData} from "src/interfaces/ICampaignData.sol"; import {AllOrNothing} from "src/treasuries/AllOrNothing.sol"; +import {KeepWhatsRaised} from "src/treasuries/KeepWhatsRaised.sol"; import {IReward} from "src/interfaces/IReward.sol"; /// @notice Contract with default values used throughout the tests. contract Defaults is Constants, ICampaignData, IReward { //Constant Variables - uint256 public constant PROTOCOL_FEE_PERCENT = 20 * 100; + uint256 public constant PROTOCOL_FEE_PERCENT = 20 * 100; uint256 public constant TOKEN_MINT_AMOUNT = 1_000_000e18; - uint256 public constant PLATFORM_FEE_PERCENT = 10 * 100; - bytes32 public constant PLATFORM_1_HASH = - keccak256(abi.encodePacked("KickStarter")); - bytes32 public constant REWARD_NAME_1_HASH = - keccak256(abi.encodePacked("sampleReward")); - bytes32 public constant CAMPAIGN_1_IDENTIFIER_HASH = - keccak256(abi.encodePacked("Sample Campaign")); + uint256 public constant PLATFORM_FEE_PERCENT = 10 * 100; // 10% + bytes32 public constant PLATFORM_1_HASH = keccak256(abi.encodePacked("KickStarter")); + bytes32 public constant PLATFORM_2_HASH = keccak256(abi.encodePacked("Vaki")); + bytes32 public constant REWARD_NAME_1_HASH = keccak256(abi.encodePacked("sampleReward")); + bytes32 public constant CAMPAIGN_1_IDENTIFIER_HASH = keccak256(abi.encodePacked("Sample Campaign")); string public constant NAME = "Name"; string public constant SYMBOL = "Symbol"; - uint256 public constant GOAL_AMOUNT = 100; - uint256 public constant CAMPAIGN_DURATION = 10_000 seconds; + uint256 public constant GOAL_AMOUNT = 100_000e18; // Increased to handle fees better + uint256 public constant CAMPAIGN_DURATION = 30 days; uint256 public constant PLEDGE_AMOUNT = 1_000e18; uint256 public constant PERCENT_DIVIDER = 10000; uint256 public constant SHIPPING_FEE = 10; @@ -42,19 +41,54 @@ contract Defaults is Constants, ICampaignData, IReward { bytes32[] public REWARD_NAMES; Reward[] public REWARDS; + // Fee Keys for KeepWhatsRaised + bytes32 public constant FLAT_FEE_KEY = keccak256(abi.encodePacked("flatFee")); + bytes32 public constant CUMULATIVE_FLAT_FEE_KEY = keccak256(abi.encodePacked("cumulativeFlatFee")); + bytes32 public constant PLATFORM_FEE_KEY = keccak256(abi.encodePacked("platformFee")); + bytes32 public constant VAKI_COMMISSION_KEY = keccak256(abi.encodePacked("vakiCommission")); + + // Fee Values + bytes32 public constant FLAT_FEE_VALUE = bytes32(uint256(100e18)); // 100 token flat fee + bytes32 public constant CUMULATIVE_FLAT_FEE_VALUE = bytes32(uint256(200e18)); // 200 token cumulative fee + bytes32 public constant PLATFORM_FEE_VALUE = bytes32(PLATFORM_FEE_PERCENT); // 10% + bytes32 public constant VAKI_COMMISSION_VALUE = bytes32(uint256(6 * 100)); // 6% for regular campaigns + + // Payment Gateway Fees - proportional to pledge + uint256 public constant PAYMENT_GATEWAY_FEE = 40e18; // 4% of 1000e18 + uint256 public constant PAYMENT_GATEWAY_FEE_PERCENTAGE = 4 * 100; // 4% + + // Config values for KeepWhatsRaised + uint256 public constant MINIMUM_WITHDRAWAL_FOR_FEE_EXEMPTION = 50_000e18; + uint256 public constant WITHDRAWAL_DELAY = 7 days; + uint256 public constant REFUND_DELAY = 14 days; + uint256 public constant CONFIG_LOCK_PERIOD = 2 days; + + // Additional constants + uint256 public constant TIP_AMOUNT = 10e18; + uint256 public constant WITHDRAWAL_AMOUNT = 50_000e18; + + // Test Pledge IDs + bytes32 public constant TEST_PLEDGE_ID_1 = keccak256(abi.encodePacked("pledge1")); + bytes32 public constant TEST_PLEDGE_ID_2 = keccak256(abi.encodePacked("pledge2")); + bytes32 public constant TEST_PLEDGE_ID_3 = keccak256(abi.encodePacked("pledge3")); + + KeepWhatsRaised.FeeKeys public FEE_KEYS; + KeepWhatsRaised.Config public CONFIG; + KeepWhatsRaised.Config public CONFIG_COLOMBIAN; + bytes32[] public GROSS_PERCENTAGE_FEE_KEYS; + bytes32[] public GROSS_PERCENTAGE_FEE_VALUES; + constructor() { LAUNCH_TIME = OCTOBER_1_2023 + 300 seconds; DEADLINE = LAUNCH_TIME + CAMPAIGN_DURATION; //Add Campaign Data - CAMPAIGN_DATA = CampaignData({ - launchTime: LAUNCH_TIME, - deadline: DEADLINE, - goalAmount: GOAL_AMOUNT - }); + CAMPAIGN_DATA = CampaignData({launchTime: LAUNCH_TIME, deadline: DEADLINE, goalAmount: GOAL_AMOUNT}); // Initialize the reward arrays setupRewardData(); + + setupKeepWhatsRaisedData(); } // Setup the reward data that can be accessed by tests @@ -117,4 +151,40 @@ contract Defaults is Constants, ICampaignData, IReward { itemQuantity: emptyQuantities }); } -} + + function setupKeepWhatsRaisedData() internal { + // Setup gross percentage fee keys and values + GROSS_PERCENTAGE_FEE_KEYS = new bytes32[](2); + GROSS_PERCENTAGE_FEE_KEYS[0] = PLATFORM_FEE_KEY; + GROSS_PERCENTAGE_FEE_KEYS[1] = VAKI_COMMISSION_KEY; + + GROSS_PERCENTAGE_FEE_VALUES = new bytes32[](2); + GROSS_PERCENTAGE_FEE_VALUES[0] = PLATFORM_FEE_VALUE; + GROSS_PERCENTAGE_FEE_VALUES[1] = VAKI_COMMISSION_VALUE; + + // Setup FEE_KEYS struct + FEE_KEYS = KeepWhatsRaised.FeeKeys({ + flatFeeKey: FLAT_FEE_KEY, + cumulativeFlatFeeKey: CUMULATIVE_FLAT_FEE_KEY, + grossPercentageFeeKeys: GROSS_PERCENTAGE_FEE_KEYS + }); + + // Setup CONFIG struct for non-Colombian creator + CONFIG = KeepWhatsRaised.Config({ + minimumWithdrawalForFeeExemption: MINIMUM_WITHDRAWAL_FOR_FEE_EXEMPTION, + withdrawalDelay: WITHDRAWAL_DELAY, + refundDelay: REFUND_DELAY, + configLockPeriod: CONFIG_LOCK_PERIOD, + isColombianCreator: false + }); + + // Setup CONFIG struct for Colombian creator + CONFIG_COLOMBIAN = KeepWhatsRaised.Config({ + minimumWithdrawalForFeeExemption: MINIMUM_WITHDRAWAL_FOR_FEE_EXEMPTION, + withdrawalDelay: WITHDRAWAL_DELAY, + refundDelay: REFUND_DELAY, + configLockPeriod: CONFIG_LOCK_PERIOD, + isColombianCreator: true + }); + } +} \ No newline at end of file From 8555972381cfef573582df02d3f30cbc8cb33b4c Mon Sep 17 00:00:00 2001 From: mahabubAlahi <32974385+mahabubAlahi@users.noreply.github.com> Date: Mon, 4 Aug 2025 21:06:39 +0600 Subject: [PATCH 34/63] Fix `AllOrNothing` treasury test failures (#22) Co-authored-by: mahabubAlahi --- test/foundry/integration/AllOrNothing/AllOrNothing.t.sol | 4 +++- .../integration/AllOrNothing/AllOrNothingFunction.t.sol | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/test/foundry/integration/AllOrNothing/AllOrNothing.t.sol b/test/foundry/integration/AllOrNothing/AllOrNothing.t.sol index 70819256..0cc2dce3 100644 --- a/test/foundry/integration/AllOrNothing/AllOrNothing.t.sol +++ b/test/foundry/integration/AllOrNothing/AllOrNothing.t.sol @@ -246,7 +246,8 @@ abstract contract AllOrNothing_Integration_Shared_Test is function claimRefund( address caller, address allOrNothingAddress, - uint256 tokenId + uint256 tokenId, + uint256 warpTime ) internal returns ( @@ -256,6 +257,7 @@ abstract contract AllOrNothing_Integration_Shared_Test is address claimer ) { + vm.warp(warpTime); vm.startPrank(caller); vm.recordLogs(); diff --git a/test/foundry/integration/AllOrNothing/AllOrNothingFunction.t.sol b/test/foundry/integration/AllOrNothing/AllOrNothingFunction.t.sol index 640a2559..26101269 100644 --- a/test/foundry/integration/AllOrNothing/AllOrNothingFunction.t.sol +++ b/test/foundry/integration/AllOrNothing/AllOrNothingFunction.t.sol @@ -112,7 +112,7 @@ contract AllOrNothingFunction_Integration_Shared_Test is uint256 refundedTokenId, uint256 refundAmount, address claimer - ) = claimRefund(users.backer1Address, address(allOrNothing), tokenId); + ) = claimRefund(users.backer1Address, address(allOrNothing), tokenId, LAUNCH_TIME + 1 days); assertEq(refundedTokenId, tokenId); assertEq(refundAmount, PLEDGE_AMOUNT); @@ -150,7 +150,7 @@ contract AllOrNothingFunction_Integration_Shared_Test is Vm.Log[] memory logs, uint256 protocolShare, uint256 platformShare - ) = disburseFees(address(allOrNothing), DEADLINE); + ) = disburseFees(address(allOrNothing), DEADLINE + 1 days); uint256 expectedProtocolShare = (totalPledged * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; @@ -195,7 +195,7 @@ contract AllOrNothingFunction_Integration_Shared_Test is ); uint256 totalPledged = GOAL_AMOUNT + PLEDGE_AMOUNT; - disburseFees(address(allOrNothing), DEADLINE); + disburseFees(address(allOrNothing), DEADLINE + 1 days); (Vm.Log[] memory logs, address to, uint256 amount) = withdraw( address(allOrNothing), From c350b01dd29e359cc923dcb81eadb0aec6a97996 Mon Sep 17 00:00:00 2001 From: mahabubAlahi <32974385+mahabubAlahi@users.noreply.github.com> Date: Mon, 4 Aug 2025 20:34:12 +0600 Subject: [PATCH 35/63] Add Campaign Payment Treasury Implementation (#21) - Key Features - Core Architecture - `ICampaignPaymentTreasury` - Interface defining the payment treasury contract standards - `BasePaymentTreasury` - Abstract base contract with shared treasury functionality - `PaymentTreasury` - Concrete implementation with campaign-specific logic - `Modular Design` - Inherits from `CampaignAccessChecker` and `PausableCancellable` for access control and state management - Payment Management - `Payment Creation`: Secure payment creation with expiration timestamps - `Payment Confirmation`: Batch and individual payment confirmation system - `Payment Cancellation`: Administrative payment cancellation with amount tracking - `Expiration Handling`: Automatic validation of payment expiration times - Treasury Operations - `Fund Tracking`: Separate tracking of pending, confirmed, and available payment amounts - `Refund System`: Comprehensive refund processing for confirmed payments - `Fee Distribution`: Automated protocol and platform fee calculation and disbursement - `Withdrawal Management`: Controlled fund withdrawal after fee disbursement - Implementation Details - State Management ```JS struct PaymentInfo { address buyerAddress; bytes32 itemId; uint256 amount; uint256 expiration; bool isConfirmed; } ``` - Key Storage Variables - `s_pendingPaymentAmount` - Total amount in pending payments - `s_confirmedPaymentAmount` - Total amount in confirmed payments - `s_availableConfirmedPaymentAmount` - Available amount after fee deductions - `s_feesDisbursed` - Flag tracking fee disbursement status - Core Functions - Payment Operations - `createPayment()` - Create new payments with validation - `cancelPayment()` - Cancel individual payments - `confirmPayment()` - Confirm individual payments - `confirmPaymentBatch()` - Batch payment confirmation for gas efficiency - Treasury Operations - `disburseFees()` - Calculate and distribute protocol/platform fees - `withdraw()` - Withdraw remaining funds after fee disbursement - `claimRefund()` - Process refunds for confirmed payments - `getAvailableRaisedAmount()` - Get the current available treasury balance - Administrative Functions - `pauseTreasury()` - Pause treasury operations - `unpauseTreasury()` - Resume treasury operations - `cancelTreasury()` - Cancel treasury (platform admin or owner) - Technical Features - Access Control - `Platform Admin Controls`: Payment creation, confirmation, cancellation - `Owner Controls`: Treasury cancellation permissions - Error Handling - `PaymentTreasuryInvalidInput` - Invalid function parameters - `PaymentTreasuryPaymentAlreadyExist` - Duplicate payment ID - `PaymentTreasuryPaymentAlreadyExpired` - Expired payment operations - `PaymentTreasuryFeeNotDisbursed` - Withdrawal before fee disbursement - `PaymentTreasuryUnAuthorized` - Access control violations - Testing Coverage - `Unit Tests`: Individual function testing with edge cases - `Integration Tests`: End-to-end payment and treasury workflows - `Access Control Tests`: Permission and authorization validation - `State Management Tests`: Pause/cancel state transitions - `Fee Calculation Tests`: Accurate fee distribution verification --------- Co-authored-by: mahabubAlahi Co-authored-by: AdnanHKx --- docs/src/SUMMARY.md | 3 + .../interface.ICampaignPaymentTreasury.md | 166 +++ docs/src/src/interfaces/README.md | 1 + .../contract.KeepWhatsRaised.md | 1101 +---------------- .../contract.PaymentTreasury.md | 130 ++ docs/src/src/treasuries/README.md | 1 + .../abstract.BasePaymentTreasury.md | 576 +++++++++ docs/src/src/utils/README.md | 1 + script/DeployAllAndSetupPaymentTreasury.s.sol | 439 +++++++ src/interfaces/ICampaignPaymentTreasury.sol | 90 ++ src/treasuries/PaymentTreasury.sol | 109 ++ src/utils/BasePaymentTreasury.sol | 476 +++++++ .../PaymentTreasury/PaymentTreasury.t.sol | 290 +++++ .../PaymentTreasuryFunction.t.sol | 172 +++ test/foundry/unit/PaymentTreasury.t.sol | 689 +++++++++++ 15 files changed, 3158 insertions(+), 1086 deletions(-) create mode 100644 docs/src/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md create mode 100644 docs/src/src/treasuries/PaymentTreasury.sol/contract.PaymentTreasury.md create mode 100644 docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md create mode 100644 script/DeployAllAndSetupPaymentTreasury.s.sol create mode 100644 src/interfaces/ICampaignPaymentTreasury.sol create mode 100644 src/treasuries/PaymentTreasury.sol create mode 100644 src/utils/BasePaymentTreasury.sol create mode 100644 test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol create mode 100644 test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol create mode 100644 test/foundry/unit/PaymentTreasury.t.sol diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index dd2e1eab..ccec9b40 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -5,6 +5,7 @@ - [ICampaignData](src/interfaces/ICampaignData.sol/interface.ICampaignData.md) - [ICampaignInfo](src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md) - [ICampaignInfoFactory](src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md) + - [ICampaignPaymentTreasury](src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md) - [ICampaignTreasury](src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md) - [IGlobalParams](src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md) - [IItem](src/interfaces/IItem.sol/interface.IItem.md) @@ -13,8 +14,10 @@ - [❱ treasuries](src/treasuries/README.md) - [AllOrNothing](src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md) - [KeepWhatsRaised](src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md) + - [PaymentTreasury](src/treasuries/PaymentTreasury.sol/contract.PaymentTreasury.md) - [❱ utils](src/utils/README.md) - [AdminAccessChecker](src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md) + - [BasePaymentTreasury](src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md) - [BaseTreasury](src/utils/BaseTreasury.sol/abstract.BaseTreasury.md) - [CampaignAccessChecker](src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md) - [Counters](src/utils/Counters.sol/library.Counters.md) diff --git a/docs/src/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md b/docs/src/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md new file mode 100644 index 00000000..e3206342 --- /dev/null +++ b/docs/src/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md @@ -0,0 +1,166 @@ +# ICampaignPaymentTreasury +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/4076c45194ab23360a65e56402b026ef44f70a42/src/interfaces/ICampaignPaymentTreasury.sol) + +An interface for managing campaign payment treasury contracts. + + +## Functions +### createPayment + +Creates a new payment entry with the specified details. + + +```solidity +function createPayment(bytes32 paymentId, address buyerAddress, bytes32 itemId, uint256 amount, uint256 expiration) + external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|A unique identifier for the payment.| +|`buyerAddress`|`address`|The address of the buyer initiating the payment.| +|`itemId`|`bytes32`|The identifier of the item being purchased.| +|`amount`|`uint256`|The amount to be paid for the item.| +|`expiration`|`uint256`|The timestamp after which the payment expires.| + + +### cancelPayment + +Cancels an existing payment with the given payment ID. + + +```solidity +function cancelPayment(bytes32 paymentId) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the payment to cancel.| + + +### confirmPayment + +Confirms and finalizes the payment associated with the given payment ID. + + +```solidity +function confirmPayment(bytes32 paymentId) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the payment to confirm.| + + +### confirmPaymentBatch + +Confirms and finalizes multiple payments in a single transaction. + + +```solidity +function confirmPaymentBatch(bytes32[] calldata paymentIds) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentIds`|`bytes32[]`|An array of unique payment identifiers to be confirmed.| + + +### disburseFees + +Disburses fees collected by the treasury. + + +```solidity +function disburseFees() external; +``` + +### withdraw + +Withdraws funds from the treasury. + + +```solidity +function withdraw() external; +``` + +### claimRefund + +Claims a refund for a specific payment ID. + + +```solidity +function claimRefund(bytes32 paymentId, address refundAddress) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the refundable payment.| +|`refundAddress`|`address`|The address where the refunded amount should be sent.| + + +### getplatformHash + +Retrieves the platform identifier associated with the treasury. + + +```solidity +function getplatformHash() external view returns (bytes32); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes32`|The platform identifier as a bytes32 value.| + + +### getplatformFeePercent + +Retrieves the platform fee percentage for the treasury. + + +```solidity +function getplatformFeePercent() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The platform fee percentage as a uint256 value.| + + +### getRaisedAmount + +Retrieves the total raised amount in the treasury. + + +```solidity +function getRaisedAmount() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The total raised amount as a uint256 value.| + + +### getAvailableRaisedAmount + +Retrieves the currently available raised amount in the treasury. + + +```solidity +function getAvailableRaisedAmount() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The current available raised amount as a uint256 value.| + + diff --git a/docs/src/src/interfaces/README.md b/docs/src/src/interfaces/README.md index e6bafb40..be6bb97a 100644 --- a/docs/src/src/interfaces/README.md +++ b/docs/src/src/interfaces/README.md @@ -4,6 +4,7 @@ - [ICampaignData](ICampaignData.sol/interface.ICampaignData.md) - [ICampaignInfo](ICampaignInfo.sol/interface.ICampaignInfo.md) - [ICampaignInfoFactory](ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md) +- [ICampaignPaymentTreasury](ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md) - [ICampaignTreasury](ICampaignTreasury.sol/interface.ICampaignTreasury.md) - [IGlobalParams](IGlobalParams.sol/interface.IGlobalParams.md) - [IItem](IItem.sol/interface.IItem.md) diff --git a/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md b/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md index 0f1896c3..286bd7bf 100644 --- a/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md +++ b/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md @@ -1,1111 +1,40 @@ # KeepWhatsRaised -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/3ab694bc5ce5037adb836a85fe710f413c2c20cc/src/treasuries/KeepWhatsRaised.sol) + +[Git Source](https://github.com/ccprotocol/campaign-utils-contracts-aggregator/blob/79d78188e565502f83e2c0309c9a4ea3b35cee91/src/treasuries/KeepWhatsRaised.sol) **Inherits:** [IReward](/src/interfaces/IReward.sol/interface.IReward.md), [BaseTreasury](/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md), [TimestampChecker](/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), ERC721Burnable, [ICampaignData](/src/interfaces/ICampaignData.sol/interface.ICampaignData.md) A contract that keeps all the funds raised, regardless of the success condition. - -## State Variables -### s_tokenToPledgedAmount - -```solidity -mapping(uint256 => uint256) private s_tokenToPledgedAmount; -``` - - -### s_tokenToTippedAmount - -```solidity -mapping(uint256 => uint256) private s_tokenToTippedAmount; -``` - - -### s_tokenToPaymentFee - -```solidity -mapping(uint256 => uint256) private s_tokenToPaymentFee; -``` - - -### s_reward - -```solidity -mapping(bytes32 => Reward) private s_reward; -``` - - -### s_processedPledges -Tracks whether a pledge with a specific ID has already been processed - - -```solidity -mapping(bytes32 => bool) public s_processedPledges; -``` - - -### s_paymentGatewayFees -Mapping to store payment gateway fees by unique pledge ID - - -```solidity -mapping(bytes32 => uint256) public s_paymentGatewayFees; -``` - - -### s_tokenIdCounter - -```solidity -Counters.Counter private s_tokenIdCounter; -``` - - -### s_rewardCounter - -```solidity -Counters.Counter private s_rewardCounter; -``` - - -### s_name - -```solidity -string private s_name; -``` - - -### s_symbol - -```solidity -string private s_symbol; -``` - - -### s_tip - -```solidity -uint256 private s_tip; -``` - - -### s_platformFee - -```solidity -uint256 private s_platformFee; -``` - - -### s_protocolFee - -```solidity -uint256 private s_protocolFee; -``` - - -### s_availablePledgedAmount - -```solidity -uint256 private s_availablePledgedAmount; -``` - - -### s_cancellationTime - -```solidity -uint256 private s_cancellationTime; -``` - - -### s_isWithdrawalApproved - -```solidity -bool private s_isWithdrawalApproved; -``` - - -### s_tipClaimed - -```solidity -bool private s_tipClaimed; -``` - - -### s_fundClaimed - -```solidity -bool private s_fundClaimed; -``` - - -### s_feeKeys - -```solidity -FeeKeys private s_feeKeys; -``` - - -### s_config - -```solidity -Config private s_config; -``` - - -### s_campaignData - -```solidity -CampaignData private s_campaignData; -``` - +_This contract inherits from the `AllOrNothing` contract and overrides the `_checkSuccessCondition` function to always return true._ ## Functions -### withdrawalEnabled - -*Ensures that withdrawals are currently enabled. -Reverts with `KeepWhatsRaisedDisabled` if the withdrawal approval flag is not set.* - - -```solidity -modifier withdrawalEnabled(); -``` - -### onlyBeforeConfigLock - -*Restricts execution to only occur before the configuration lock period. -Reverts with `KeepWhatsRaisedConfigLocked` if called too close to or after the campaign deadline. -The lock period is defined as the duration before the deadline during which configuration changes are not allowed.* - - -```solidity -modifier onlyBeforeConfigLock(); -``` - -### onlyPlatformAdminOrCampaignOwner - -Restricts access to only the platform admin or the campaign owner. - -*Checks if `msg.sender` is either the platform admin (via `INFO.getPlatformAdminAddress`) -or the campaign owner (via `INFO.owner()`). Reverts with `KeepWhatsRaisedUnAuthorized` if not authorized.* - - -```solidity -modifier onlyPlatformAdminOrCampaignOwner(); -``` ### constructor -*Constructor for the KeepWhatsRaised contract.* - - -```solidity -constructor() ERC721("", ""); -``` - -### initialize - - -```solidity -function initialize(bytes32 _platformHash, address _infoAddress, string calldata _name, string calldata _symbol) - external - initializer; -``` - -### name - - -```solidity -function name() public view override returns (string memory); -``` - -### symbol - - -```solidity -function symbol() public view override returns (string memory); -``` - -### getWithdrawalApprovalStatus - -Retrieves the withdrawal approval status. - - -```solidity -function getWithdrawalApprovalStatus() public view returns (bool); -``` - -### getReward - -Retrieves the details of a reward. - +_Initializes the KeepWhatsRaised contract._ ```solidity -function getReward(bytes32 rewardName) external view returns (Reward memory reward); +constructor(bytes32 platformHash, address infoAddress) AllOrNothing(platformHash, infoAddress); ``` **Parameters** -|Name|Type|Description| -|----|----|-----------| -|`rewardName`|`bytes32`|The name of the reward.| - -**Returns** - -|Name|Type|Description| -|----|----|-----------| -|`reward`|`Reward`|The details of the reward as a `Reward` struct.| - - -### getRaisedAmount - -Retrieves the total raised amount in the treasury. - - -```solidity -function getRaisedAmount() external view override returns (uint256); -``` -**Returns** - -|Name|Type|Description| -|----|----|-----------| -|``|`uint256`|The total raised amount as a uint256 value.| - - -### getAvailableRaisedAmount - -Retrieves the currently available raised amount in the treasury. - - -```solidity -function getAvailableRaisedAmount() external view returns (uint256); -``` -**Returns** - -|Name|Type|Description| -|----|----|-----------| -|``|`uint256`|The current available raised amount as a uint256 value.| - - -### getLaunchTime - -Retrieves the campaign's launch time. - - -```solidity -function getLaunchTime() public view returns (uint256); -``` -**Returns** - -|Name|Type|Description| -|----|----|-----------| -|``|`uint256`|The timestamp when the campaign was launched.| - - -### getDeadline - -Retrieves the campaign's deadline. - - -```solidity -function getDeadline() public view returns (uint256); -``` -**Returns** - -|Name|Type|Description| -|----|----|-----------| -|``|`uint256`|The timestamp when the campaign ends.| - - -### getGoalAmount - -Retrieves the campaign's funding goal amount. - - -```solidity -function getGoalAmount() external view returns (uint256); -``` -**Returns** - -|Name|Type|Description| -|----|----|-----------| -|``|`uint256`|The funding goal amount of the campaign.| - - -### getPaymentGatewayFee +| Name | Type | Description | +| -------------- | --------- | ------------------------------------------------------------ | +| `platformHash` | `bytes32` | The unique identifier of the platform. | +| `infoAddress` | `address` | The address of the associated campaign information contract. | -Retrieves the payment gateway fee for a given pledge ID. +### \_checkSuccessCondition +_Internal function to check the success condition for fee disbursement._ ```solidity -function getPaymentGatewayFee(bytes32 pledgeId) public view returns (uint256); +function _checkSuccessCondition() internal pure override returns (bool); ``` -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`pledgeId`|`bytes32`|The unique identifier of the pledge.| **Returns** -|Name|Type|Description| -|----|----|-----------| -|``|`uint256`|The fixed gateway fee amount associated with the pledge ID.| - - -### setPaymentGatewayFee - -Sets the fixed payment gateway fee for a specific pledge. - - -```solidity -function setPaymentGatewayFee(bytes32 pledgeId, uint256 fee) - public - onlyPlatformAdmin(PLATFORM_HASH) - whenCampaignNotPaused - whenNotPaused - whenCampaignNotCancelled - whenNotCancelled; -``` -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`pledgeId`|`bytes32`|The unique identifier of the pledge.| -|`fee`|`uint256`|The gateway fee amount to be associated with the given pledge ID.| - - -### approveWithdrawal - -Approves the withdrawal of the treasury by the platform admin. - - -```solidity -function approveWithdrawal() - external - onlyPlatformAdmin(PLATFORM_HASH) - whenCampaignNotPaused - whenNotPaused - whenCampaignNotCancelled - whenNotCancelled; -``` - -### configureTreasury - -*Configures the treasury for a campaign by setting the system parameters, -campaign-specific data, and fee configuration keys.* - - -```solidity -function configureTreasury(Config memory config, CampaignData memory campaignData, FeeKeys memory feeKeys) - external - onlyPlatformAdmin(PLATFORM_HASH) - whenCampaignNotPaused - whenNotPaused - whenCampaignNotCancelled - whenNotCancelled; -``` -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`config`|`Config`|The configuration settings including withdrawal delay, refund delay, fee exemption threshold, and configuration lock period.| -|`campaignData`|`CampaignData`|The campaign-related metadata such as deadlines and funding goals.| -|`feeKeys`|`FeeKeys`|The set of keys used to reference applicable flat and percentage-based fees.| - - -### updateDeadline - -*Updates the campaign's deadline.* - - -```solidity -function updateDeadline(uint256 deadline) - external - onlyPlatformAdminOrCampaignOwner - onlyBeforeConfigLock - whenNotPaused - whenNotCancelled; -``` -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`deadline`|`uint256`|The new deadline timestamp for the campaign. Requirements: - Must be called before the configuration lock period (see `onlyBeforeConfigLock`). - The new deadline must be a future timestamp.| - - -### updateGoalAmount - -*Updates the funding goal amount for the campaign.* - - -```solidity -function updateGoalAmount(uint256 goalAmount) - external - onlyPlatformAdminOrCampaignOwner - onlyBeforeConfigLock - whenNotPaused - whenNotCancelled; -``` -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`goalAmount`|`uint256`|The new goal amount. Requirements: - Must be called before the configuration lock period (see `onlyBeforeConfigLock`).| - - -### addRewards - -Adds multiple rewards in a batch. - -*This function allows for both reward tiers and non-reward tiers. -For both types, rewards must have non-zero value. -If items are specified (non-empty arrays), the itemId, itemValue, and itemQuantity arrays must match in length. -Empty arrays are allowed for both reward tiers and non-reward tiers.* - - -```solidity -function addRewards(bytes32[] calldata rewardNames, Reward[] calldata rewards) - external - onlyCampaignOwner - whenCampaignNotPaused - whenNotPaused - whenCampaignNotCancelled - whenNotCancelled; -``` -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`rewardNames`|`bytes32[]`|An array of reward names.| -|`rewards`|`Reward[]`|An array of `Reward` structs containing reward details.| - - -### removeReward - -Removes a reward from the campaign. - - -```solidity -function removeReward(bytes32 rewardName) - external - onlyCampaignOwner - whenCampaignNotPaused - whenNotPaused - whenCampaignNotCancelled - whenNotCancelled; -``` -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`rewardName`|`bytes32`|The name of the reward.| - - -### setFeeAndPledge - -Sets the payment gateway fee and executes a pledge in a single transaction. - - -```solidity -function setFeeAndPledge( - bytes32 pledgeId, - address backer, - uint256 pledgeAmount, - uint256 tip, - uint256 fee, - bytes32[] calldata reward, - bool isPledgeForAReward -) - external - onlyPlatformAdmin(PLATFORM_HASH) - whenCampaignNotPaused - whenNotPaused - whenCampaignNotCancelled - whenNotCancelled; -``` -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`pledgeId`|`bytes32`|The unique identifier of the pledge.| -|`backer`|`address`|The address of the backer making the pledge.| -|`pledgeAmount`|`uint256`|The amount of the pledge.| -|`tip`|`uint256`|An optional tip can be added during the process.| -|`fee`|`uint256`|The payment gateway fee to associate with this pledge.| -|`reward`|`bytes32[]`|An array of reward names.| -|`isPledgeForAReward`|`bool`|A boolean indicating whether this pledge is for a reward or without..| - - -### pledgeForAReward - -Allows a backer to pledge for a reward. - -*The first element of the `reward` array must be a reward tier and the other elements can be either reward tiers or non-reward tiers. -The non-reward tiers cannot be pledged for without a reward.* - - -```solidity -function pledgeForAReward(bytes32 pledgeId, address backer, uint256 tip, bytes32[] calldata reward) - public - currentTimeIsWithinRange(getLaunchTime(), getDeadline()) - whenCampaignNotPaused - whenNotPaused - whenCampaignNotCancelled - whenNotCancelled; -``` -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`pledgeId`|`bytes32`|The unique identifier of the pledge.| -|`backer`|`address`|The address of the backer making the pledge.| -|`tip`|`uint256`|An optional tip can be added during the process.| -|`reward`|`bytes32[]`|An array of reward names.| - - -### pledgeWithoutAReward - -Allows a backer to pledge without selecting a reward. - - -```solidity -function pledgeWithoutAReward(bytes32 pledgeId, address backer, uint256 pledgeAmount, uint256 tip) - public - currentTimeIsWithinRange(getLaunchTime(), getDeadline()) - whenCampaignNotPaused - whenNotPaused - whenCampaignNotCancelled - whenNotCancelled; -``` -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`pledgeId`|`bytes32`|The unique identifier of the pledge.| -|`backer`|`address`|The address of the backer making the pledge.| -|`pledgeAmount`|`uint256`|The amount of the pledge.| -|`tip`|`uint256`|An optional tip can be added during the process.| - - -### withdraw - -Withdraws funds from the treasury. - - -```solidity -function withdraw() public view override whenNotPaused whenNotCancelled; -``` - -### withdraw - -*Allows a campaign owner or eligible party to withdraw a specified amount of funds.* - - -```solidity -function withdraw(uint256 amount) - public - currentTimeIsLess(getDeadline() + s_config.withdrawalDelay) - whenNotPaused - whenNotCancelled - withdrawalEnabled; -``` -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`amount`|`uint256`|The amount to withdraw. Requirements: - Withdrawals must be approved (see `withdrawalEnabled` modifier). - Amount must not exceed the available balance after fees. - May apply and deduct a withdrawal fee.| - - -### claimRefund - -*Allows a backer to claim a refund associated with a specific pledge (token ID).* - - -```solidity -function claimRefund(uint256 tokenId) - external - currentTimeIsGreater(getLaunchTime()) - whenCampaignNotPaused - whenNotPaused; -``` -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`tokenId`|`uint256`|The ID of the token representing the backer's pledge. Requirements: - Refund delay must have passed. - The token must be eligible for a refund and not previously claimed.| - - -### disburseFees - -*Disburses all accumulated fees to the appropriate fee collector or treasury. -Requirements: -- Only callable when fees are available.* - - -```solidity -function disburseFees() public override whenNotPaused whenNotCancelled; -``` - -### claimTip - -*Allows an authorized claimer to collect tips contributed during the campaign. -Requirements: -- Caller must be authorized to claim tips. -- Tip amount must be non-zero.* - - -```solidity -function claimTip() external onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenNotPaused; -``` - -### claimFund - -*Allows a campaign owner or authorized user to claim remaining campaign funds. -Requirements: -- Claim period must have started and funds must be available. -- Cannot be previously claimed.* - - -```solidity -function claimFund() external onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenNotPaused; -``` - -### cancelTreasury - -*This function is overridden to allow the platform admin and the campaign owner to cancel a treasury.* - - -```solidity -function cancelTreasury(bytes32 message) public override onlyPlatformAdminOrCampaignOwner; -``` - -### _checkSuccessCondition - -*Internal function to check the success condition for fee disbursement.* - - -```solidity -function _checkSuccessCondition() internal view virtual override returns (bool); -``` -**Returns** - -|Name|Type|Description| -|----|----|-----------| -|``|`bool`|Whether the success condition is met.| - - -### _pledge - - -```solidity -function _pledge( - bytes32 pledgeId, - address backer, - bytes32 reward, - uint256 pledgeAmount, - uint256 tip, - uint256 tokenId, - bytes32[] memory rewards -) private; -``` - -### _calculateNetAvailable - -This function performs the following calculations: -1. Applies all gross percentage fees based on platform configuration -2. Calculates Colombian creator tax if applicable (0.4% effective rate) -3. Updates the total platform fee accumulator - -*Calculates the net available amount after deducting platform fees and applicable taxes* - - -```solidity -function _calculateNetAvailable(bytes32 pledgeId, uint256 tokenId, uint256 pledgeAmount) internal returns (uint256); -``` -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`pledgeId`|`bytes32`|The unique identifier of the pledge.| -|`tokenId`|`uint256`|The ID of the token representing the pledge.| -|`pledgeAmount`|`uint256`|The total pledge amount before any deductions| - -**Returns** - -|Name|Type|Description| -|----|----|-----------| -|``|`uint256`|The net available amount after all fees and taxes are deducted| - - -### _checkRefundPeriodStatus - -Refund period logic: -- If campaign is cancelled: refund period is active until s_cancellationTime + s_config.refundDelay -- If campaign is not cancelled: refund period is active until deadline + s_config.refundDelay -- Before deadline (non-cancelled): not in refund period - -*Checks the refund period status based on campaign state* - -*This function handles both cancelled and non-cancelled campaign scenarios* - - -```solidity -function _checkRefundPeriodStatus(bool checkIfOver) internal view returns (bool); -``` -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`checkIfOver`|`bool`|If true, returns whether refund period is over; if false, returns whether currently within refund period| - -**Returns** - -|Name|Type|Description| -|----|----|-----------| -|``|`bool`|bool Status based on checkIfOver parameter| - - -### supportsInterface - - -```solidity -function supportsInterface(bytes4 interfaceId) public view override returns (bool); -``` - -## Events -### Receipt -*Emitted when a backer makes a pledge.* - - -```solidity -event Receipt( - address indexed backer, - bytes32 indexed reward, - uint256 pledgeAmount, - uint256 tip, - uint256 tokenId, - bytes32[] rewards -); -``` - -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`backer`|`address`|The address of the backer making the pledge.| -|`reward`|`bytes32`|The name of the reward.| -|`pledgeAmount`|`uint256`|The amount pledged.| -|`tip`|`uint256`|An optional tip can be added during the process.| -|`tokenId`|`uint256`|The ID of the token representing the pledge.| -|`rewards`|`bytes32[]`|An array of reward names.| - -### RewardsAdded -*Emitted when rewards are added to the campaign.* - - -```solidity -event RewardsAdded(bytes32[] rewardNames, Reward[] rewards); -``` - -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`rewardNames`|`bytes32[]`|The names of the rewards.| -|`rewards`|`Reward[]`|The details of the rewards.| - -### RewardRemoved -*Emitted when a reward is removed from the campaign.* - - -```solidity -event RewardRemoved(bytes32 indexed rewardName); -``` - -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`rewardName`|`bytes32`|The name of the reward.| - -### WithdrawalApproved -*Emitted when withdrawal functionality has been approved by the platform admin.* - - -```solidity -event WithdrawalApproved(); -``` - -### TreasuryConfigured -*Emitted when the treasury configuration is updated.* - - -```solidity -event TreasuryConfigured(Config config, CampaignData campaignData, FeeKeys feeKeys); -``` - -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`config`|`Config`|The updated configuration parameters (e.g., delays, exemptions).| -|`campaignData`|`CampaignData`|The campaign-related data associated with the treasury setup.| -|`feeKeys`|`FeeKeys`|The set of keys used to determine applicable fees.| - -### WithdrawalWithFeeSuccessful -*Emitted when a withdrawal is successfully processed along with the applied fee.* - - -```solidity -event WithdrawalWithFeeSuccessful(address indexed to, uint256 amount, uint256 fee); -``` - -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`to`|`address`|The recipient address receiving the funds.| -|`amount`|`uint256`|The total amount withdrawn (excluding fee).| -|`fee`|`uint256`|The fee amount deducted from the withdrawal.| - -### TipClaimed -*Emitted when a tip is claimed from the contract.* - - -```solidity -event TipClaimed(uint256 amount, address indexed claimer); -``` - -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`amount`|`uint256`|The amount of tip claimed.| -|`claimer`|`address`|The address that claimed the tip.| - -### FundClaimed -*Emitted when campaign or user's remaining funds are successfully claimed by the platform admin.* - - -```solidity -event FundClaimed(uint256 amount, address indexed claimer); -``` - -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`amount`|`uint256`|The amount of funds claimed.| -|`claimer`|`address`|The address that claimed the funds.| - -### RefundClaimed -*Emitted when a refund is claimed.* - - -```solidity -event RefundClaimed(uint256 indexed tokenId, uint256 refundAmount, address indexed claimer); -``` - -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`tokenId`|`uint256`|The ID of the token representing the pledge.| -|`refundAmount`|`uint256`|The refund amount claimed.| -|`claimer`|`address`|The address of the claimer.| - -### KeepWhatsRaisedDeadlineUpdated -*Emitted when the deadline of the campaign is updated.* - - -```solidity -event KeepWhatsRaisedDeadlineUpdated(uint256 newDeadline); -``` - -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`newDeadline`|`uint256`|The new deadline.| - -### KeepWhatsRaisedGoalAmountUpdated -*Emitted when the goal amount for a campaign is updated.* - - -```solidity -event KeepWhatsRaisedGoalAmountUpdated(uint256 newGoalAmount); -``` - -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`newGoalAmount`|`uint256`|The new goal amount set for the campaign.| - -### KeepWhatsRaisedPaymentGatewayFeeSet -*Emitted when a gateway fee is set for a specific pledge.* - - -```solidity -event KeepWhatsRaisedPaymentGatewayFeeSet(bytes32 indexed pledgeId, uint256 fee); -``` - -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`pledgeId`|`bytes32`|The unique identifier of the pledge.| -|`fee`|`uint256`|The amount of the payment gateway fee set.| - -## Errors -### KeepWhatsRaisedUnAuthorized -*Emitted when an unauthorized action is attempted.* - - -```solidity -error KeepWhatsRaisedUnAuthorized(); -``` - -### KeepWhatsRaisedInvalidInput -*Emitted when an invalid input is detected.* - - -```solidity -error KeepWhatsRaisedInvalidInput(); -``` - -### KeepWhatsRaisedRewardExists -*Emitted when a `Reward` already exists for given input.* - - -```solidity -error KeepWhatsRaisedRewardExists(); -``` - -### KeepWhatsRaisedDisabled -*Emitted when anyone called a disabled function.* - - -```solidity -error KeepWhatsRaisedDisabled(); -``` - -### KeepWhatsRaisedAlreadyEnabled -*Emitted when any functionality is already enabled and cannot be re-enabled.* - - -```solidity -error KeepWhatsRaisedAlreadyEnabled(); -``` - -### KeepWhatsRaisedWithdrawalOverload -*Emitted when a withdrawal attempt exceeds the available funds after accounting for the fee.* - - -```solidity -error KeepWhatsRaisedWithdrawalOverload(uint256 availableAmount, uint256 withdrawalAmount, uint256 fee); -``` - -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`availableAmount`|`uint256`|The maximum amount that can be withdrawn.| -|`withdrawalAmount`|`uint256`|The attempted withdrawal amount.| -|`fee`|`uint256`|The fee that would be applied to the withdrawal.| - -### KeepWhatsRaisedAlreadyWithdrawn -*Emitted when a withdrawal has already been made and cannot be repeated.* - - -```solidity -error KeepWhatsRaisedAlreadyWithdrawn(); -``` - -### KeepWhatsRaisedAlreadyClaimed -*Emitted when funds or rewards have already been claimed for the given context.* - - -```solidity -error KeepWhatsRaisedAlreadyClaimed(); -``` - -### KeepWhatsRaisedNotClaimable -*Emitted when a token or pledge is not eligible for claiming (e.g., claim period not reached or not valid).* - - -```solidity -error KeepWhatsRaisedNotClaimable(uint256 tokenId); -``` - -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`tokenId`|`uint256`|The ID of the token that was attempted to be claimed.| - -### KeepWhatsRaisedNotClaimableAdmin -*Emitted when an admin attempts to claim funds that are not yet claimable according to the rules.* - - -```solidity -error KeepWhatsRaisedNotClaimableAdmin(); -``` - -### KeepWhatsRaisedConfigLocked -*Emitted when a configuration change is attempted during the lock period.* - - -```solidity -error KeepWhatsRaisedConfigLocked(); -``` - -### KeepWhatsRaisedDisbursementBlocked -*Emitted when a disbursement is attempted before the refund period has ended.* - - -```solidity -error KeepWhatsRaisedDisbursementBlocked(); -``` - -### KeepWhatsRaisedPledgeAlreadyProcessed -*Emitted when a pledge is submitted using a pledgeId that has already been processed.* - - -```solidity -error KeepWhatsRaisedPledgeAlreadyProcessed(bytes32 pledgeId); -``` - -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`pledgeId`|`bytes32`|The unique identifier of the pledge that was already used.| - -## Structs -### FeeKeys -*Represents keys used to reference different fee configurations. -These keys are typically used to look up fee values stored in `s_platformData`.* - - -```solidity -struct FeeKeys { - bytes32 flatFeeKey; - bytes32 cumulativeFlatFeeKey; - bytes32[] grossPercentageFeeKeys; -} -``` - -### Config -*System configuration parameters related to withdrawal and refund behavior.* - - -```solidity -struct Config { - uint256 minimumWithdrawalForFeeExemption; - uint256 withdrawalDelay; - uint256 refundDelay; - uint256 configLockPeriod; - bool isColombianCreator; -} -``` - +| Name | Type | Description | +| -------- | ------ | ------------------------------------- | +| `` | `bool` | Whether the success condition is met. | diff --git a/docs/src/src/treasuries/PaymentTreasury.sol/contract.PaymentTreasury.md b/docs/src/src/treasuries/PaymentTreasury.sol/contract.PaymentTreasury.md new file mode 100644 index 00000000..753d043b --- /dev/null +++ b/docs/src/src/treasuries/PaymentTreasury.sol/contract.PaymentTreasury.md @@ -0,0 +1,130 @@ +# PaymentTreasury +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/4076c45194ab23360a65e56402b026ef44f70a42/src/treasuries/PaymentTreasury.sol) + +**Inherits:** +[BasePaymentTreasury](/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md) + + +## State Variables +### s_name + +```solidity +string private s_name; +``` + + +### s_symbol + +```solidity +string private s_symbol; +``` + + +## Functions +### constructor + +*Constructor for the AllOrNothing contract.* + + +```solidity +constructor(); +``` + +### initialize + + +```solidity +function initialize(bytes32 _platformHash, address _infoAddress, string calldata _name, string calldata _symbol) + external + initializer; +``` + +### name + + +```solidity +function name() public view returns (string memory); +``` + +### symbol + + +```solidity +function symbol() public view returns (string memory); +``` + +### claimRefund + +Claims a refund for a specific payment ID. + + +```solidity +function claimRefund(bytes32 paymentId, address refundAddress) public override whenNotPaused whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the refundable payment.| +|`refundAddress`|`address`|The address where the refunded amount should be sent.| + + +### disburseFees + +Disburses fees collected by the treasury. + + +```solidity +function disburseFees() public override whenNotPaused whenNotCancelled; +``` + +### withdraw + +Withdraws funds from the treasury. + + +```solidity +function withdraw() public override whenNotPaused whenNotCancelled; +``` + +### cancelTreasury + +*This function is overridden to allow the platform admin and the campaign owner to cancel a treasury.* + + +```solidity +function cancelTreasury(bytes32 message) public override; +``` + +### _checkSuccessCondition + +*Internal function to check the success condition for fee disbursement.* + + +```solidity +function _checkSuccessCondition() internal view virtual override returns (bool); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|Whether the success condition is met.| + + +## Errors +### PaymentTreasuryUnAuthorized +*Emitted when an unauthorized action is attempted.* + + +```solidity +error PaymentTreasuryUnAuthorized(); +``` + +### PaymentTreasuryFeeAlreadyDisbursed +*Emitted when `disburseFees` after fee is disbursed already.* + + +```solidity +error PaymentTreasuryFeeAlreadyDisbursed(); +``` + diff --git a/docs/src/src/treasuries/README.md b/docs/src/src/treasuries/README.md index c591b575..00a1cf9d 100644 --- a/docs/src/src/treasuries/README.md +++ b/docs/src/src/treasuries/README.md @@ -3,3 +3,4 @@ # Contents - [AllOrNothing](AllOrNothing.sol/contract.AllOrNothing.md) - [KeepWhatsRaised](KeepWhatsRaised.sol/contract.KeepWhatsRaised.md) +- [PaymentTreasury](PaymentTreasury.sol/contract.PaymentTreasury.md) diff --git a/docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md b/docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md new file mode 100644 index 00000000..2d5866ee --- /dev/null +++ b/docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md @@ -0,0 +1,576 @@ +# BasePaymentTreasury +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/4076c45194ab23360a65e56402b026ef44f70a42/src/utils/BasePaymentTreasury.sol) + +**Inherits:** +Initializable, [ICampaignPaymentTreasury](/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md), [CampaignAccessChecker](/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md), [PausableCancellable](/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md) + + +## State Variables +### ZERO_BYTES + +```solidity +bytes32 internal constant ZERO_BYTES = 0x0000000000000000000000000000000000000000000000000000000000000000; +``` + + +### PERCENT_DIVIDER + +```solidity +uint256 internal constant PERCENT_DIVIDER = 10000; +``` + + +### PLATFORM_HASH + +```solidity +bytes32 internal PLATFORM_HASH; +``` + + +### PLATFORM_FEE_PERCENT + +```solidity +uint256 internal PLATFORM_FEE_PERCENT; +``` + + +### TOKEN + +```solidity +IERC20 internal TOKEN; +``` + + +### s_feesDisbursed + +```solidity +bool internal s_feesDisbursed; +``` + + +### s_payment + +```solidity +mapping(bytes32 => PaymentInfo) internal s_payment; +``` + + +### s_pendingPaymentAmount + +```solidity +uint256 internal s_pendingPaymentAmount; +``` + + +### s_confirmedPaymentAmount + +```solidity +uint256 internal s_confirmedPaymentAmount; +``` + + +### s_availableConfirmedPaymentAmount + +```solidity +uint256 internal s_availableConfirmedPaymentAmount; +``` + + +## Functions +### __BaseContract_init + + +```solidity +function __BaseContract_init(bytes32 platformHash, address infoAddress) internal; +``` + +### whenCampaignNotPaused + +*Modifier that checks if the campaign is not paused.* + + +```solidity +modifier whenCampaignNotPaused(); +``` + +### whenCampaignNotCancelled + + +```solidity +modifier whenCampaignNotCancelled(); +``` + +### getplatformHash + +Retrieves the platform identifier associated with the treasury. + + +```solidity +function getplatformHash() external view override returns (bytes32); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes32`|The platform identifier as a bytes32 value.| + + +### getplatformFeePercent + +Retrieves the platform fee percentage for the treasury. + + +```solidity +function getplatformFeePercent() external view override returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The platform fee percentage as a uint256 value.| + + +### getRaisedAmount + +Retrieves the total raised amount in the treasury. + + +```solidity +function getRaisedAmount() public view virtual override returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The total raised amount as a uint256 value.| + + +### getAvailableRaisedAmount + +Retrieves the currently available raised amount in the treasury. + + +```solidity +function getAvailableRaisedAmount() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The current available raised amount as a uint256 value.| + + +### createPayment + +Creates a new payment entry with the specified details. + + +```solidity +function createPayment(bytes32 paymentId, address buyerAddress, bytes32 itemId, uint256 amount, uint256 expiration) + public + virtual + override + onlyPlatformAdmin(PLATFORM_HASH) + whenCampaignNotPaused + whenCampaignNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|A unique identifier for the payment.| +|`buyerAddress`|`address`|The address of the buyer initiating the payment.| +|`itemId`|`bytes32`|The identifier of the item being purchased.| +|`amount`|`uint256`|The amount to be paid for the item.| +|`expiration`|`uint256`|The timestamp after which the payment expires.| + + +### cancelPayment + +Cancels an existing payment with the given payment ID. + + +```solidity +function cancelPayment(bytes32 paymentId) + public + virtual + override + onlyPlatformAdmin(PLATFORM_HASH) + whenCampaignNotPaused + whenCampaignNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the payment to cancel.| + + +### confirmPayment + +Confirms and finalizes the payment associated with the given payment ID. + + +```solidity +function confirmPayment(bytes32 paymentId) + public + virtual + override + onlyPlatformAdmin(PLATFORM_HASH) + whenCampaignNotPaused + whenCampaignNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the payment to confirm.| + + +### confirmPaymentBatch + +Confirms and finalizes multiple payments in a single transaction. + + +```solidity +function confirmPaymentBatch(bytes32[] calldata paymentIds) + public + virtual + override + onlyPlatformAdmin(PLATFORM_HASH) + whenCampaignNotPaused + whenCampaignNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentIds`|`bytes32[]`|An array of unique payment identifiers to be confirmed.| + + +### claimRefund + + +```solidity +function claimRefund(bytes32 paymentId, address refundAddress) + public + virtual + override + onlyPlatformAdmin(PLATFORM_HASH) + whenCampaignNotPaused + whenCampaignNotCancelled; +``` + +### disburseFees + +Disburses fees collected by the treasury. + + +```solidity +function disburseFees() public virtual override whenCampaignNotPaused whenCampaignNotCancelled; +``` + +### withdraw + +Withdraws funds from the treasury. + + +```solidity +function withdraw() public virtual override whenCampaignNotPaused whenCampaignNotCancelled; +``` + +### pauseTreasury + +*External function to pause the campaign.* + + +```solidity +function pauseTreasury(bytes32 message) public virtual onlyPlatformAdmin(PLATFORM_HASH); +``` + +### unpauseTreasury + +*External function to unpause the campaign.* + + +```solidity +function unpauseTreasury(bytes32 message) public virtual onlyPlatformAdmin(PLATFORM_HASH); +``` + +### cancelTreasury + +*External function to cancel the campaign.* + + +```solidity +function cancelTreasury(bytes32 message) public virtual onlyPlatformAdmin(PLATFORM_HASH); +``` + +### _revertIfCampaignPaused + +*Internal function to check if the campaign is paused. +If the campaign is paused, it reverts with TreasuryCampaignInfoIsPaused error.* + + +```solidity +function _revertIfCampaignPaused() internal view; +``` + +### _revertIfCampaignCancelled + + +```solidity +function _revertIfCampaignCancelled() internal view; +``` + +### _validatePaymentForAction + +*Validates the given payment ID to ensure it is eligible for further action. +Reverts if: +- The payment does not exist. +- The payment has already been confirmed. +- The payment has already expired.* + + +```solidity +function _validatePaymentForAction(bytes32 paymentId) internal view; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the payment to validate.| + + +### _checkSuccessCondition + +*Internal function to check the success condition for fee disbursement.* + + +```solidity +function _checkSuccessCondition() internal view virtual returns (bool); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|Whether the success condition is met.| + + +## Events +### PaymentCreated +*Emitted when a new payment is created.* + + +```solidity +event PaymentCreated( + bytes32 indexed paymentId, address indexed buyerAddress, bytes32 indexed itemId, uint256 amount, uint256 expiration +); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the payment.| +|`buyerAddress`|`address`|The address of the buyer who initiated the payment.| +|`itemId`|`bytes32`|The identifier of the item being purchased.| +|`amount`|`uint256`|The amount to be paid for the item.| +|`expiration`|`uint256`|The timestamp after which the payment expires.| + +### PaymentCancelled +*Emitted when a payment is cancelled and removed from the treasury.* + + +```solidity +event PaymentCancelled(bytes32 indexed paymentId); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the cancelled payment.| + +### PaymentConfirmed +*Emitted when a payment is confirmed.* + + +```solidity +event PaymentConfirmed(bytes32 indexed paymentId); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the cancelled payment.| + +### PaymentBatchConfirmed +*Emitted when multiple payments are confirmed in a single batch operation.* + + +```solidity +event PaymentBatchConfirmed(bytes32[] paymentIds); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentIds`|`bytes32[]`|An array of unique identifiers for the confirmed payments.| + +### FeesDisbursed +Emitted when fees are successfully disbursed. + + +```solidity +event FeesDisbursed(uint256 protocolShare, uint256 platformShare); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`protocolShare`|`uint256`|The amount of fees sent to the protocol.| +|`platformShare`|`uint256`|The amount of fees sent to the platform.| + +### WithdrawalSuccessful +Emitted when a withdrawal is successful. + + +```solidity +event WithdrawalSuccessful(address indexed to, uint256 amount); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`to`|`address`|The recipient of the withdrawal.| +|`amount`|`uint256`|The amount withdrawn.| + +### RefundClaimed +*Emitted when a refund is claimed.* + + +```solidity +event RefundClaimed(bytes32 indexed paymentId, uint256 refundAmount, address indexed claimer); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the cancelled payment.| +|`refundAmount`|`uint256`|The refund amount claimed.| +|`claimer`|`address`|The address of the claimer.| + +## Errors +### PaymentTreasuryInvalidInput +*Reverts when one or more provided inputs to the payment treasury are invalid.* + + +```solidity +error PaymentTreasuryInvalidInput(); +``` + +### PaymentTreasuryPaymentAlreadyExist +*Throws an error indicating that the payment id is already exist.* + + +```solidity +error PaymentTreasuryPaymentAlreadyExist(bytes32 paymentId); +``` + +### PaymentTreasuryPaymentAlreadyConfirmed +*Throws an error indicating that the payment id is already confirmed.* + + +```solidity +error PaymentTreasuryPaymentAlreadyConfirmed(bytes32 paymentId); +``` + +### PaymentTreasuryPaymentAlreadyExpired +*Throws an error indicating that the payment id is already expired.* + + +```solidity +error PaymentTreasuryPaymentAlreadyExpired(bytes32 paymentId); +``` + +### PaymentTreasuryPaymentNotExist +*Throws an error indicating that the payment id is not exist.* + + +```solidity +error PaymentTreasuryPaymentNotExist(bytes32 paymentId); +``` + +### PaymentTreasuryCampaignInfoIsPaused +*Throws an error indicating that the campaign is paused.* + + +```solidity +error PaymentTreasuryCampaignInfoIsPaused(); +``` + +### PaymentTreasurySuccessConditionNotFulfilled +*Throws an error indicating that the success condition was not fulfilled.* + + +```solidity +error PaymentTreasurySuccessConditionNotFulfilled(); +``` + +### PaymentTreasuryFeeNotDisbursed +*Throws an error indicating that fees have not been disbursed.* + + +```solidity +error PaymentTreasuryFeeNotDisbursed(); +``` + +### PaymentTreasuryPaymentNotConfirmed +*Throws an error indicating that the payment id is not confirmed.* + + +```solidity +error PaymentTreasuryPaymentNotConfirmed(bytes32 paymentId); +``` + +### PaymentTreasuryPaymentNotClaimable +*Emitted when claiming an unclaimable refund.* + + +```solidity +error PaymentTreasuryPaymentNotClaimable(bytes32 paymentId); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the refundable payment.| + +### PaymentTreasuryAlreadyWithdrawn +*Emitted when an attempt is made to withdraw funds from the treasury but the payment has already been withdrawn.* + + +```solidity +error PaymentTreasuryAlreadyWithdrawn(); +``` + +## Structs +### PaymentInfo + +```solidity +struct PaymentInfo { + address buyerAddress; + bytes32 itemId; + uint256 amount; + uint256 expiration; + bool isConfirmed; +} +``` + diff --git a/docs/src/src/utils/README.md b/docs/src/src/utils/README.md index 41bc0ddb..d1fb1063 100644 --- a/docs/src/src/utils/README.md +++ b/docs/src/src/utils/README.md @@ -2,6 +2,7 @@ # Contents - [AdminAccessChecker](AdminAccessChecker.sol/abstract.AdminAccessChecker.md) +- [BasePaymentTreasury](BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md) - [BaseTreasury](BaseTreasury.sol/abstract.BaseTreasury.md) - [CampaignAccessChecker](CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md) - [Counters](Counters.sol/library.Counters.md) diff --git a/script/DeployAllAndSetupPaymentTreasury.s.sol b/script/DeployAllAndSetupPaymentTreasury.s.sol new file mode 100644 index 00000000..9cc95ca8 --- /dev/null +++ b/script/DeployAllAndSetupPaymentTreasury.s.sol @@ -0,0 +1,439 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.20; + +import {Script} from "forge-std/Script.sol"; +import {console2} from "forge-std/console2.sol"; +import {TestToken} from "../test/mocks/TestToken.sol"; +import {GlobalParams} from "src/GlobalParams.sol"; +import {CampaignInfoFactory} from "src/CampaignInfoFactory.sol"; +import {CampaignInfo} from "src/CampaignInfo.sol"; +import {TreasuryFactory} from "src/TreasuryFactory.sol"; +import {PaymentTreasury} from "src/treasuries/PaymentTreasury.sol"; + +/** + * @notice Script to deploy and setup all needed contracts for the protocol + */ +contract DeployAllAndSetupPaymentTreasury is Script { + // Customizable values (set through environment variables) + bytes32 platformHash; + uint256 protocolFeePercent; + uint256 platformFeePercent; + uint256 tokenMintAmount; + bool simulate; + + // Contract addresses + address testToken; + address globalParams; + address campaignInfoImplementation; + address treasuryFactory; + address campaignInfoFactory; + address paymentTreasuryImplementation; + + // User addresses + address deployerAddress; + address finalProtocolAdmin; + address finalPlatformAdmin; + address backer1; + address backer2; + + // Token details + // string tokenName; + // string tokenSymbol; + + // Flags to track what was completed + bool platformEnlisted = false; + bool implementationRegistered = false; + bool implementationApproved = false; + bool adminRightsTransferred = false; + + // Flags for contract deployment or reuse + bool testTokenDeployed = false; + bool globalParamsDeployed = false; + bool treasuryFactoryDeployed = false; + bool campaignInfoFactoryDeployed = false; + bool paymentTreasuryDeployed = false; + + // Configure parameters based on environment variables + function setupParams() internal { + // Get customizable values + string memory platformName = vm.envOr( + "PLATFORM_NAME", + string("E-Commerce") + ); + + platformHash = keccak256(abi.encodePacked(platformName)); + protocolFeePercent = vm.envOr("PROTOCOL_FEE_PERCENT", uint256(100)); // Default 1% + platformFeePercent = vm.envOr("PLATFORM_FEE_PERCENT", uint256(400)); // Default 4% + tokenMintAmount = vm.envOr("TOKEN_MINT_AMOUNT", uint256(10000000e18)); + simulate = vm.envOr("SIMULATE", false); + + // Get user addresses + uint256 deployerKey = vm.envUint("PRIVATE_KEY"); + deployerAddress = vm.addr(deployerKey); + + // These are the final admin addresses that will receive control + finalProtocolAdmin = vm.envOr( + "PROTOCOL_ADMIN_ADDRESS", + deployerAddress + ); + finalPlatformAdmin = vm.envOr( + "PLATFORM_ADMIN_ADDRESS", + deployerAddress + ); + backer1 = vm.envOr("BACKER1_ADDRESS", address(0)); + backer2 = vm.envOr("BACKER2_ADDRESS", address(0)); + + // Check for existing contract addresses + testToken = vm.envOr("TOKEN_ADDRESS", address(0)); + globalParams = vm.envOr("GLOBAL_PARAMS_ADDRESS", address(0)); + treasuryFactory = vm.envOr("TREASURY_FACTORY_ADDRESS", address(0)); + campaignInfoFactory = vm.envOr( + "CAMPAIGN_INFO_FACTORY_ADDRESS", + address(0) + ); + paymentTreasuryImplementation = vm.envOr( + "PAYMENT_TREASURY_IMPLEMENTATION_ADDRESS", + address(0) + ); + + console2.log("Using platform hash for:", platformName); + console2.log("Protocol fee percent:", protocolFeePercent); + console2.log("Platform fee percent:", platformFeePercent); + console2.log("Simulation mode:", simulate); + console2.log("Deployer address:", deployerAddress); + console2.log("Final protocol admin:", finalProtocolAdmin); + console2.log("Final platform admin:", finalPlatformAdmin); + } + + // Deploy or reuse contracts + function deployContracts() internal { + console2.log("Setting up contracts..."); + + // Deploy or reuse TestToken + + string memory tokenName = vm.envOr("TOKEN_NAME", string("TestToken")); + string memory tokenSymbol = vm.envOr("TOKEN_SYMBOL", string("TST")); + + if (testToken == address(0)) { + testToken = address(new TestToken(tokenName, tokenSymbol)); + testTokenDeployed = true; + console2.log("TestToken deployed at:", testToken); + } else { + console2.log("Reusing TestToken at:", testToken); + } + + // Deploy or reuse GlobalParams + if (globalParams == address(0)) { + globalParams = address( + new GlobalParams( + deployerAddress, // Initially deployer is protocol admin + testToken, + protocolFeePercent + ) + ); + globalParamsDeployed = true; + console2.log("GlobalParams deployed at:", globalParams); + } else { + console2.log("Reusing GlobalParams at:", globalParams); + } + + // We need at least TestToken and GlobalParams to continue + require(testToken != address(0), "TestToken address is required"); + require(globalParams != address(0), "GlobalParams address is required"); + + // Deploy CampaignInfo implementation if needed for new deployments + if (campaignInfoFactory == address(0)) { + campaignInfoImplementation = address( + new CampaignInfo(address(this)) + ); + console2.log( + "CampaignInfo implementation deployed at:", + campaignInfoImplementation + ); + } + + // Deploy or reuse TreasuryFactory + if (treasuryFactory == address(0)) { + treasuryFactory = address( + new TreasuryFactory(GlobalParams(globalParams)) + ); + treasuryFactoryDeployed = true; + console2.log("TreasuryFactory deployed at:", treasuryFactory); + } else { + console2.log("Reusing TreasuryFactory at:", treasuryFactory); + } + + // Deploy or reuse CampaignInfoFactory + if (campaignInfoFactory == address(0)) { + campaignInfoFactory = address( + new CampaignInfoFactory( + GlobalParams(globalParams), + campaignInfoImplementation + ) + ); + CampaignInfoFactory(campaignInfoFactory)._initialize( + treasuryFactory, + globalParams + ); + campaignInfoFactoryDeployed = true; + console2.log( + "CampaignInfoFactory deployed and initialized at:", + campaignInfoFactory + ); + } else { + console2.log( + "Reusing CampaignInfoFactory at:", + campaignInfoFactory + ); + } + + // Deploy or reuse PaymentTreasury implementation + if (paymentTreasuryImplementation == address(0)) { + paymentTreasuryImplementation = address(new PaymentTreasury()); + paymentTreasuryDeployed = true; + console2.log( + "PaymentTreasury implementation deployed at:", + paymentTreasuryImplementation + ); + } else { + console2.log( + "Reusing PaymentTreasury implementation at:", + paymentTreasuryImplementation + ); + } + } + + // Setup steps when deployer has all roles + function enlistPlatform() internal { + // Skip if we didn't deploy GlobalParams (assuming it's already set up) + if (!globalParamsDeployed) { + console2.log( + "Skipping enlistPlatform - using existing GlobalParams" + ); + platformEnlisted = true; + return; + } + + console2.log("Setting up: enlistPlatform"); + // Only use startPrank in simulation mode + if (simulate) { + vm.startPrank(deployerAddress); + } + + GlobalParams(globalParams).enlistPlatform( + platformHash, + deployerAddress, // Initially deployer is platform admin + platformFeePercent + ); + + if (simulate) { + vm.stopPrank(); + } + platformEnlisted = true; + console2.log("Platform enlisted successfully"); + } + + function registerTreasuryImplementation() internal { + // Skip if we didn't deploy TreasuryFactory (assuming it's already set up) + if (!treasuryFactoryDeployed || !paymentTreasuryDeployed) { + console2.log( + "Skipping registerTreasuryImplementation - using existing contracts" + ); + implementationRegistered = true; + return; + } + + console2.log("Setting up: registerTreasuryImplementation"); + // Only use startPrank in simulation mode + if (simulate) { + vm.startPrank(deployerAddress); + } + + TreasuryFactory(treasuryFactory).registerTreasuryImplementation( + platformHash, + 0, // Implementation ID + paymentTreasuryImplementation + ); + + if (simulate) { + vm.stopPrank(); + } + implementationRegistered = true; + console2.log("Treasury implementation registered successfully"); + } + + function approveTreasuryImplementation() internal { + // Skip if we didn't deploy TreasuryFactory (assuming it's already set up) + if (!treasuryFactoryDeployed || !paymentTreasuryDeployed) { + console2.log( + "Skipping approveTreasuryImplementation - using existing contracts" + ); + implementationApproved = true; + return; + } + + console2.log("Setting up: approveTreasuryImplementation"); + // Only use startPrank in simulation mode + if (simulate) { + vm.startPrank(deployerAddress); + } + + TreasuryFactory(treasuryFactory).approveTreasuryImplementation( + platformHash, + 0 // Implementation ID + ); + + if (simulate) { + vm.stopPrank(); + } + implementationApproved = true; + console2.log("Treasury implementation approved successfully"); + } + + function mintTokens() internal { + // Only mint tokens if we deployed TestToken + if (!testTokenDeployed) { + console2.log("Skipping mintTokens - using existing TestToken"); + return; + } + + if (backer1 != address(0) && backer2 != address(0)) { + console2.log("Minting tokens to test backers"); + TestToken(testToken).mint(backer1, tokenMintAmount); + if (backer1 != backer2) { + TestToken(testToken).mint(backer2, tokenMintAmount); + } + console2.log("Tokens minted successfully"); + } + } + + // Transfer admin rights to final addresses + function transferAdminRights() internal { + // Skip if we didn't deploy GlobalParams (assuming it's already set up) + if (!globalParamsDeployed) { + console2.log( + "Skipping transferAdminRights - using existing GlobalParams" + ); + adminRightsTransferred = true; + return; + } + + console2.log("Transferring admin rights to final addresses..."); + + // Only transfer if the final addresses are different from deployer + if (finalProtocolAdmin != deployerAddress) { + console2.log( + "Transferring protocol admin rights to:", + finalProtocolAdmin + ); + GlobalParams(globalParams).updateProtocolAdminAddress( + finalProtocolAdmin + ); + } + + if (finalPlatformAdmin != deployerAddress) { + console2.log( + "Updating platform admin address for platform hash:", + vm.toString(platformHash) + ); + GlobalParams(globalParams).updatePlatformAdminAddress( + platformHash, + finalPlatformAdmin + ); + } + + adminRightsTransferred = true; + console2.log("Admin rights transferred successfully"); + } + + function run() external { + // Load configuration + setupParams(); + + uint256 deployerKey = vm.envUint("PRIVATE_KEY"); + + // Start broadcast with deployer key + vm.startBroadcast(deployerKey); + + // Deploy or reuse contracts + deployContracts(); + + // Setup the protocol with individual transactions in the correct order + // Since deployer is both protocol and platform admin initially, we can do all steps + enlistPlatform(); + registerTreasuryImplementation(); + approveTreasuryImplementation(); + + // Mint tokens if needed + mintTokens(); + + // Finally, transfer admin rights to the final addresses + transferAdminRights(); + + // Stop broadcast + vm.stopBroadcast(); + + // Output summary + console2.log("\n--- Deployment & Setup Summary ---"); + console2.log("Platform Name Hash:", vm.toString(platformHash)); + console2.log("TOKEN_ADDRESS:", testToken); + console2.log("GLOBAL_PARAMS_ADDRESS:", globalParams); + if (campaignInfoImplementation != address(0)) { + console2.log( + "CAMPAIGN_INFO_IMPLEMENTATION_ADDRESS:", + campaignInfoImplementation + ); + } + console2.log("TREASURY_FACTORY_ADDRESS:", treasuryFactory); + console2.log("CAMPAIGN_INFO_FACTORY_ADDRESS:", campaignInfoFactory); + console2.log( + "PAYMENT_TREASURY_IMPLEMENTATION_ADDRESS:", + paymentTreasuryImplementation + ); + console2.log("Protocol Admin:", finalProtocolAdmin); + console2.log("Platform Admin:", finalPlatformAdmin); + + if (backer1 != address(0)) { + console2.log("Backer1 (tokens minted):", backer1); + } + if (backer2 != address(0) && backer1 != backer2) { + console2.log("Backer2 (tokens minted):", backer2); + } + + console2.log("\nDeployment status:"); + console2.log( + "- TestToken:", + testTokenDeployed ? "Newly deployed" : "Reused existing" + ); + console2.log( + "- GlobalParams:", + globalParamsDeployed ? "Newly deployed" : "Reused existing" + ); + console2.log( + "- TreasuryFactory:", + treasuryFactoryDeployed ? "Newly deployed" : "Reused existing" + ); + console2.log( + "- CampaignInfoFactory:", + campaignInfoFactoryDeployed ? "Newly deployed" : "Reused existing" + ); + console2.log( + "- PaymentTreasury Implementation:", + paymentTreasuryDeployed ? "Newly deployed" : "Reused existing" + ); + + console2.log("\nSetup steps:"); + console2.log("1. Platform enlisted:", platformEnlisted); + console2.log( + "2. Treasury implementation registered:", + implementationRegistered + ); + console2.log( + "3. Treasury implementation approved:", + implementationApproved + ); + console2.log("4. Admin rights transferred:", adminRightsTransferred); + + console2.log("\nDeployment and setup completed successfully!"); + } +} diff --git a/src/interfaces/ICampaignPaymentTreasury.sol b/src/interfaces/ICampaignPaymentTreasury.sol new file mode 100644 index 00000000..cd9f62ae --- /dev/null +++ b/src/interfaces/ICampaignPaymentTreasury.sol @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.20; + +/** + * @title ICampaignPaymentTreasury + * @notice An interface for managing campaign payment treasury contracts. + */ +interface ICampaignPaymentTreasury { + + /** + * @notice Creates a new payment entry with the specified details. + * @param paymentId A unique identifier for the payment. + * @param buyerAddress The address of the buyer initiating the payment. + * @param itemId The identifier of the item being purchased. + * @param amount The amount to be paid for the item. + * @param expiration The timestamp after which the payment expires. + */ + function createPayment( + bytes32 paymentId, + address buyerAddress, + bytes32 itemId, + uint256 amount, + uint256 expiration + ) external; + + /** + * @notice Cancels an existing payment with the given payment ID. + * @param paymentId The unique identifier of the payment to cancel. + */ + function cancelPayment( + bytes32 paymentId + ) external; + + /** + * @notice Confirms and finalizes the payment associated with the given payment ID. + * @param paymentId The unique identifier of the payment to confirm. + */ + function confirmPayment( + bytes32 paymentId + ) external; + + /** + * @notice Confirms and finalizes multiple payments in a single transaction. + * @param paymentIds An array of unique payment identifiers to be confirmed. + */ + function confirmPaymentBatch( + bytes32[] calldata paymentIds + ) external; + + /** + * @notice Disburses fees collected by the treasury. + */ + function disburseFees() external; + + /** + * @notice Withdraws funds from the treasury. + */ + function withdraw() external; + + /** + * @notice Claims a refund for a specific payment ID. + * @param paymentId The unique identifier of the refundable payment. + * @param refundAddress The address where the refunded amount should be sent. + */ + function claimRefund(bytes32 paymentId, address refundAddress) external; + + /** + * @notice Retrieves the platform identifier associated with the treasury. + * @return The platform identifier as a bytes32 value. + */ + function getplatformHash() external view returns (bytes32); + + /** + * @notice Retrieves the platform fee percentage for the treasury. + * @return The platform fee percentage as a uint256 value. + */ + function getplatformFeePercent() external view returns (uint256); + + /** + * @notice Retrieves the total raised amount in the treasury. + * @return The total raised amount as a uint256 value. + */ + function getRaisedAmount() external view returns (uint256); + + /** + * @notice Retrieves the currently available raised amount in the treasury. + * @return The current available raised amount as a uint256 value. + */ + function getAvailableRaisedAmount() external view returns (uint256); +} diff --git a/src/treasuries/PaymentTreasury.sol b/src/treasuries/PaymentTreasury.sol new file mode 100644 index 00000000..e9f18e1f --- /dev/null +++ b/src/treasuries/PaymentTreasury.sol @@ -0,0 +1,109 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.20; + +import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; + +import {BasePaymentTreasury} from "../utils/BasePaymentTreasury.sol"; +import {ICampaignPaymentTreasury} from "../interfaces/ICampaignPaymentTreasury.sol"; + +contract PaymentTreasury is + BasePaymentTreasury +{ + using SafeERC20 for IERC20; + + string private s_name; + string private s_symbol; + + /** + * @dev Emitted when an unauthorized action is attempted. + */ + error PaymentTreasuryUnAuthorized(); + + /** + * @dev Emitted when `disburseFees` after fee is disbursed already. + */ + error PaymentTreasuryFeeAlreadyDisbursed(); + + /** + * @dev Constructor for the AllOrNothing contract. + */ + constructor() {} + + function initialize( + bytes32 _platformHash, + address _infoAddress, + string calldata _name, + string calldata _symbol + ) external initializer { + __BaseContract_init(_platformHash, _infoAddress); + s_name = _name; + s_symbol = _symbol; + } + + function name() public view returns (string memory) { + return s_name; + } + + function symbol() public view returns (string memory) { + return s_symbol; + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function claimRefund( + bytes32 paymentId, + address refundAddress + ) public override whenNotPaused whenNotCancelled { + super.claimRefund(paymentId, refundAddress); + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function disburseFees() + public + override + whenNotPaused + whenNotCancelled + { + if (s_feesDisbursed) { + revert PaymentTreasuryFeeAlreadyDisbursed(); + } + super.disburseFees(); + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function withdraw() public override whenNotPaused whenNotCancelled { + super.withdraw(); + } + + /** + * @inheritdoc BasePaymentTreasury + * @dev This function is overridden to allow the platform admin and the campaign owner to cancel a treasury. + */ + function cancelTreasury(bytes32 message) public override { + if ( + msg.sender != INFO.getPlatformAdminAddress(PLATFORM_HASH) && + msg.sender != INFO.owner() + ) { + revert PaymentTreasuryUnAuthorized(); + } + _cancel(message); + } + + /** + * @inheritdoc BasePaymentTreasury + */ + function _checkSuccessCondition() + internal + view + virtual + override + returns (bool) + { + return true; + } +} \ No newline at end of file diff --git a/src/utils/BasePaymentTreasury.sol b/src/utils/BasePaymentTreasury.sol new file mode 100644 index 00000000..86dbddf3 --- /dev/null +++ b/src/utils/BasePaymentTreasury.sol @@ -0,0 +1,476 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.20; + +import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; +import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol"; + +import {ICampaignPaymentTreasury} from "../interfaces/ICampaignPaymentTreasury.sol"; +import {CampaignAccessChecker} from "./CampaignAccessChecker.sol"; +import {PausableCancellable} from "./PausableCancellable.sol"; + +abstract contract BasePaymentTreasury is + Initializable, + ICampaignPaymentTreasury, + CampaignAccessChecker, + PausableCancellable +{ + using SafeERC20 for IERC20; + + bytes32 internal constant ZERO_BYTES = + 0x0000000000000000000000000000000000000000000000000000000000000000; + uint256 internal constant PERCENT_DIVIDER = 10000; + + bytes32 internal PLATFORM_HASH; + uint256 internal PLATFORM_FEE_PERCENT; + IERC20 internal TOKEN; + bool internal s_feesDisbursed; + + struct PaymentInfo { + address buyerAddress; + bytes32 itemId; + uint256 amount; + uint256 expiration; + bool isConfirmed; + } + + mapping (bytes32 => PaymentInfo) internal s_payment; + uint256 internal s_pendingPaymentAmount; + uint256 internal s_confirmedPaymentAmount; + uint256 internal s_availableConfirmedPaymentAmount; + + /** + * @dev Emitted when a new payment is created. + * @param paymentId The unique identifier of the payment. + * @param buyerAddress The address of the buyer who initiated the payment. + * @param itemId The identifier of the item being purchased. + * @param amount The amount to be paid for the item. + * @param expiration The timestamp after which the payment expires. + */ + event PaymentCreated( + bytes32 indexed paymentId, + address indexed buyerAddress, + bytes32 indexed itemId, + uint256 amount, + uint256 expiration + ); + + /** + * @dev Emitted when a payment is cancelled and removed from the treasury. + * @param paymentId The unique identifier of the cancelled payment. + */ + event PaymentCancelled( + bytes32 indexed paymentId + ); + + /** + * @dev Emitted when a payment is confirmed. + * @param paymentId The unique identifier of the cancelled payment. + */ + event PaymentConfirmed( + bytes32 indexed paymentId + ); + + /** + * @dev Emitted when multiple payments are confirmed in a single batch operation. + * @param paymentIds An array of unique identifiers for the confirmed payments. + */ + event PaymentBatchConfirmed( + bytes32[] paymentIds + ); + + /** + * @notice Emitted when fees are successfully disbursed. + * @param protocolShare The amount of fees sent to the protocol. + * @param platformShare The amount of fees sent to the platform. + */ + event FeesDisbursed(uint256 protocolShare, uint256 platformShare); + + /** + * @notice Emitted when a withdrawal is successful. + * @param to The recipient of the withdrawal. + * @param amount The amount withdrawn. + */ + event WithdrawalSuccessful(address indexed to, uint256 amount); + + /** + * @dev Emitted when a refund is claimed. + * @param paymentId The unique identifier of the cancelled payment. + * @param refundAmount The refund amount claimed. + * @param claimer The address of the claimer. + */ + event RefundClaimed(bytes32 indexed paymentId, uint256 refundAmount, address indexed claimer); + + /** + * @dev Reverts when one or more provided inputs to the payment treasury are invalid. + */ + error PaymentTreasuryInvalidInput(); + + /** + * @dev Throws an error indicating that the payment id is already exist. + */ + error PaymentTreasuryPaymentAlreadyExist(bytes32 paymentId); + + /** + * @dev Throws an error indicating that the payment id is already confirmed. + */ + error PaymentTreasuryPaymentAlreadyConfirmed(bytes32 paymentId); + + /** + * @dev Throws an error indicating that the payment id is already expired. + */ + error PaymentTreasuryPaymentAlreadyExpired(bytes32 paymentId); + + /** + * @dev Throws an error indicating that the payment id is not exist. + */ + error PaymentTreasuryPaymentNotExist(bytes32 paymentId); + + /** + * @dev Throws an error indicating that the campaign is paused. + */ + error PaymentTreasuryCampaignInfoIsPaused(); + + /** + * @dev Throws an error indicating that the success condition was not fulfilled. + */ + error PaymentTreasurySuccessConditionNotFulfilled(); + + /** + * @dev Throws an error indicating that fees have not been disbursed. + */ + error PaymentTreasuryFeeNotDisbursed(); + + /** + * @dev Throws an error indicating that the payment id is not confirmed. + */ + error PaymentTreasuryPaymentNotConfirmed(bytes32 paymentId); + + /** + * @dev Emitted when claiming an unclaimable refund. + * @param paymentId The unique identifier of the refundable payment. + */ + error PaymentTreasuryPaymentNotClaimable(bytes32 paymentId); + + /** + * @dev Emitted when an attempt is made to withdraw funds from the treasury but the payment has already been withdrawn. + */ + error PaymentTreasuryAlreadyWithdrawn(); + + function __BaseContract_init( + bytes32 platformHash, + address infoAddress + ) internal { + __CampaignAccessChecker_init(infoAddress); + PLATFORM_HASH = platformHash; + TOKEN = IERC20(INFO.getTokenAddress()); + PLATFORM_FEE_PERCENT = INFO.getPlatformFeePercent(platformHash); + } + + /** + * @dev Modifier that checks if the campaign is not paused. + */ + modifier whenCampaignNotPaused() { + _revertIfCampaignPaused(); + _; + } + + modifier whenCampaignNotCancelled() { + _revertIfCampaignCancelled(); + _; + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function getplatformHash() external view override returns (bytes32) { + return PLATFORM_HASH; + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function getplatformFeePercent() external view override returns (uint256) { + return PLATFORM_FEE_PERCENT; + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function getRaisedAmount() public view override virtual returns (uint256) { + return s_confirmedPaymentAmount; + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function getAvailableRaisedAmount() external view returns (uint256) { + return s_availableConfirmedPaymentAmount; + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function createPayment( + bytes32 paymentId, + address buyerAddress, + bytes32 itemId, + uint256 amount, + uint256 expiration + ) public override virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { + + if(buyerAddress == address(0) || + amount == 0 || + expiration <= block.timestamp || + paymentId == ZERO_BYTES || + itemId == ZERO_BYTES + ){ + revert PaymentTreasuryInvalidInput(); + } + + if(s_payment[paymentId].buyerAddress != address(0)){ + revert PaymentTreasuryPaymentAlreadyExist(paymentId); + } + + s_payment[paymentId] = PaymentInfo({ + buyerAddress: buyerAddress, + itemId: itemId, + amount: amount, + expiration: expiration, + isConfirmed: false + }); + + s_pendingPaymentAmount += amount; + + emit PaymentCreated( + paymentId, + buyerAddress, + itemId, + amount, + expiration + ); + + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function cancelPayment( + bytes32 paymentId + ) public override virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { + + _validatePaymentForAction(paymentId); + + uint256 amount = s_payment[paymentId].amount; + + delete s_payment[paymentId]; + + s_pendingPaymentAmount -= amount; + + emit PaymentCancelled(paymentId); + + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function confirmPayment( + bytes32 paymentId + ) public override virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { + + _validatePaymentForAction(paymentId); + + s_payment[paymentId].isConfirmed = true; + + uint256 amount = s_payment[paymentId].amount; + + s_pendingPaymentAmount -= amount; + s_confirmedPaymentAmount += amount; + s_availableConfirmedPaymentAmount += amount; + + emit PaymentConfirmed(paymentId); + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function confirmPaymentBatch( + bytes32[] calldata paymentIds + ) public override virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { + + for(uint256 i = 0; i < paymentIds.length; i++){ + _validatePaymentForAction(paymentIds[i]); + + s_payment[paymentIds[i]].isConfirmed = true; + + uint256 amount = s_payment[paymentIds[i]].amount; + + s_pendingPaymentAmount -= amount; + s_confirmedPaymentAmount += amount; + s_availableConfirmedPaymentAmount += amount; + } + + emit PaymentBatchConfirmed(paymentIds); + + } + + function claimRefund( + bytes32 paymentId, + address refundAddress + ) public override virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled + { + PaymentInfo memory payment = s_payment[paymentId]; + + if (payment.buyerAddress == address(0)) { + revert PaymentTreasuryPaymentNotExist(paymentId); + } + if(!payment.isConfirmed){ + revert PaymentTreasuryPaymentNotConfirmed(paymentId); + } + + uint256 amountToRefund = payment.amount; + if (amountToRefund == 0) { + revert PaymentTreasuryPaymentNotClaimable(paymentId); + } + + delete s_payment[paymentId]; + + s_confirmedPaymentAmount -= amountToRefund; + s_availableConfirmedPaymentAmount -= amountToRefund; + + TOKEN.safeTransfer(refundAddress, amountToRefund); + emit RefundClaimed(paymentId, amountToRefund, refundAddress); + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function disburseFees() + public + virtual + override + whenCampaignNotPaused + whenCampaignNotCancelled + { + if (!_checkSuccessCondition()) { + revert PaymentTreasurySuccessConditionNotFulfilled(); + } + uint256 balance = s_availableConfirmedPaymentAmount; + uint256 protocolShare = (balance * INFO.getProtocolFeePercent()) / + PERCENT_DIVIDER; + uint256 platformShare = (balance * + INFO.getPlatformFeePercent(PLATFORM_HASH)) / PERCENT_DIVIDER; + + s_availableConfirmedPaymentAmount -= protocolShare; + s_availableConfirmedPaymentAmount -= platformShare; + + TOKEN.safeTransfer(INFO.getProtocolAdminAddress(), protocolShare); + + TOKEN.safeTransfer( + INFO.getPlatformAdminAddress(PLATFORM_HASH), + platformShare + ); + + s_feesDisbursed = true; + emit FeesDisbursed(protocolShare, platformShare); + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function withdraw() + public + virtual + override + whenCampaignNotPaused + whenCampaignNotCancelled + { + if (!s_feesDisbursed) { + revert PaymentTreasuryFeeNotDisbursed(); + } + uint256 balance = s_availableConfirmedPaymentAmount; + if (balance == 0) { + revert PaymentTreasuryAlreadyWithdrawn(); + } + + address recipient = INFO.owner(); + s_availableConfirmedPaymentAmount = 0; + + TOKEN.safeTransfer(recipient, balance); + + emit WithdrawalSuccessful(recipient, balance); + } + + /** + * @dev External function to pause the campaign. + */ + function pauseTreasury( + bytes32 message + ) public virtual onlyPlatformAdmin(PLATFORM_HASH) { + _pause(message); + } + + /** + * @dev External function to unpause the campaign. + */ + function unpauseTreasury( + bytes32 message + ) public virtual onlyPlatformAdmin(PLATFORM_HASH) { + _unpause(message); + } + + /** + * @dev External function to cancel the campaign. + */ + function cancelTreasury( + bytes32 message + ) public virtual onlyPlatformAdmin(PLATFORM_HASH) { + _cancel(message); + } + + /** + * @dev Internal function to check if the campaign is paused. + * If the campaign is paused, it reverts with TreasuryCampaignInfoIsPaused error. + */ + function _revertIfCampaignPaused() internal view { + if (INFO.paused()) { + revert PaymentTreasuryCampaignInfoIsPaused(); + } + } + + function _revertIfCampaignCancelled() internal view { + if (INFO.cancelled()) { + revert PaymentTreasuryCampaignInfoIsPaused(); + } + } + + /** + * @dev Validates the given payment ID to ensure it is eligible for further action. + * Reverts if: + * - The payment does not exist. + * - The payment has already been confirmed. + * - The payment has already expired. + * @param paymentId The unique identifier of the payment to validate. + */ + function _validatePaymentForAction(bytes32 paymentId) internal view { + PaymentInfo memory payment = s_payment[paymentId]; + + if (payment.buyerAddress == address(0)) { + revert PaymentTreasuryPaymentNotExist(paymentId); + } + + if (payment.isConfirmed) { + revert PaymentTreasuryPaymentAlreadyConfirmed(paymentId); + } + + if (payment.expiration <= block.timestamp) { + revert PaymentTreasuryPaymentAlreadyExpired(paymentId); + } + } + + /** + * @dev Internal function to check the success condition for fee disbursement. + * @return Whether the success condition is met. + */ + function _checkSuccessCondition() internal view virtual returns (bool); + +} \ No newline at end of file diff --git a/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol b/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol new file mode 100644 index 00000000..8f6d8f79 --- /dev/null +++ b/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol @@ -0,0 +1,290 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.20; + +import {Base_Test} from "../../Base.t.sol"; +import "forge-std/Vm.sol"; +import "forge-std/console.sol"; +import {PaymentTreasury} from "src/treasuries/PaymentTreasury.sol"; +import {CampaignInfo} from "src/CampaignInfo.sol"; +import {ICampaignPaymentTreasury} from "src/interfaces/ICampaignPaymentTreasury.sol"; +import {LogDecoder} from "../../utils/LogDecoder.sol"; + +/// @notice Common testing logic needed by all PaymentTreasury integration tests. +abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Test { + address campaignAddress; + address treasuryAddress; + PaymentTreasury internal paymentTreasury; + + // Payment test data + bytes32 internal constant PAYMENT_ID_1 = keccak256("payment1"); + bytes32 internal constant PAYMENT_ID_2 = keccak256("payment2"); + bytes32 internal constant PAYMENT_ID_3 = keccak256("payment3"); + bytes32 internal constant ITEM_ID_1 = keccak256("item1"); + bytes32 internal constant ITEM_ID_2 = keccak256("item2"); + uint256 internal constant PAYMENT_AMOUNT_1 = 1000e18; + uint256 internal constant PAYMENT_AMOUNT_2 = 2000e18; + uint256 internal constant PAYMENT_EXPIRATION = 7 days; + + /// @dev Initial dependent functions setup included for PaymentTreasury Integration Tests. + function setUp() public virtual override { + super.setUp(); + console.log("setUp: enlistPlatform"); + + // Enlist Platform + enlistPlatform(PLATFORM_1_HASH); + console.log("enlisted platform"); + + registerTreasuryImplementation(PLATFORM_1_HASH); + console.log("registered treasury"); + + approveTreasuryImplementation(PLATFORM_1_HASH); + console.log("approved treasury"); + + // Create Campaign + createCampaign(PLATFORM_1_HASH); + console.log("created campaign"); + + // Deploy Treasury Contract + deploy(PLATFORM_1_HASH); + console.log("deployed treasury"); + } + + /** + * @notice Implements enlistPlatform helper function. + * @param platformHash The platform bytes. + */ + function enlistPlatform(bytes32 platformHash) internal { + vm.startPrank(users.protocolAdminAddress); + globalParams.enlistPlatform(platformHash, users.platform1AdminAddress, PLATFORM_FEE_PERCENT); + vm.stopPrank(); + } + + function registerTreasuryImplementation(bytes32 platformHash) internal { + PaymentTreasury implementation = new PaymentTreasury(); + vm.startPrank(users.platform1AdminAddress); + treasuryFactory.registerTreasuryImplementation(platformHash, 2, address(implementation)); + vm.stopPrank(); + } + + function approveTreasuryImplementation(bytes32 platformHash) internal { + vm.startPrank(users.protocolAdminAddress); + treasuryFactory.approveTreasuryImplementation(platformHash, 2); + vm.stopPrank(); + } + + /** + * @notice Implements createCampaign helper function. It creates new campaign info contract + * @param platformHash The platform bytes. + */ + function createCampaign(bytes32 platformHash) internal { + bytes32 identifierHash = keccak256(abi.encodePacked(platformHash)); + bytes32[] memory selectedPlatformHash = new bytes32[](1); + selectedPlatformHash[0] = platformHash; + + bytes32[] memory platformDataKey = new bytes32[](0); + bytes32[] memory platformDataValue = new bytes32[](0); + + vm.startPrank(users.creator1Address); + vm.recordLogs(); + + campaignInfoFactory.createCampaign( + users.creator1Address, + identifierHash, + selectedPlatformHash, + platformDataKey, + platformDataValue, + CAMPAIGN_DATA + ); + + Vm.Log[] memory entries = vm.getRecordedLogs(); + vm.stopPrank(); + + (bytes32[] memory topics,) = decodeTopicsAndData( + entries, "CampaignInfoFactoryCampaignCreated(bytes32,address)", address(campaignInfoFactory) + ); + + require(topics.length == 3, "Unexpected topic length for event"); + + campaignAddress = address(uint160(uint256(topics[2]))); + } + + /** + * @notice Implements deploy helper function. It deploys treasury contract. + */ + function deploy(bytes32 platformHash) internal { + vm.startPrank(users.platform1AdminAddress); + vm.recordLogs(); + + // Deploy the treasury contract with implementation ID 2 for PaymentTreasury + treasuryFactory.deploy(platformHash, campaignAddress, 2, NAME, SYMBOL); + + Vm.Log[] memory entries = vm.getRecordedLogs(); + vm.stopPrank(); + + (bytes32[] memory topics, bytes memory data) = decodeTopicsAndData( + entries, "TreasuryFactoryTreasuryDeployed(bytes32,uint256,address,address)", address(treasuryFactory) + ); + + require(topics.length >= 3, "Expected indexed params missing"); + + treasuryAddress = abi.decode(data, (address)); + paymentTreasury = PaymentTreasury(treasuryAddress); + } + + /** + * @notice Creates a payment + */ + function createPayment( + address caller, + bytes32 paymentId, + address buyerAddress, + bytes32 itemId, + uint256 amount, + uint256 expiration + ) internal { + vm.prank(caller); + paymentTreasury.createPayment(paymentId, buyerAddress, itemId, amount, expiration); + } + + /** + * @notice Cancels a payment + */ + function cancelPayment(address caller, bytes32 paymentId) internal { + vm.prank(caller); + paymentTreasury.cancelPayment(paymentId); + } + + /** + * @notice Confirms a payment + */ + function confirmPayment(address caller, bytes32 paymentId) internal { + vm.prank(caller); + paymentTreasury.confirmPayment(paymentId); + } + + /** + * @notice Confirms multiple payments in batch + */ + function confirmPaymentBatch(address caller, bytes32[] memory paymentIds) internal { + vm.prank(caller); + paymentTreasury.confirmPaymentBatch(paymentIds); + } + + /** + * @notice Claims a refund + */ + function claimRefund(address caller, bytes32 paymentId, address refundAddress) + internal + returns (uint256 refundAmount) + { + vm.startPrank(caller); + vm.recordLogs(); + + paymentTreasury.claimRefund(paymentId, refundAddress); + + Vm.Log[] memory logs = vm.getRecordedLogs(); + + (bytes32[] memory topics, bytes memory data) = decodeTopicsAndData( + logs, "RefundClaimed(bytes32,uint256,address)", treasuryAddress + ); + + refundAmount = abi.decode(data, (uint256)); + + vm.stopPrank(); + } + + /** + * @notice Disburses fees + */ + function disburseFees(address treasury) + internal + returns (uint256 protocolShare, uint256 platformShare) + { + vm.recordLogs(); + + PaymentTreasury(treasury).disburseFees(); + + Vm.Log[] memory logs = vm.getRecordedLogs(); + + bytes memory data = decodeEventFromLogs(logs, "FeesDisbursed(uint256,uint256)", treasury); + + (protocolShare, platformShare) = abi.decode(data, (uint256, uint256)); + } + + /** + * @notice Withdraws funds + */ + function withdraw(address treasury) + internal + returns (address to, uint256 amount) + { + vm.recordLogs(); + + PaymentTreasury(treasury).withdraw(); + + Vm.Log[] memory logs = vm.getRecordedLogs(); + + (bytes32[] memory topics, bytes memory data) = + decodeTopicsAndData(logs, "WithdrawalSuccessful(address,uint256)", treasury); + + to = address(uint160(uint256(topics[1]))); + amount = abi.decode(data, (uint256)); + } + + /** + * @notice Pauses the treasury + */ + function pauseTreasury(address caller, address treasury, bytes32 message) internal { + vm.prank(caller); + PaymentTreasury(treasury).pauseTreasury(message); + } + + /** + * @notice Unpauses the treasury + */ + function unpauseTreasury(address caller, address treasury, bytes32 message) internal { + vm.prank(caller); + PaymentTreasury(treasury).unpauseTreasury(message); + } + + /** + * @notice Cancels the treasury + */ + function cancelTreasury(address caller, address treasury, bytes32 message) internal { + vm.prank(caller); + PaymentTreasury(treasury).cancelTreasury(message); + } + + /** + * @notice Helper to create and fund a payment from buyer + */ + function _createAndFundPayment( + bytes32 paymentId, + address buyerAddress, + bytes32 itemId, + uint256 amount + ) internal { + // Fund buyer + deal(address(testToken), buyerAddress, amount); + + // Buyer approves treasury + vm.prank(buyerAddress); + testToken.approve(treasuryAddress, amount); + + // Create payment + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + createPayment(users.platform1AdminAddress, paymentId, buyerAddress, itemId, amount, expiration); + + // Transfer tokens from buyer to treasury + vm.prank(buyerAddress); + testToken.transfer(treasuryAddress, amount); + } + + /** + * @notice Helper to create multiple test payments + */ + function _createTestPayments() internal { + _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + _createAndFundPayment(PAYMENT_ID_2, users.backer2Address, ITEM_ID_2, PAYMENT_AMOUNT_2); + } +} \ No newline at end of file diff --git a/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol b/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol new file mode 100644 index 00000000..ce193e9a --- /dev/null +++ b/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol @@ -0,0 +1,172 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.20; + +import "./PaymentTreasury.t.sol"; +import "forge-std/console.sol"; +import "forge-std/Vm.sol"; +import "forge-std/Test.sol"; +import {CampaignInfo} from "src/CampaignInfo.sol"; +import {PaymentTreasury} from "src/treasuries/PaymentTreasury.sol"; + +/** + * @title PaymentTreasuryFunction_Integration_Test + * @notice This contract contains integration tests for the happy-path functionality + * of the PaymentTreasury contract. Each test focuses on a single core function. + */ +contract PaymentTreasuryFunction_Integration_Test is + PaymentTreasury_Integration_Shared_Test +{ + /** + * @notice Tests the successful confirmation of a single payment. + */ + function test_confirmPayment() public { + _createAndFundPayment( + PAYMENT_ID_1, + users.backer1Address, + ITEM_ID_1, + PAYMENT_AMOUNT_1 + ); + assertEq(testToken.balanceOf(treasuryAddress), PAYMENT_AMOUNT_1); + + confirmPayment(users.platform1AdminAddress, PAYMENT_ID_1); + + assertEq( + paymentTreasury.getRaisedAmount(), + PAYMENT_AMOUNT_1, + "Raised amount should match the payment amount" + ); + assertEq( + paymentTreasury.getAvailableRaisedAmount(), + PAYMENT_AMOUNT_1, + "Available raised amount should match the payment amount" + ); + } + + /** + * @notice Tests the successful confirmation of multiple payments in a batch. + */ + function test_confirmPaymentBatch() public { + _createTestPayments(); // Creates PAYMENT_ID_1 and PAYMENT_ID_2 + uint256 totalAmount = PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2; + assertEq(testToken.balanceOf(treasuryAddress), totalAmount); + + bytes32[] memory paymentIds = new bytes32[](2); + paymentIds[0] = PAYMENT_ID_1; + paymentIds[1] = PAYMENT_ID_2; + confirmPaymentBatch(users.platform1AdminAddress, paymentIds); + + assertEq( + paymentTreasury.getRaisedAmount(), + totalAmount, + "Raised amount should match the total of batched payments" + ); + assertEq( + paymentTreasury.getAvailableRaisedAmount(), + totalAmount, + "Available raised amount should match the total of batched payments" + ); + } + + /** + * @notice Tests that a confirmed payment can be successfully refunded. + */ + function test_claimRefund() public { + _createAndFundPayment( + PAYMENT_ID_1, + users.backer1Address, + ITEM_ID_1, + PAYMENT_AMOUNT_1 + ); + confirmPayment(users.platform1AdminAddress, PAYMENT_ID_1); + uint256 backerBalanceBefore = testToken.balanceOf(users.backer1Address); + + uint256 refundAmount = claimRefund( + users.platform1AdminAddress, + PAYMENT_ID_1, + users.backer1Address + ); + + // Assert: The refund amount is correct and all balances are updated as expected. + assertEq(refundAmount, PAYMENT_AMOUNT_1, "Refunded amount is incorrect"); + assertEq( + testToken.balanceOf(users.backer1Address), + backerBalanceBefore + PAYMENT_AMOUNT_1, + "Backer did not receive the correct refund amount" + ); + assertEq(paymentTreasury.getRaisedAmount(), 0, "Raised amount should be zero after refund"); + assertEq(paymentTreasury.getAvailableRaisedAmount(), 0, "Available amount should be zero after refund"); + assertEq(testToken.balanceOf(treasuryAddress), 0, "Treasury token balance should be zero after refund"); + } + + /** + * @notice Tests the correct disbursement of fees to the protocol and platform. + */ + function test_disburseFees() public { + _createTestPayments(); + uint256 totalAmount = PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2; + bytes32[] memory paymentIds = new bytes32[](2); + paymentIds[0] = PAYMENT_ID_1; + paymentIds[1] = PAYMENT_ID_2; + confirmPaymentBatch(users.platform1AdminAddress, paymentIds); + + uint256 protocolAdminBalanceBefore = testToken.balanceOf(users.protocolAdminAddress); + uint256 platformAdminBalanceBefore = testToken.balanceOf(users.platform1AdminAddress); + uint256 treasuryAvailableAmountBefore = paymentTreasury.getAvailableRaisedAmount(); + + (uint256 protocolShare, uint256 platformShare) = disburseFees(treasuryAddress); + + // Assert: Fees are calculated and transferred correctly. + uint256 expectedProtocolShare = (totalAmount * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 expectedPlatformShare = (totalAmount * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; + + assertEq(protocolShare, expectedProtocolShare, "Incorrect protocol fee disbursed"); + assertEq(platformShare, expectedPlatformShare, "Incorrect platform fee disbursed"); + + assertEq( + testToken.balanceOf(users.protocolAdminAddress), + protocolAdminBalanceBefore + expectedProtocolShare, + "Protocol admin did not receive correct fee amount" + ); + assertEq( + testToken.balanceOf(users.platform1AdminAddress), + platformAdminBalanceBefore + expectedPlatformShare, + "Platform admin did not receive correct fee amount" + ); + assertEq( + paymentTreasury.getAvailableRaisedAmount(), + treasuryAvailableAmountBefore - protocolShare - platformShare, + "Treasury available amount not reduced correctly after disbursing fees" + ); + } + + /** + * @notice Tests the final withdrawal of funds by the campaign owner after fees have been disbursed. + */ + function test_withdraw() public { + _createTestPayments(); + uint256 totalAmount = PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2; + bytes32[] memory paymentIds = new bytes32[](2); + paymentIds[0] = PAYMENT_ID_1; + paymentIds[1] = PAYMENT_ID_2; + confirmPaymentBatch(users.platform1AdminAddress, paymentIds); + (uint256 protocolShare, uint256 platformShare) = disburseFees(treasuryAddress); + + address campaignOwner = CampaignInfo(campaignAddress).owner(); + uint256 ownerBalanceBefore = testToken.balanceOf(campaignOwner); + + (address recipient, uint256 withdrawnAmount) = withdraw(treasuryAddress); + uint256 ownerBalanceAfter = testToken.balanceOf(campaignOwner); + + // Check that the correct amount is withdrawn to the campaign owner's address. + uint256 expectedWithdrawalAmount = totalAmount - protocolShare - platformShare; + assertEq(recipient, campaignOwner, "Funds withdrawn to incorrect address"); + assertEq(withdrawnAmount, expectedWithdrawalAmount, "Incorrect amount withdrawn"); + assertEq( + ownerBalanceAfter - ownerBalanceBefore, + expectedWithdrawalAmount, + "Campaign owner did not receive correct withdrawn amount" + ); + assertEq(paymentTreasury.getAvailableRaisedAmount(), 0, "Available amount should be zero after withdrawal"); + assertEq(testToken.balanceOf(treasuryAddress), 0, "Treasury token balance should be zero after withdrawal"); + } +} diff --git a/test/foundry/unit/PaymentTreasury.t.sol b/test/foundry/unit/PaymentTreasury.t.sol new file mode 100644 index 00000000..cb585cbc --- /dev/null +++ b/test/foundry/unit/PaymentTreasury.t.sol @@ -0,0 +1,689 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.20; + +import "../integration/PaymentTreasury/PaymentTreasury.t.sol"; +import "forge-std/Test.sol"; +import {PaymentTreasury} from "src/treasuries/PaymentTreasury.sol"; +import {CampaignInfo} from "src/CampaignInfo.sol"; + +contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Test { + + function setUp() public virtual override { + super.setUp(); + // Fund test addresses + deal(address(testToken), users.backer1Address, 10_000e18); + deal(address(testToken), users.backer2Address, 10_000e18); + // Label addresses + vm.label(users.protocolAdminAddress, "ProtocolAdmin"); + vm.label(users.platform1AdminAddress, "PlatformAdmin"); + vm.label(users.creator1Address, "CampaignOwner"); + vm.label(users.backer1Address, "Backer1"); + vm.label(users.backer2Address, "Backer2"); + vm.label(address(paymentTreasury), "PaymentTreasury"); + } + + /*////////////////////////////////////////////////////////////// + INITIALIZATION + //////////////////////////////////////////////////////////////*/ + + function testInitialize() public { + // Create a new campaign for this test + bytes32 newIdentifierHash = keccak256(abi.encodePacked("newPaymentCampaign")); + bytes32[] memory selectedPlatformHash = new bytes32[](1); + selectedPlatformHash[0] = PLATFORM_1_HASH; + + bytes32[] memory platformDataKey = new bytes32[](0); + bytes32[] memory platformDataValue = new bytes32[](0); + + vm.prank(users.creator1Address); + campaignInfoFactory.createCampaign( + users.creator1Address, + newIdentifierHash, + selectedPlatformHash, + platformDataKey, + platformDataValue, + CAMPAIGN_DATA + ); + address newCampaignAddress = campaignInfoFactory.identifierToCampaignInfo(newIdentifierHash); + + // Deploy a new treasury + vm.prank(users.platform1AdminAddress); + address newTreasury = treasuryFactory.deploy( + PLATFORM_1_HASH, + newCampaignAddress, + 2, + "NewPaymentTreasury", + "NPT" + ); + PaymentTreasury newContract = PaymentTreasury(newTreasury); + + assertEq(newContract.name(), "NewPaymentTreasury"); + assertEq(newContract.symbol(), "NPT"); + assertEq(newContract.getplatformHash(), PLATFORM_1_HASH); + assertEq(newContract.getplatformFeePercent(), PLATFORM_FEE_PERCENT); + } + + /*////////////////////////////////////////////////////////////// + PAYMENT CREATION + //////////////////////////////////////////////////////////////*/ + + function testCreatePayment() public { + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + users.backer1Address, + ITEM_ID_1, + PAYMENT_AMOUNT_1, + expiration + ); + // Payment created but not confirmed + assertEq(paymentTreasury.getRaisedAmount(), 0); + assertEq(paymentTreasury.getAvailableRaisedAmount(), 0); + } + + function testCreatePaymentRevertWhenNotPlatformAdmin() public { + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.expectRevert(); + vm.prank(users.backer1Address); + paymentTreasury.createPayment( + PAYMENT_ID_1, + users.backer1Address, + ITEM_ID_1, + PAYMENT_AMOUNT_1, + expiration + ); + } + + function testCreatePaymentRevertWhenZeroBuyerAddress() public { + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + address(0), + ITEM_ID_1, + PAYMENT_AMOUNT_1, + expiration + ); + } + + function testCreatePaymentRevertWhenZeroAmount() public { + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + users.backer1Address, + ITEM_ID_1, + 0, + expiration + ); + } + + function testCreatePaymentRevertWhenExpired() public { + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + users.backer1Address, + ITEM_ID_1, + PAYMENT_AMOUNT_1, + block.timestamp - 1 + ); + } + + function testCreatePaymentRevertWhenZeroPaymentId() public { + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + bytes32(0), + users.backer1Address, + ITEM_ID_1, + PAYMENT_AMOUNT_1, + expiration + ); + } + + function testCreatePaymentRevertWhenZeroItemId() public { + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + users.backer1Address, + bytes32(0), + PAYMENT_AMOUNT_1, + expiration + ); + } + + function testCreatePaymentRevertWhenPaymentExists() public { + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.startPrank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + users.backer1Address, + ITEM_ID_1, + PAYMENT_AMOUNT_1, + expiration + ); + vm.expectRevert(); + paymentTreasury.createPayment( + PAYMENT_ID_1, + users.backer2Address, + ITEM_ID_2, + PAYMENT_AMOUNT_2, + expiration + ); + vm.stopPrank(); + } + + function testCreatePaymentRevertWhenPaused() public { + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + // Pause the treasury - but this won't affect createPayment + vm.prank(users.platform1AdminAddress); + paymentTreasury.pauseTreasury(keccak256("Pause")); + + // createPayment checks campaign pause, not treasury pause + CampaignInfo actualCampaignInfo = CampaignInfo(campaignAddress); + vm.prank(users.protocolAdminAddress); + actualCampaignInfo._pauseCampaign(keccak256("Pause")); + + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + users.backer1Address, + ITEM_ID_1, + PAYMENT_AMOUNT_1, + expiration + ); + } + + function testCreatePaymentRevertWhenCampaignPaused() public { + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + // Pause the campaign + CampaignInfo actualCampaignInfo = CampaignInfo(campaignAddress); + vm.prank(users.protocolAdminAddress); + actualCampaignInfo._pauseCampaign(keccak256("Pause")); + + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + users.backer1Address, + ITEM_ID_1, + PAYMENT_AMOUNT_1, + expiration + ); + } + + /*////////////////////////////////////////////////////////////// + PAYMENT CANCELLATION + //////////////////////////////////////////////////////////////*/ + + function testCancelPayment() public { + // Create payment first + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + users.backer1Address, + ITEM_ID_1, + PAYMENT_AMOUNT_1, + expiration + ); + // Cancel it + vm.prank(users.platform1AdminAddress); + paymentTreasury.cancelPayment(PAYMENT_ID_1); + // Payment should be deleted + assertEq(paymentTreasury.getRaisedAmount(), 0); + } + + function testCancelPaymentRevertWhenNotExists() public { + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.cancelPayment(PAYMENT_ID_1); + } + + function testCancelPaymentRevertWhenAlreadyConfirmed() public { + _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.cancelPayment(PAYMENT_ID_1); + } + + function testCancelPaymentRevertWhenExpired() public { + uint256 expiration = block.timestamp + 1 hours; + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + users.backer1Address, + ITEM_ID_1, + PAYMENT_AMOUNT_1, + expiration + ); + // Warp past expiration + vm.warp(expiration + 1); + + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.cancelPayment(PAYMENT_ID_1); + } + + /*////////////////////////////////////////////////////////////// + PAYMENT CONFIRMATION + //////////////////////////////////////////////////////////////*/ + + function testConfirmPayment() public { + _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + + assertEq(paymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1); + assertEq(paymentTreasury.getAvailableRaisedAmount(), PAYMENT_AMOUNT_1); + } + + function testConfirmPaymentBatch() public { + _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + _createAndFundPayment(PAYMENT_ID_2, users.backer2Address, ITEM_ID_2, PAYMENT_AMOUNT_2); + _createAndFundPayment(PAYMENT_ID_3, users.backer1Address, ITEM_ID_1, 500e18); + + bytes32[] memory paymentIds = new bytes32[](3); + paymentIds[0] = PAYMENT_ID_1; + paymentIds[1] = PAYMENT_ID_2; + paymentIds[2] = PAYMENT_ID_3; + + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPaymentBatch(paymentIds); + + uint256 totalAmount = PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2 + 500e18; + assertEq(paymentTreasury.getRaisedAmount(), totalAmount); + assertEq(paymentTreasury.getAvailableRaisedAmount(), totalAmount); + } + + function testConfirmPaymentRevertWhenNotExists() public { + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + } + + function testConfirmPaymentRevertWhenAlreadyConfirmed() public { + _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + vm.startPrank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + + vm.expectRevert(); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + vm.stopPrank(); + } + + /*////////////////////////////////////////////////////////////// + REFUNDS + //////////////////////////////////////////////////////////////*/ + + function testClaimRefund() public { + _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + + uint256 balanceBefore = testToken.balanceOf(users.backer1Address); + + vm.prank(users.platform1AdminAddress); + paymentTreasury.claimRefund(PAYMENT_ID_1, users.backer1Address); + + uint256 balanceAfter = testToken.balanceOf(users.backer1Address); + + assertEq(balanceAfter - balanceBefore, PAYMENT_AMOUNT_1); + assertEq(paymentTreasury.getRaisedAmount(), 0); + assertEq(paymentTreasury.getAvailableRaisedAmount(), 0); + } + + function testClaimRefundRevertWhenNotConfirmed() public { + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + users.backer1Address, + ITEM_ID_1, + PAYMENT_AMOUNT_1, + expiration + ); + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.claimRefund(PAYMENT_ID_1, users.backer1Address); + } + + function testClaimRefundRevertWhenNotExists() public { + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.claimRefund(PAYMENT_ID_1, users.backer1Address); + } + + function testClaimRefundRevertWhenPaused() public { + _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + + // Pause treasury + vm.prank(users.platform1AdminAddress); + paymentTreasury.pauseTreasury(keccak256("Pause")); + + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.claimRefund(PAYMENT_ID_1, users.backer1Address); + } + + /*////////////////////////////////////////////////////////////// + FEE DISBURSEMENT + //////////////////////////////////////////////////////////////*/ + + function testDisburseFees() public { + _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + + uint256 protocolBalanceBefore = testToken.balanceOf(users.protocolAdminAddress); + uint256 platformBalanceBefore = testToken.balanceOf(users.platform1AdminAddress); + + paymentTreasury.disburseFees(); + + uint256 protocolBalanceAfter = testToken.balanceOf(users.protocolAdminAddress); + uint256 platformBalanceAfter = testToken.balanceOf(users.platform1AdminAddress); + assertTrue(protocolBalanceAfter > protocolBalanceBefore); + assertTrue(platformBalanceAfter > platformBalanceBefore); + } + + function testDisburseFeesRevertWhenAlreadyDisbursed() public { + _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + + paymentTreasury.disburseFees(); + + vm.expectRevert(); + paymentTreasury.disburseFees(); + } + + function testDisburseFeesRevertWhenPaused() public { + _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + + // Pause treasury + vm.prank(users.platform1AdminAddress); + paymentTreasury.pauseTreasury(keccak256("Pause")); + + vm.expectRevert(); + paymentTreasury.disburseFees(); + } + + /*////////////////////////////////////////////////////////////// + WITHDRAWALS + //////////////////////////////////////////////////////////////*/ + + function testWithdraw() public { + _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + + paymentTreasury.disburseFees(); + + address owner = CampaignInfo(campaignAddress).owner(); + uint256 ownerBalanceBefore = testToken.balanceOf(owner); + uint256 availableAmount = paymentTreasury.getAvailableRaisedAmount(); + + paymentTreasury.withdraw(); + + uint256 ownerBalanceAfter = testToken.balanceOf(owner); + assertEq(ownerBalanceAfter - ownerBalanceBefore, availableAmount); + assertEq(paymentTreasury.getAvailableRaisedAmount(), 0); + } + + function testWithdrawRevertWhenFeesNotDisbursed() public { + _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + + vm.expectRevert(); + paymentTreasury.withdraw(); + } + + function testWithdrawRevertWhenAlreadyWithdrawn() public { + _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + + paymentTreasury.disburseFees(); + paymentTreasury.withdraw(); + + vm.expectRevert(); + paymentTreasury.withdraw(); + } + + function testWithdrawRevertWhenPaused() public { + _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.disburseFees(); + + // Pause treasury + vm.prank(users.platform1AdminAddress); + paymentTreasury.pauseTreasury(keccak256("Pause")); + + vm.expectRevert(); + paymentTreasury.withdraw(); + } + + /*////////////////////////////////////////////////////////////// + PAUSE AND CANCEL + //////////////////////////////////////////////////////////////*/ + + function testPauseTreasury() public { + // First create and confirm a payment to test functions that require it + _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + + // Pause the treasury + vm.prank(users.platform1AdminAddress); + paymentTreasury.pauseTreasury(keccak256("Pause")); + // Functions that check treasury pause status should revert + // claimRefund uses whenNotPaused + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.claimRefund(PAYMENT_ID_1, users.backer1Address); + + // disburseFees uses whenNotPaused + vm.expectRevert(); + paymentTreasury.disburseFees(); + + // createPayment checks campaign pause, not treasury pause + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_2, + users.backer2Address, + ITEM_ID_2, + PAYMENT_AMOUNT_2, + expiration + ); + } + + function testUnpauseTreasury() public { + vm.prank(users.platform1AdminAddress); + paymentTreasury.pauseTreasury(keccak256("Pause")); + + vm.prank(users.platform1AdminAddress); + paymentTreasury.unpauseTreasury(keccak256("Unpause")); + + // Should be able to create payment + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + users.backer1Address, + ITEM_ID_1, + PAYMENT_AMOUNT_1, + expiration + ); + } + + function testCancelTreasuryByPlatformAdmin() public { + _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + + vm.prank(users.platform1AdminAddress); + paymentTreasury.cancelTreasury(keccak256("Cancel")); + + vm.expectRevert(); + paymentTreasury.disburseFees(); + + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_2, + users.backer2Address, + ITEM_ID_2, + PAYMENT_AMOUNT_2, + expiration + ); + } + + function testCancelTreasuryByCampaignOwner() public { + _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + + address owner = CampaignInfo(campaignAddress).owner(); + vm.prank(owner); + paymentTreasury.cancelTreasury(keccak256("Cancel")); + + vm.expectRevert(); + paymentTreasury.disburseFees(); + + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_2, + users.backer2Address, + ITEM_ID_2, + PAYMENT_AMOUNT_2, + expiration + ); + } + + function testCancelTreasuryRevertWhenUnauthorized() public { + vm.expectRevert(); + vm.prank(users.backer1Address); + paymentTreasury.cancelTreasury(keccak256("Cancel")); + } + + /*////////////////////////////////////////////////////////////// + EDGE CASES + //////////////////////////////////////////////////////////////*/ + + function testMultipleRefundsAfterBatchConfirm() public { + // Create multiple payments + _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + _createAndFundPayment(PAYMENT_ID_2, users.backer2Address, ITEM_ID_2, PAYMENT_AMOUNT_2); + _createAndFundPayment(PAYMENT_ID_3, users.backer1Address, ITEM_ID_1, 500e18); + + // Confirm all in batch + bytes32[] memory paymentIds = new bytes32[](3); + paymentIds[0] = PAYMENT_ID_1; + paymentIds[1] = PAYMENT_ID_2; + paymentIds[2] = PAYMENT_ID_3; + + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPaymentBatch(paymentIds); + + uint256 totalAmount = PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2 + 500e18; + assertEq(paymentTreasury.getRaisedAmount(), totalAmount); + + // Refund payments one by one + vm.startPrank(users.platform1AdminAddress); + paymentTreasury.claimRefund(PAYMENT_ID_1, users.backer1Address); + assertEq(paymentTreasury.getRaisedAmount(), totalAmount - PAYMENT_AMOUNT_1); + + paymentTreasury.claimRefund(PAYMENT_ID_2, users.backer2Address); + assertEq(paymentTreasury.getRaisedAmount(), totalAmount - PAYMENT_AMOUNT_1 - PAYMENT_AMOUNT_2); + + paymentTreasury.claimRefund(PAYMENT_ID_3, users.backer1Address); + assertEq(paymentTreasury.getRaisedAmount(), 0); + vm.stopPrank(); + } + + function testZeroBalanceAfterAllRefunds() public { + _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + _createAndFundPayment(PAYMENT_ID_2, users.backer2Address, ITEM_ID_2, PAYMENT_AMOUNT_2); + + vm.startPrank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_2); + + // Refund all payments + paymentTreasury.claimRefund(PAYMENT_ID_1, users.backer1Address); + paymentTreasury.claimRefund(PAYMENT_ID_2, users.backer2Address); + vm.stopPrank(); + + assertEq(paymentTreasury.getRaisedAmount(), 0); + assertEq(paymentTreasury.getAvailableRaisedAmount(), 0); + + // Disbursing fees with zero balance should succeed (transferring 0 amounts) + paymentTreasury.disburseFees(); + // But withdraw should revert because balance is 0 + vm.expectRevert(); + paymentTreasury.withdraw(); + } + + function testPaymentExpirationScenarios() public { + uint256 shortExpiration = block.timestamp + 1 hours; + uint256 longExpiration = block.timestamp + 7 days; + + // Create payments with different expirations + vm.startPrank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + users.backer1Address, + ITEM_ID_1, + PAYMENT_AMOUNT_1, + shortExpiration + ); + paymentTreasury.createPayment( + PAYMENT_ID_2, + users.backer2Address, + ITEM_ID_2, + PAYMENT_AMOUNT_2, + longExpiration + ); + vm.stopPrank(); + + // Fund both payments + vm.prank(users.backer1Address); + testToken.transfer(treasuryAddress, PAYMENT_AMOUNT_1); + + vm.prank(users.backer2Address); + testToken.transfer(treasuryAddress, PAYMENT_AMOUNT_2); + // Confirm first payment before expiration + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + // Warp past first expiration but before second + vm.warp(shortExpiration + 1); + // Cannot cancel or confirm expired payment + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.cancelPayment(PAYMENT_ID_1); + // Can still confirm non-expired payment + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_2); + + assertEq(paymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2); + } +} \ No newline at end of file From bc745fa65a82fa9593241391e295fb619197e332 Mon Sep 17 00:00:00 2001 From: mahabubAlahi <32974385+mahabubAlahi@users.noreply.github.com> Date: Fri, 8 Aug 2025 11:26:16 +0600 Subject: [PATCH 36/63] Immunefi audit fixes (#23) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix incorrect description of the `claimFund` function (#6) (immunefi)(issue#06) - Updated the NatSpec comment for claimFund() * Refactor `platformDataKey` parameter validation optimization (#7) (immunefi)(issue#09) - Move `platformDataKey` parameter validation to an earlier stage of the `createCampaign` flow * Add configuring platform data during `updateSelectedPlatform` (#8) (immunefi)(issue#10) * Add creator's non-zero validation during `createCampaign` (#9) (immunefi)(issue#16) * Add zero validation for `platformDataValue` in `createCampaign` (#10) (immunefi)(issue#12) * Add reward value zero validation in pledge (#11) (immunefi)(issue#14) * Fix `updateDeadline` allowing past deadline that blocks `claimRefund` (#12) (immunefi)(issue#05) - Added check to ensure new deadline is after current block timestamp * Fix blocking KeepWhatsRaised pledge functions via front-running (#13) (immunefi)(issue#04) - Add internal pledge ID generation using msg.sender and pledgeId * Add fee configuration via configure treasury (#14) (immunefi)(issue#11) - Update configure treasury to support fee values - Add getter function for fee value * Add campaign data validation in configure treasury (#15) (immunefi)(issue#20) - Update fee values js doc - Update custom error * Fix Gateway fee bypass (#16) (immunefi)(issue#19) - When `setFeeAndPledge` is called, tokens are transferred from the admin's wallet (msg.sender) - When `pledgeWithoutAReward` or `pledgeForAReward` is called directly, tokens are transferred from the backer's wallet * Add expected fee description in create campaign jsdoc (#17) (immunefi)(issue#03) * Refactor withdrawal and pledge calculation (#19) (immunefi)(issue#15) (immunefi)(issue#18) - Restrict access to the withdrawal function so that only the campaign owner and platform administrator can use it. - Move the protocol fee calculation from the withdrawal process to the pledge stage. - For withdrawals: - Partial Withdrawals: - Conditions: amount > 0 and amount + fees ≤ available balance. - The creator must specify the exact withdrawal amount, and the system will ensure there are sufficient funds to cover both the withdrawal and the fees. - Final Withdrawals: - Conditions: available balance > 0 and fees ≤ available balance. - The creator can withdraw the entire remaining balance. The system will check if there are enough funds to cover the fees and will then provide the remainder to the creator. --------- Co-authored-by: mahabubAlahi --- src/CampaignInfo.sol | 33 ++- src/CampaignInfoFactory.sol | 16 ++ src/interfaces/ICampaignInfo.sol | 6 +- src/interfaces/ICampaignInfoFactory.sol | 5 + src/treasuries/AllOrNothing.sol | 6 +- src/treasuries/KeepWhatsRaised.sol | 282 ++++++++++++++++++------ 6 files changed, 273 insertions(+), 75 deletions(-) diff --git a/src/CampaignInfo.sol b/src/CampaignInfo.sol index 9dc4e9af..9e50b8ba 100644 --- a/src/CampaignInfo.sol +++ b/src/CampaignInfo.sol @@ -134,14 +134,7 @@ contract CampaignInfo is s_isSelectedPlatform[selectedPlatformHash[i]] = true; } len = platformDataKey.length; - bool isValid; for (uint256 i = 0; i < len; ++i) { - isValid = GLOBAL_PARAMS.checkIfPlatformDataKeyValid( - platformDataKey[i] - ); - if (!isValid) { - revert CampaignInfoInvalidInput(); - } s_platformData[platformDataKey[i]] = platformDataValue[i]; } } @@ -398,7 +391,9 @@ contract CampaignInfo is */ function updateSelectedPlatform( bytes32 platformHash, - bool selection + bool selection, + bytes32[] calldata platformDataKey, + bytes32[] calldata platformDataValue ) external override @@ -417,6 +412,28 @@ contract CampaignInfo is if (!selection && checkIfPlatformApproved(platformHash)) { revert CampaignInfoPlatformAlreadyApproved(platformHash); } + + if (platformDataKey.length != platformDataValue.length) { + revert CampaignInfoInvalidInput(); + } + + if (selection) { + bool isValid; + for (uint256 i = 0; i < platformDataKey.length; i++) { + isValid = GLOBAL_PARAMS.checkIfPlatformDataKeyValid( + platformDataKey[i] + ); + if (!isValid) { + revert CampaignInfoInvalidInput(); + } + if (platformDataValue[i] == bytes32(0)) { + revert CampaignInfoInvalidInput(); + } + + s_platformData[platformDataKey[i]] = platformDataValue[i]; + } + } + s_isSelectedPlatform[platformHash] = selection; if (selection) { s_platformFeePercent[platformHash] = GLOBAL_PARAMS diff --git a/src/CampaignInfoFactory.sol b/src/CampaignInfoFactory.sol index 8342956c..716ac1b4 100644 --- a/src/CampaignInfoFactory.sol +++ b/src/CampaignInfoFactory.sol @@ -81,6 +81,9 @@ contract CampaignInfoFactory is Initializable, ICampaignInfoFactory, Ownable { bytes32[] calldata platformDataValue, CampaignData calldata campaignData ) external override { + if (creator == address(0)) { + revert CampaignInfoFactoryInvalidInput(); + } if ( campaignData.launchTime < block.timestamp || campaignData.deadline <= campaignData.launchTime @@ -90,6 +93,19 @@ contract CampaignInfoFactory is Initializable, ICampaignInfoFactory, Ownable { if (platformDataKey.length != platformDataValue.length) { revert CampaignInfoFactoryInvalidInput(); } + + bool isValid; + for (uint256 i = 0; i < platformDataKey.length; i++) { + isValid = GLOBAL_PARAMS.checkIfPlatformDataKeyValid( + platformDataKey[i] + ); + if (!isValid) { + revert CampaignInfoFactoryInvalidInput(); + } + if (platformDataValue[i] == bytes32(0)) { + revert CampaignInfoFactoryInvalidInput(); + } + } address cloneExists = identifierToCampaignInfo[identifierHash]; if (cloneExists != address(0)) { revert CampaignInfoFactoryCampaignWithSameIdentifierExists( diff --git a/src/interfaces/ICampaignInfo.sol b/src/interfaces/ICampaignInfo.sol index 43771b79..6dda02c9 100644 --- a/src/interfaces/ICampaignInfo.sol +++ b/src/interfaces/ICampaignInfo.sol @@ -125,10 +125,14 @@ interface ICampaignInfo { * @dev It can only be called for a platform if its not approved i.e. the platform treasury is not deployed * @param platformHash The bytes32 identifier of the platform. * @param selection The new selection status (true or false). + * @param platformDataKey An array of platform-specific data keys. + * @param platformDataValue An array of platform-specific data values. */ function updateSelectedPlatform( bytes32 platformHash, - bool selection + bool selection, + bytes32[] calldata platformDataKey, + bytes32[] calldata platformDataValue ) external; /** diff --git a/src/interfaces/ICampaignInfoFactory.sol b/src/interfaces/ICampaignInfoFactory.sol index f8b53c35..cc7f137c 100644 --- a/src/interfaces/ICampaignInfoFactory.sol +++ b/src/interfaces/ICampaignInfoFactory.sol @@ -25,6 +25,11 @@ interface ICampaignInfoFactory is ICampaignData { /** * @notice Creates a new campaign information contract. + * @dev IMPORTANT: Protocol and platform fees are retrieved at execution time and locked + * permanently in the campaign contract. Users should verify current fees before + * calling this function or using intermediate contracts that check fees haven't + * changed from expected values. The protocol fee is stored as immutable in the cloned + * contract and platform fees are stored during initialization. * @param creator The address of the creator of the campaign. * @param identifierHash The unique identifier hash of the campaign. * @param selectedPlatformHash An array of platform identifiers selected for the campaign. diff --git a/src/treasuries/AllOrNothing.sol b/src/treasuries/AllOrNothing.sol index 2a400a9e..10b52d28 100644 --- a/src/treasuries/AllOrNothing.sol +++ b/src/treasuries/AllOrNothing.sol @@ -270,7 +270,11 @@ contract AllOrNothing is if (reward[i] == ZERO_BYTES) { revert AllOrNothingInvalidInput(); } - pledgeAmount += s_reward[reward[i]].rewardValue; + tempReward = s_reward[reward[i]]; + if (tempReward.rewardValue == 0) { + revert AllOrNothingInvalidInput(); + } + pledgeAmount += tempReward.rewardValue; } _pledge(backer, reward[0], pledgeAmount, shippingFee, tokenId, reward); } diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index 38ed74bb..f7c64500 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -38,6 +38,8 @@ contract KeepWhatsRaised is mapping(bytes32 => bool) public s_processedPledges; /// Mapping to store payment gateway fees by unique pledge ID mapping(bytes32 => uint256) public s_paymentGatewayFees; + /// Mapping that stores fee values indexed by their corresponding fee keys. + mapping(bytes32 => uint256) private s_feeValues; // Counters for token IDs and rewards Counters.Counter private s_tokenIdCounter; @@ -57,6 +59,22 @@ contract KeepWhatsRaised is /// @dev Keys for gross percentage-based fees (calculated before deductions). bytes32[] grossPercentageFeeKeys; } + + /** + * @dev Represents the complete fee structure values for treasury operations. + * These values correspond to the fees that will be applied to transactions + * and are typically retrieved using keys from `FeeKeys` struct. + */ + struct FeeValues { + /// @dev Value for a flat fee applied to an operation. + uint256 flatFeeValue; + + /// @dev Value for a cumulative flat fee, potentially across multiple actions. + uint256 cumulativeFlatFeeValue; + + /// @dev Values for gross percentage-based fees (calculated before deductions). + uint256[] grossPercentageFeeValues; + } /** * @dev System configuration parameters related to withdrawal and refund behavior. */ @@ -130,11 +148,13 @@ contract KeepWhatsRaised is * @param config The updated configuration parameters (e.g., delays, exemptions). * @param campaignData The campaign-related data associated with the treasury setup. * @param feeKeys The set of keys used to determine applicable fees. + * @param feeValues The fee values corresponding to the fee keys. */ event TreasuryConfigured( Config config, CampaignData campaignData, - FeeKeys feeKeys + FeeKeys feeKeys, + FeeValues feeValues ); /** @@ -217,7 +237,15 @@ contract KeepWhatsRaised is * @param withdrawalAmount The attempted withdrawal amount. * @param fee The fee that would be applied to the withdrawal. */ - error KeepWhatsRaisedWithdrawalOverload(uint256 availableAmount, uint256 withdrawalAmount, uint256 fee); + error KeepWhatsRaisedInsufficientFundsForWithdrawalAndFee(uint256 availableAmount, uint256 withdrawalAmount, uint256 fee); + + /** + * @notice Emitted when the fee exceeds the requested withdrawal amount. + * + * @param withdrawalAmount The amount requested for withdrawal. + * @param fee The calculated fee, which is greater than the withdrawal amount. + */ + error KeepWhatsRaisedInsufficientFundsForFee(uint256 withdrawalAmount, uint256 fee); /** * @dev Emitted when a withdrawal has already been made and cannot be repeated. @@ -385,6 +413,16 @@ contract KeepWhatsRaised is return s_paymentGatewayFees[pledgeId]; } + /** + * @dev Retrieves the fee value associated with a specific fee key from storage. + * @param {bytes32} feeKey - The unique identifier key used to reference a specific fee type. + * + * @return {uint256} The fee value corresponding to the provided fee key. + */ + function getFeeValue(bytes32 feeKey) public view returns (uint256) { + return s_feeValues[feeKey]; + } + /** * @notice Sets the fixed payment gateway fee for a specific pledge. * @param pledgeId The unique identifier of the pledge. @@ -431,11 +469,13 @@ contract KeepWhatsRaised is * fee exemption threshold, and configuration lock period. * @param campaignData The campaign-related metadata such as deadlines and funding goals. * @param feeKeys The set of keys used to reference applicable flat and percentage-based fees. + * @param feeValues The fee values corresponding to the fee keys. */ function configureTreasury( Config memory config, CampaignData memory campaignData, - FeeKeys memory feeKeys + FeeKeys memory feeKeys, + FeeValues memory feeValues ) external onlyPlatformAdmin(PLATFORM_HASH) @@ -444,14 +484,34 @@ contract KeepWhatsRaised is whenCampaignNotCancelled whenNotCancelled { + if ( + campaignData.launchTime < block.timestamp || + campaignData.deadline <= campaignData.launchTime + ) { + revert KeepWhatsRaisedInvalidInput(); + } + if( + feeKeys.grossPercentageFeeKeys.length != feeValues.grossPercentageFeeValues.length + ) { + revert KeepWhatsRaisedInvalidInput(); + } + s_config = config; s_feeKeys = feeKeys; s_campaignData = campaignData; + s_feeValues[feeKeys.flatFeeKey] = feeValues.flatFeeValue; + s_feeValues[feeKeys.cumulativeFlatFeeKey] = feeValues.cumulativeFlatFeeValue; + + for (uint256 i = 0; i < feeKeys.grossPercentageFeeKeys.length; i++) { + s_feeValues[feeKeys.grossPercentageFeeKeys[i]] = feeValues.grossPercentageFeeValues[i]; + } + emit TreasuryConfigured( config, campaignData, - feeKeys + feeKeys, + feeValues ); } @@ -473,7 +533,7 @@ contract KeepWhatsRaised is whenNotPaused whenNotCancelled { - if (deadline <= getLaunchTime()) { + if (deadline <= getLaunchTime() || deadline <= block.timestamp) { revert KeepWhatsRaisedInvalidInput(); } @@ -609,9 +669,9 @@ contract KeepWhatsRaised is setPaymentGatewayFee(pledgeId, fee); if(isPledgeForAReward){ - pledgeForAReward(pledgeId, backer, tip, reward); + _pledgeForAReward(pledgeId, backer, tip, reward, msg.sender); // Pass admin as token source }else { - pledgeWithoutAReward(pledgeId, backer, pledgeAmount, tip); + _pledgeWithoutAReward(pledgeId, backer, pledgeAmount, tip, msg.sender); // Pass admin as token source } } @@ -637,10 +697,41 @@ contract KeepWhatsRaised is whenCampaignNotCancelled whenNotCancelled { - if(s_processedPledges[pledgeId]){ - revert KeepWhatsRaisedPledgeAlreadyProcessed(pledgeId); + _pledgeForAReward(pledgeId, backer, tip, reward, backer); // Pass backer as token source for direct calls + } + + /** + * @notice Internal function that allows a backer to pledge for a reward with tokens transferred from a specified source. + * @dev The first element of the `reward` array must be a reward tier and the other elements can be either reward tiers or non-reward tiers. + * The non-reward tiers cannot be pledged for without a reward. + * This function is called internally by both public pledgeForAReward (with backer as token source) and + * setFeeAndPledge (with admin as token source). + * @param pledgeId The unique identifier of the pledge. + * @param backer The address of the backer making the pledge (receives the NFT). + * @param tip An optional tip can be added during the process. + * @param reward An array of reward names. + * @param tokenSource The address from which tokens will be transferred (either backer for direct calls or admin for setFeeAndPledge calls). + */ + function _pledgeForAReward( + bytes32 pledgeId, + address backer, + uint256 tip, + bytes32[] calldata reward, + address tokenSource + ) + internal + currentTimeIsWithinRange(getLaunchTime(), getDeadline()) + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled + { + bytes32 internalPledgeId = keccak256(abi.encodePacked(pledgeId, msg.sender)); + + if(s_processedPledges[internalPledgeId]){ + revert KeepWhatsRaisedPledgeAlreadyProcessed(internalPledgeId); } - s_processedPledges[pledgeId] = true; + s_processedPledges[internalPledgeId] = true; uint256 tokenId = s_tokenIdCounter.current(); uint256 rewardLen = reward.length; @@ -658,9 +749,13 @@ contract KeepWhatsRaised is if (reward[i] == ZERO_BYTES) { revert KeepWhatsRaisedInvalidInput(); } - pledgeAmount += s_reward[reward[i]].rewardValue; + tempReward = s_reward[reward[i]]; + if (tempReward.rewardValue == 0) { + revert KeepWhatsRaisedInvalidInput(); + } + pledgeAmount += tempReward.rewardValue; } - _pledge(pledgeId, backer, reward[0], pledgeAmount, tip, tokenId, reward); + _pledge(pledgeId, backer, reward[0], pledgeAmount, tip, tokenId, reward, tokenSource); } /** @@ -683,15 +778,44 @@ contract KeepWhatsRaised is whenCampaignNotCancelled whenNotCancelled { - if(s_processedPledges[pledgeId]){ - revert KeepWhatsRaisedPledgeAlreadyProcessed(pledgeId); + _pledgeWithoutAReward(pledgeId, backer, pledgeAmount, tip, backer); // Pass backer as token source for direct calls + } + + /** + * @notice Internal function that allows a backer to pledge without selecting a reward with tokens transferred from a specified source. + * @dev This function is called internally by both public pledgeWithoutAReward (with backer as token source) and + * setFeeAndPledge (with admin as token source). + * @param pledgeId The unique identifier of the pledge. + * @param backer The address of the backer making the pledge (receives the NFT). + * @param pledgeAmount The amount of the pledge. + * @param tip An optional tip can be added during the process. + * @param tokenSource The address from which tokens will be transferred (either backer for direct calls or admin for setFeeAndPledge calls). + */ + function _pledgeWithoutAReward( + bytes32 pledgeId, + address backer, + uint256 pledgeAmount, + uint256 tip, + address tokenSource + ) + internal + currentTimeIsWithinRange(getLaunchTime(), getDeadline()) + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled + { + bytes32 internalPledgeId = keccak256(abi.encodePacked(pledgeId, msg.sender)); + + if(s_processedPledges[internalPledgeId]){ + revert KeepWhatsRaisedPledgeAlreadyProcessed(internalPledgeId); } - s_processedPledges[pledgeId] = true; + s_processedPledges[internalPledgeId] = true; uint256 tokenId = s_tokenIdCounter.current(); bytes32[] memory emptyByteArray = new bytes32[](0); - _pledge(pledgeId, backer, ZERO_BYTES, pledgeAmount, tip, tokenId, emptyByteArray); + _pledge(pledgeId, backer, ZERO_BYTES, pledgeAmount, tip, tokenId, emptyByteArray, tokenSource); } /** @@ -702,33 +826,49 @@ contract KeepWhatsRaised is } /** - * @dev Allows a campaign owner or eligible party to withdraw a specified amount of funds. - * - * @param amount The amount to withdraw. - * + * @dev Allows the campaign owner or platform admin to withdraw funds, applying required fees and taxes. + * + * @param amount The withdrawal amount (ignored for final withdrawals). + * * Requirements: - * - Withdrawals must be approved (see `withdrawalEnabled` modifier). - * - Amount must not exceed the available balance after fees. - * - May apply and deduct a withdrawal fee. + * - Caller must be authorized. + * - Withdrawals must be enabled, not paused, and within the allowed time. + * - For partial withdrawals: + * - `amount` > 0 and `amount + fees` ≤ available balance. + * - For final withdrawals: + * - Available balance > 0 and fees ≤ available balance. + * + * Effects: + * - Deducts fees (flat, cumulative, and Colombian tax if applicable). + * - Updates available balance. + * - Transfers net funds to the recipient. + * + * Reverts: + * - If insufficient funds or invalid input. + * + * Emits: + * - `WithdrawalWithFeeSuccessful`. */ function withdraw( uint256 amount ) public + onlyPlatformAdminOrCampaignOwner currentTimeIsLess(getDeadline() + s_config.withdrawalDelay) whenNotPaused whenNotCancelled withdrawalEnabled { - uint256 flatFee = uint256(INFO.getPlatformData(s_feeKeys.flatFeeKey)); - uint256 cumulativeFee = uint256(INFO.getPlatformData(s_feeKeys.cumulativeFlatFeeKey)); + uint256 flatFee = getFeeValue(s_feeKeys.flatFeeKey); + uint256 cumulativeFee = getFeeValue(s_feeKeys.cumulativeFlatFeeKey); uint256 currentTime = block.timestamp; uint256 withdrawalAmount = s_availablePledgedAmount; uint256 totalFee = 0; address recipient = INFO.owner(); + bool isFinalWithdrawal = (currentTime > getDeadline()); //Main Fees - if(currentTime > getDeadline()){ + if(isFinalWithdrawal){ if(withdrawalAmount == 0){ revert KeepWhatsRaisedAlreadyWithdrawn(); } @@ -743,7 +883,7 @@ contract KeepWhatsRaised is revert KeepWhatsRaisedInvalidInput(); } if(withdrawalAmount > s_availablePledgedAmount){ - revert KeepWhatsRaisedWithdrawalOverload(s_availablePledgedAmount, withdrawalAmount, totalFee); + revert KeepWhatsRaisedInsufficientFundsForWithdrawalAndFee(s_availablePledgedAmount, withdrawalAmount, totalFee); } if(withdrawalAmount < s_config.minimumWithdrawalForFeeExemption){ @@ -755,17 +895,7 @@ contract KeepWhatsRaised is } } - //Other Fees - uint256 fee = (withdrawalAmount * INFO.getProtocolFeePercent()) / - PERCENT_DIVIDER; - s_protocolFee += fee; - totalFee += fee; - - if(totalFee > withdrawalAmount){ - revert KeepWhatsRaisedWithdrawalOverload(s_availablePledgedAmount, withdrawalAmount, totalFee); - } - - uint256 availableBeforeTax = withdrawalAmount - totalFee; + uint256 availableBeforeTax = withdrawalAmount; //The tax implemented is on the withdrawal amount // Colombian creator tax if (s_config.isColombianCreator) { @@ -777,18 +907,25 @@ contract KeepWhatsRaised is s_platformFee += columbianCreatorTax; totalFee += columbianCreatorTax; + } - if(totalFee > withdrawalAmount){ - revert KeepWhatsRaisedWithdrawalOverload(s_availablePledgedAmount, withdrawalAmount, totalFee); + if(isFinalWithdrawal) { + if(withdrawalAmount < totalFee) { + revert KeepWhatsRaisedInsufficientFundsForFee(withdrawalAmount, totalFee); + } + + s_availablePledgedAmount = 0; + TOKEN.safeTransfer(recipient, withdrawalAmount - totalFee); + } else { + if(s_availablePledgedAmount < (withdrawalAmount + totalFee)) { + revert KeepWhatsRaisedInsufficientFundsForWithdrawalAndFee(s_availablePledgedAmount, withdrawalAmount, totalFee); } + + s_availablePledgedAmount -= (withdrawalAmount + totalFee); + TOKEN.safeTransfer(recipient, withdrawalAmount); } - s_availablePledgedAmount -= withdrawalAmount; - withdrawalAmount -= totalFee; - - TOKEN.safeTransfer(recipient, withdrawalAmount); - - emit WithdrawalWithFeeSuccessful(recipient, withdrawalAmount, totalFee); + emit WithdrawalWithFeeSuccessful(recipient, isFinalWithdrawal ? withdrawalAmount - totalFee : withdrawalAmount, totalFee); } /** @@ -891,12 +1028,12 @@ contract KeepWhatsRaised is } /** - * @dev Allows a campaign owner or authorized user to claim remaining campaign funds. - * - * Requirements: - * - Claim period must have started and funds must be available. - * - Cannot be previously claimed. - */ + * @dev Allows the platform admin to claim the remaining funds from a campaign. + * + * Requirements: + * - Claim period must have started and funds must be available. + * - Cannot be previously claimed. + */ function claimFund() external onlyPlatformAdmin(PLATFORM_HASH) @@ -957,10 +1094,14 @@ contract KeepWhatsRaised is uint256 pledgeAmount, uint256 tip, uint256 tokenId, - bytes32[] memory rewards + bytes32[] memory rewards, + address tokenSource ) private { uint256 totalAmount = pledgeAmount + tip; - TOKEN.safeTransferFrom(backer, address(this), totalAmount); + + // Transfer tokens from tokenSource (either admin or backer) + TOKEN.safeTransferFrom(tokenSource, address(this), totalAmount); + s_tokenIdCounter.increment(); s_tokenToPledgedAmount[tokenId] = pledgeAmount; s_tokenToTippedAmount[tokenId] = tip; @@ -983,16 +1124,21 @@ contract KeepWhatsRaised is } /** - * @dev Calculates the net available amount after deducting platform fees and applicable taxes - * @param pledgeId The unique identifier of the pledge. - * @param tokenId The ID of the token representing the pledge. - * @param pledgeAmount The total pledge amount before any deductions - * @return The net available amount after all fees and taxes are deducted - * - * @notice This function performs the following calculations: - * 1. Applies all gross percentage fees based on platform configuration - * 2. Calculates Colombian creator tax if applicable (0.4% effective rate) - * 3. Updates the total platform fee accumulator + * @notice Calculates the net amount available from a pledge after deducting + * all applicable fees. + * + * @dev The function performs the following: + * - Applies all configured gross percentage-based fees + * - Applies payment gateway fee for the given pledge + * - Applies protocol fee based on protocol configuration + * - Accumulates total platform and protocol fees + * - Records the total deducted fee for the token + * + * @param pledgeId The unique identifier of the pledge + * @param tokenId The token ID representing the pledge + * @param pledgeAmount The original pledged amount before deductions + * + * @return The net available amount after all fees are deducted */ function _calculateNetAvailable(bytes32 pledgeId, uint256 tokenId, uint256 pledgeAmount) internal returns (uint256) { uint256 totalFee = 0; @@ -1000,7 +1146,7 @@ contract KeepWhatsRaised is // Gross Percentage Fee Calculation uint256 len = s_feeKeys.grossPercentageFeeKeys.length; for (uint256 i = 0; i < len; i++) { - uint256 fee = (pledgeAmount * uint256(INFO.getPlatformData(s_feeKeys.grossPercentageFeeKeys[i]))) + uint256 fee = (pledgeAmount * getFeeValue(s_feeKeys.grossPercentageFeeKeys[i])) / PERCENT_DIVIDER; s_platformFee += fee; totalFee += fee; @@ -1011,6 +1157,12 @@ contract KeepWhatsRaised is s_platformFee += paymentGatewayFee; totalFee += paymentGatewayFee; + //Protocol Fee Calculation + uint256 protocolFee = (pledgeAmount * INFO.getProtocolFeePercent()) / + PERCENT_DIVIDER; + s_protocolFee += protocolFee; + totalFee += protocolFee; + s_tokenToPaymentFee[tokenId] = totalFee; return pledgeAmount - totalFee; From b9815f2bffad4e092aaa72dc0d7e7418795ee1ce Mon Sep 17 00:00:00 2001 From: AdnanHKx Date: Fri, 8 Aug 2025 12:14:47 +0600 Subject: [PATCH 37/63] Enhance KeepWhatsRaised audit test coverage and update deployment scripts (#20) * Update test files for KeepWhatsRaised treasury - Remove platformData setup and switch to empty arrays for the new treasury flow - It accommodates a new fee storage flow * Update KeepWhatsRaised deployment script * Update address(this) to deployerAddress in the AllOrNothing deploy script to avoid deployment compatibility issues with newer versions of forge --- .gitignore | 1 + script/DeployAllAndSetupAllOrNothing.s.sol | 2 +- script/DeployAllAndSetupKeepWhatsRaised.s.sol | 56 +--- .../KeepWhatsRaised/KeepWhatsRaised.t.sol | 78 +++--- .../KeepWhatsRaisedFunction.t.sol | 42 ++- test/foundry/unit/KeepWhatsRaised.t.sol | 253 ++++++++++++------ 6 files changed, 249 insertions(+), 183 deletions(-) diff --git a/.gitignore b/.gitignore index e8be93c1..723c0dbd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules +lib .env .deps .temp diff --git a/script/DeployAllAndSetupAllOrNothing.s.sol b/script/DeployAllAndSetupAllOrNothing.s.sol index d0dc456c..6ec89e72 100644 --- a/script/DeployAllAndSetupAllOrNothing.s.sol +++ b/script/DeployAllAndSetupAllOrNothing.s.sol @@ -144,7 +144,7 @@ contract DeployAllAndSetupAllOrNothing is Script { // Deploy CampaignInfo implementation if needed for new deployments if (campaignInfoFactory == address(0)) { campaignInfoImplementation = address( - new CampaignInfo(address(this)) + new CampaignInfo(deployerAddress) ); console2.log( "CampaignInfo implementation deployed at:", diff --git a/script/DeployAllAndSetupKeepWhatsRaised.s.sol b/script/DeployAllAndSetupKeepWhatsRaised.s.sol index 4dd2d31e..8b134030 100644 --- a/script/DeployAllAndSetupKeepWhatsRaised.s.sol +++ b/script/DeployAllAndSetupKeepWhatsRaised.s.sol @@ -12,6 +12,7 @@ import {KeepWhatsRaised} from "src/treasuries/KeepWhatsRaised.sol"; /** * @notice Script to deploy and setup all needed contracts for the keepWhatsRaised + * @dev Updated for the new KeepWhatsRaised contract that stores fees locally */ contract DeployAllAndSetupKeepWhatsRaised is Script { // Customizable values (set through environment variables) @@ -41,7 +42,6 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { bool implementationRegistered = false; bool implementationApproved = false; bool adminRightsTransferred = false; - bool platformDataKeyAdded = false; // Flags for contract deployment or reuse bool testTokenDeployed = false; @@ -50,13 +50,6 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { bool campaignInfoFactoryDeployed = false; bool keepWhatsRaisedDeployed = false; - //Treasury Keys - bytes32 PLATFORM_FEE_KEY; - bytes32 FLAT_FEE_KEY; - bytes32 CUMULATIVE_FLAT_FEE_KEY; - bytes32 PAYMENT_GATEWAY_FEE_KEY; - bytes32 COLUMBIAN_CREATOR_TAX_KEY; - // Configure parameters based on environment variables function setupParams() internal { // Get customizable values @@ -83,18 +76,6 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { treasuryFactory = vm.envOr("TREASURY_FACTORY_ADDRESS", address(0)); campaignInfoFactory = vm.envOr("CAMPAIGN_INFO_FACTORY_ADDRESS", address(0)); keepWhatsRaisedImplementation = vm.envOr("KEEP_WHATS_RAISED_IMPLEMENTATION_ADDRESS", address(0)); - - //Get Treasury Keys - PLATFORM_FEE_KEY = keccak256(abi.encodePacked("platformFee")); - FLAT_FEE_KEY = keccak256(abi.encodePacked("flatFee")); - CUMULATIVE_FLAT_FEE_KEY = keccak256(abi.encodePacked("cumulativeFlatFee")); - - console2.log("Platform Fee Key:"); - console2.logBytes32(PLATFORM_FEE_KEY); - console2.log("Flat Fee Key:"); - console2.logBytes32(FLAT_FEE_KEY); - console2.log("Cumulative Fee Key:"); - console2.logBytes32(CUMULATIVE_FLAT_FEE_KEY); console2.log("Using platform hash for:", platformName); console2.log("Protocol fee percent:", protocolFeePercent); @@ -110,7 +91,6 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { console2.log("Setting up contracts..."); // Deploy or reuse TestToken - string memory tokenName = vm.envOr("TOKEN_NAME", string("TestToken")); string memory tokenSymbol = vm.envOr("TOKEN_SYMBOL", string("TST")); @@ -141,7 +121,7 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { // Deploy CampaignInfo implementation if needed for new deployments if (campaignInfoFactory == address(0)) { - campaignInfo = address(new CampaignInfo(address(this))); + campaignInfo = address(new CampaignInfo(deployerAddress)); console2.log("CampaignInfo deployed at:", campaignInfo); } @@ -260,35 +240,6 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { implementationApproved = true; console2.log("Treasury implementation approved successfully"); } - - function addPlatformDataKey() internal { - - console2.log("Setting up: addPlatformDataKey"); - - // Only use startPrank in simulation mode - if (simulate) { - vm.startPrank(deployerAddress); - } - - GlobalParams(globalParams).addPlatformData( - platformHash, - PLATFORM_FEE_KEY - ); - GlobalParams(globalParams).addPlatformData( - platformHash, - FLAT_FEE_KEY - ); - GlobalParams(globalParams).addPlatformData( - platformHash, - CUMULATIVE_FLAT_FEE_KEY - ); - - if (simulate) { - vm.stopPrank(); - } - platformDataKeyAdded = true; - console2.log("Platform Data Key Added successfully"); - } function mintTokens() internal { // Only mint tokens if we deployed TestToken @@ -350,7 +301,6 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { enlistPlatform(); registerTreasuryImplementation(); approveTreasuryImplementation(); - addPlatformDataKey(); // Mint tokens if needed mintTokens(); @@ -394,8 +344,6 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { console2.log("2. Treasury implementation registered:", implementationRegistered); console2.log("3. Treasury implementation approved:", implementationApproved); console2.log("4. Admin rights transferred:", adminRightsTransferred); - console2.log("5. Added Platform Data Key:", platformDataKeyAdded); - console2.log("\nDeployment and setup completed successfully!"); } } \ No newline at end of file diff --git a/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaised.t.sol b/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaised.t.sol index 59ba173e..7fcc957a 100644 --- a/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaised.t.sol +++ b/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaised.t.sol @@ -32,11 +32,7 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder approveTreasuryImplementation(PLATFORM_2_HASH); console.log("approved treasury"); - - // Add platform data keys - addPlatformData(PLATFORM_2_HASH); - console.log("added platform data"); - + // Create Campaign createCampaign(PLATFORM_2_HASH); console.log("created campaign"); @@ -45,8 +41,17 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder deploy(PLATFORM_2_HASH); console.log("deployed treasury"); - // Configure Treasury - configureTreasury(users.platform2AdminAddress, treasuryAddress, CONFIG, CAMPAIGN_DATA, FEE_KEYS); + // Create FeeValues struct + KeepWhatsRaised.FeeValues memory feeValues = KeepWhatsRaised.FeeValues({ + flatFeeValue: uint256(FLAT_FEE_VALUE), + cumulativeFlatFeeValue: uint256(CUMULATIVE_FLAT_FEE_VALUE), + grossPercentageFeeValues: new uint256[](2) + }); + feeValues.grossPercentageFeeValues[0] = uint256(PLATFORM_FEE_VALUE); + feeValues.grossPercentageFeeValues[1] = uint256(VAKI_COMMISSION_VALUE); + + // Configure Treasury with fee values + configureTreasury(users.platform2AdminAddress, treasuryAddress, CONFIG, CAMPAIGN_DATA, FEE_KEYS, feeValues); console.log("configured treasury"); } @@ -100,27 +105,9 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder bytes32[] memory selectedPlatformHash = new bytes32[](1); selectedPlatformHash[0] = platformHash; - // Calculate total size needed - uint256 totalSize = GROSS_PERCENTAGE_FEE_KEYS.length + 2; // +2 for flat fees - - // Create arrays for platform data keys and values - bytes32[] memory platformDataKey = new bytes32[](totalSize); - bytes32[] memory platformDataValue = new bytes32[](totalSize); - - // Add the individual fee key-value pairs - platformDataKey[0] = FLAT_FEE_KEY; - platformDataValue[0] = FLAT_FEE_VALUE; - - platformDataKey[1] = CUMULATIVE_FLAT_FEE_KEY; - platformDataValue[1] = CUMULATIVE_FLAT_FEE_VALUE; - - // Add gross percentage fees - uint256 currentIndex = 2; - for (uint256 i = 0; i < GROSS_PERCENTAGE_FEE_KEYS.length; i++) { - platformDataKey[currentIndex] = GROSS_PERCENTAGE_FEE_KEYS[i]; - platformDataValue[currentIndex] = GROSS_PERCENTAGE_FEE_VALUES[i]; - currentIndex++; - } + // Pass empty arrays since fees are now configured via configureTreasury + bytes32[] memory platformDataKey = new bytes32[](0); + bytes32[] memory platformDataValue = new bytes32[](0); vm.startPrank(users.creator1Address); vm.recordLogs(); @@ -129,8 +116,8 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder users.creator1Address, identifierHash, selectedPlatformHash, - platformDataKey, - platformDataValue, + platformDataKey, + platformDataValue, CAMPAIGN_DATA ); @@ -179,13 +166,27 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder address treasury, KeepWhatsRaised.Config memory _config, ICampaignData.CampaignData memory campaignData, - KeepWhatsRaised.FeeKeys memory _feeKeys + KeepWhatsRaised.FeeKeys memory _feeKeys, + KeepWhatsRaised.FeeValues memory _feeValues ) internal { vm.startPrank(caller); - KeepWhatsRaised(treasury).configureTreasury(_config, campaignData, _feeKeys); + KeepWhatsRaised(treasury).configureTreasury(_config, campaignData, _feeKeys, _feeValues); vm.stopPrank(); } + /** + * @notice Helper function to create FeeValues struct + */ + function createFeeValues() internal pure returns (KeepWhatsRaised.FeeValues memory) { + KeepWhatsRaised.FeeValues memory feeValues; + feeValues.flatFeeValue = uint256(FLAT_FEE_VALUE); + feeValues.cumulativeFlatFeeValue = uint256(CUMULATIVE_FLAT_FEE_VALUE); + feeValues.grossPercentageFeeValues = new uint256[](2); + feeValues.grossPercentageFeeValues[0] = uint256(PLATFORM_FEE_VALUE); + feeValues.grossPercentageFeeValues[1] = uint256(VAKI_COMMISSION_VALUE); + return feeValues; + } + /** * @notice Approves withdrawal for the treasury. */ @@ -259,10 +260,7 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder vm.startPrank(caller); vm.recordLogs(); - // Approve tokens from backer first - vm.stopPrank(); - vm.startPrank(backer); - + // Approve tokens from admin (caller) since admin will be the token source if (isPledgeForAReward) { // Calculate total pledge amount from rewards uint256 totalPledgeAmount = 0; @@ -273,9 +271,6 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder } else { testToken.approve(treasury, pledgeAmount + tip); } - - vm.stopPrank(); - vm.startPrank(caller); KeepWhatsRaised(treasury).setFeeAndPledge(pledgeId, backer, pledgeAmount, tip, fee, reward, isPledgeForAReward); @@ -358,11 +353,12 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder /** * @notice Implements withdraw helper function with amount parameter. */ - function withdraw(address keepWhatsRaisedAddress, uint256 amount, uint256 warpTime) + function withdraw(address caller, address keepWhatsRaisedAddress, uint256 amount, uint256 warpTime) internal returns (Vm.Log[] memory logs, address to, uint256 withdrawalAmount, uint256 fee) { vm.warp(warpTime); + vm.startPrank(caller); vm.recordLogs(); KeepWhatsRaised(keepWhatsRaisedAddress).withdraw(amount); @@ -375,6 +371,8 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder to = address(uint160(uint256(topics[1]))); (withdrawalAmount, fee) = abi.decode(data, (uint256, uint256)); + + vm.stopPrank(); } /** diff --git a/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaisedFunction.t.sol b/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaisedFunction.t.sol index a8b7e46d..67a8f5aa 100644 --- a/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaisedFunction.t.sol +++ b/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaisedFunction.t.sol @@ -86,6 +86,7 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte assertEq(1, backerNftBalance); assertEq(keepWhatsRaised.getRaisedAmount(), PLEDGE_AMOUNT); + // Account for protocol fee being deducted during pledge assertTrue(keepWhatsRaised.getAvailableRaisedAmount() < PLEDGE_AMOUNT); } @@ -108,6 +109,7 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte assertEq(1, backerNftBalance); assertEq(keepWhatsRaised.getRaisedAmount(), PLEDGE_AMOUNT); + // Account for protocol fee being deducted during pledge assertTrue(keepWhatsRaised.getAvailableRaisedAmount() < PLEDGE_AMOUNT); } @@ -134,7 +136,7 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte // Verify fee was set assertEq(keepWhatsRaised.getPaymentGatewayFee(TEST_PLEDGE_ID_1), PAYMENT_GATEWAY_FEE); - // Verify pledge was made + // Verify pledge was made - tokens come from admin not backer address nftOwnerAddress = keepWhatsRaised.ownerOf(tokenId); assertEq(users.backer1Address, nftOwnerAddress); } @@ -159,14 +161,15 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte // Verify fee was set assertEq(keepWhatsRaised.getPaymentGatewayFee(TEST_PLEDGE_ID_1), PAYMENT_GATEWAY_FEE); - // Verify pledge was made + // Verify pledge was made - tokens come from admin not backer address nftOwnerAddress = keepWhatsRaised.ownerOf(tokenId); assertEq(users.backer1Address, nftOwnerAddress); } function test_withdrawWithColombianCreatorTax() external { // Configure with Colombian creator - configureTreasury(users.platform2AdminAddress, address(keepWhatsRaised), CONFIG_COLOMBIAN, CAMPAIGN_DATA, FEE_KEYS); + KeepWhatsRaised.FeeValues memory feeValues = createFeeValues(); + configureTreasury(users.platform2AdminAddress, address(keepWhatsRaised), CONFIG_COLOMBIAN, CAMPAIGN_DATA, FEE_KEYS, feeValues); addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); @@ -195,7 +198,7 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte uint256 ownerBalanceBefore = testToken.balanceOf(actualOwner); (Vm.Log[] memory logs, address to, uint256 withdrawalAmount, uint256 fee) = - withdraw(address(keepWhatsRaised), 0, DEADLINE + 1 days); + withdraw(users.platform2AdminAddress, address(keepWhatsRaised), 0, DEADLINE + 1 days); uint256 ownerBalanceAfter = testToken.balanceOf(actualOwner); @@ -231,9 +234,11 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte assertEq(refundedTokenId, tokenId); + // Account for all fees including protocol fee uint256 platformFee = (PLEDGE_AMOUNT * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; uint256 vakiCommission = (PLEDGE_AMOUNT * uint256(VAKI_COMMISSION_VALUE)) / PERCENT_DIVIDER; - uint256 expectedRefund = PLEDGE_AMOUNT - PAYMENT_GATEWAY_FEE - platformFee - vakiCommission; + uint256 protocolFee = (PLEDGE_AMOUNT * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 expectedRefund = PLEDGE_AMOUNT - PAYMENT_GATEWAY_FEE - platformFee - vakiCommission - protocolFee; assertEq(refundAmount, expectedRefund); assertEq(claimer, users.backer1Address); @@ -261,9 +266,12 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte users.backer2Address, address(testToken), address(keepWhatsRaised), TEST_PLEDGE_ID_2, PLEDGE_AMOUNT, 0, LAUNCH_TIME ); - // Approve and withdraw + // Approve and withdraw (as platform admin) approveWithdrawal(users.platform2AdminAddress, address(keepWhatsRaised)); - withdraw(address(keepWhatsRaised), PLEDGE_AMOUNT, DEADLINE - 1 days); + + vm.warp(DEADLINE - 1 days); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.withdraw(PLEDGE_AMOUNT); uint256 protocolAdminBalanceBefore = testToken.balanceOf(users.protocolAdminAddress); uint256 platformAdminBalanceBefore = testToken.balanceOf(users.platform2AdminAddress); @@ -366,7 +374,7 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte uint256 ownerBalanceBefore = testToken.balanceOf(actualOwner); (Vm.Log[] memory logs, address to, uint256 withdrawalAmount, uint256 fee) = - withdraw(address(keepWhatsRaised), 0, DEADLINE + 1 days); + withdraw(users.platform2AdminAddress, address(keepWhatsRaised), 0, DEADLINE + 1 days); uint256 ownerBalanceAfter = testToken.balanceOf(actualOwner); @@ -387,16 +395,22 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte // Approve withdrawal approveWithdrawal(users.platform2AdminAddress, address(keepWhatsRaised)); - uint256 partialAmount = 500e18; // Withdraw less than full amount uint256 availableBefore = keepWhatsRaised.getAvailableRaisedAmount(); + + // Calculate safe withdrawal amount that accounts for cumulative fee + // For small withdrawals, cumulative fee (200e18) is applied + // So we need available >= withdrawalAmount + cumulativeFee + uint256 partialAmount = 300e18; // Small amount to ensure we have enough for fees (Vm.Log[] memory logs, address to, uint256 withdrawalAmount, uint256 fee) = - withdraw(address(keepWhatsRaised), partialAmount, DEADLINE - 1 days); + withdraw(users.platform2AdminAddress, address(keepWhatsRaised), partialAmount, DEADLINE - 1 days); uint256 availableAfter = keepWhatsRaised.getAvailableRaisedAmount(); - assertEq(withdrawalAmount + fee, partialAmount, "Incorrect partial withdrawal"); - assertTrue(availableAfter < availableBefore, "Available amount should be reduced"); + // For partial withdrawals, the full amount requested is transferred + assertEq(withdrawalAmount, partialAmount, "Incorrect partial withdrawal"); + // Available amount is reduced by withdrawal amount plus fees + assertEq(availableBefore - availableAfter, partialAmount + fee, "Available should be reduced by withdrawal plus fee"); } function test_claimTip() external { @@ -569,9 +583,11 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte assertEq(refundedTokenId, tokenId); + // Account for all fees including protocol fee uint256 platformFee = (PLEDGE_AMOUNT * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; uint256 vakiCommission = (PLEDGE_AMOUNT * uint256(VAKI_COMMISSION_VALUE)) / PERCENT_DIVIDER; - uint256 expectedRefund = PLEDGE_AMOUNT - PAYMENT_GATEWAY_FEE - platformFee - vakiCommission; + uint256 protocolFee = (PLEDGE_AMOUNT * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 expectedRefund = PLEDGE_AMOUNT - PAYMENT_GATEWAY_FEE - platformFee - vakiCommission - protocolFee; assertEq(refundAmount, expectedRefund, "Refund amount should be pledge minus fees"); assertEq(claimer, users.backer1Address); diff --git a/test/foundry/unit/KeepWhatsRaised.t.sol b/test/foundry/unit/KeepWhatsRaised.t.sol index e6b27037..d9562c92 100644 --- a/test/foundry/unit/KeepWhatsRaised.t.sol +++ b/test/foundry/unit/KeepWhatsRaised.t.sol @@ -45,32 +45,17 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te bytes32[] memory selectedPlatformHash = new bytes32[](1); selectedPlatformHash[0] = PLATFORM_2_HASH; - // Create arrays for platform data keys and values - uint256 totalSize = 2 + GROSS_PERCENTAGE_FEE_KEYS.length; - bytes32[] memory platformDataKey = new bytes32[](totalSize); - bytes32[] memory platformDataValue = new bytes32[](totalSize); - - // Add the individual fee key-value pairs - platformDataKey[0] = FLAT_FEE_KEY; - platformDataValue[0] = FLAT_FEE_VALUE; - platformDataKey[1] = CUMULATIVE_FLAT_FEE_KEY; - platformDataValue[1] = CUMULATIVE_FLAT_FEE_VALUE; - - // Add gross percentage fees - uint256 currentIndex = 2; - for (uint256 i = 0; i < GROSS_PERCENTAGE_FEE_KEYS.length; i++) { - platformDataKey[currentIndex] = GROSS_PERCENTAGE_FEE_KEYS[i]; - platformDataValue[currentIndex] = GROSS_PERCENTAGE_FEE_VALUES[i]; - currentIndex++; - } + // Pass empty arrays since platform data is not used by the new treasury + bytes32[] memory platformDataKey = new bytes32[](0); + bytes32[] memory platformDataValue = new bytes32[](0); vm.prank(users.creator1Address); campaignInfoFactory.createCampaign( users.creator1Address, newIdentifierHash, selectedPlatformHash, - platformDataKey, - platformDataValue, + platformDataKey, // Empty array + platformDataValue, // Empty array CAMPAIGN_DATA ); @@ -103,12 +88,20 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te goalAmount: 5000 }); + KeepWhatsRaised.FeeValues memory feeValues = _createFeeValues(); + vm.prank(users.platform2AdminAddress); - keepWhatsRaised.configureTreasury(CONFIG, newCampaignData, FEE_KEYS); + keepWhatsRaised.configureTreasury(CONFIG, newCampaignData, FEE_KEYS, feeValues); assertEq(keepWhatsRaised.getLaunchTime(), newCampaignData.launchTime); assertEq(keepWhatsRaised.getDeadline(), newCampaignData.deadline); assertEq(keepWhatsRaised.getGoalAmount(), newCampaignData.goalAmount); + + // Verify fee values are stored + assertEq(keepWhatsRaised.getFeeValue(FLAT_FEE_KEY), uint256(FLAT_FEE_VALUE)); + assertEq(keepWhatsRaised.getFeeValue(CUMULATIVE_FLAT_FEE_KEY), uint256(CUMULATIVE_FLAT_FEE_VALUE)); + assertEq(keepWhatsRaised.getFeeValue(PLATFORM_FEE_KEY), uint256(PLATFORM_FEE_VALUE)); + assertEq(keepWhatsRaised.getFeeValue(VAKI_COMMISSION_KEY), uint256(VAKI_COMMISSION_VALUE)); } function testConfigureTreasuryWithColombianCreator() public { @@ -118,8 +111,10 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te goalAmount: 5000 }); + KeepWhatsRaised.FeeValues memory feeValues = _createFeeValues(); + vm.prank(users.platform2AdminAddress); - keepWhatsRaised.configureTreasury(CONFIG_COLOMBIAN, newCampaignData, FEE_KEYS); + keepWhatsRaised.configureTreasury(CONFIG_COLOMBIAN, newCampaignData, FEE_KEYS, feeValues); // Test that Colombian creator tax is not applied in pledges _setupReward(); @@ -137,14 +132,45 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te // Available amount should not include Colombian tax deduction at pledge time uint256 availableAmount = keepWhatsRaised.getAvailableRaisedAmount(); - uint256 expectedWithoutColombianTax = TEST_PLEDGE_AMOUNT - (TEST_PLEDGE_AMOUNT * PLATFORM_FEE_PERCENT / PERCENT_DIVIDER) - (TEST_PLEDGE_AMOUNT * 6 * 100 / PERCENT_DIVIDER); + uint256 expectedWithoutColombianTax = TEST_PLEDGE_AMOUNT + - (TEST_PLEDGE_AMOUNT * PLATFORM_FEE_PERCENT / PERCENT_DIVIDER) + - (TEST_PLEDGE_AMOUNT * 6 * 100 / PERCENT_DIVIDER) + - (TEST_PLEDGE_AMOUNT * PROTOCOL_FEE_PERCENT / PERCENT_DIVIDER); assertEq(availableAmount, expectedWithoutColombianTax, "Colombian tax should not be applied at pledge time"); } function testConfigureTreasuryRevertWhenNotPlatformAdmin() public { + KeepWhatsRaised.FeeValues memory feeValues = _createFeeValues(); + vm.expectRevert(); vm.prank(users.backer1Address); - keepWhatsRaised.configureTreasury(CONFIG, CAMPAIGN_DATA, FEE_KEYS); + keepWhatsRaised.configureTreasury(CONFIG, CAMPAIGN_DATA, FEE_KEYS, feeValues); + } + + function testConfigureTreasuryRevertWhenInvalidCampaignData() public { + // Invalid launch time (in the past) + ICampaignData.CampaignData memory invalidCampaignData = ICampaignData.CampaignData({ + launchTime: block.timestamp - 1, + deadline: block.timestamp + 31 days, + goalAmount: 5000 + }); + + KeepWhatsRaised.FeeValues memory feeValues = _createFeeValues(); + + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedInvalidInput.selector); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.configureTreasury(CONFIG, invalidCampaignData, FEE_KEYS, feeValues); + } + + function testConfigureTreasuryRevertWhenMismatchedFeeArrays() public { + // Create mismatched fee arrays + KeepWhatsRaised.FeeKeys memory mismatchedKeys = FEE_KEYS; + KeepWhatsRaised.FeeValues memory mismatchedValues = _createFeeValues(); + mismatchedValues.grossPercentageFeeValues = new uint256[](1); // Wrong length + + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedInvalidInput.selector); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.configureTreasury(CONFIG, CAMPAIGN_DATA, mismatchedKeys, mismatchedValues); } /*////////////////////////////////////////////////////////////// @@ -246,6 +272,14 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te keepWhatsRaised.updateDeadline(LAUNCH_TIME - 1); } + function testUpdateDeadlineRevertWhenDeadlineBeforeCurrentTime() public { + vm.warp(LAUNCH_TIME + 5 days); + + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedInvalidInput.selector); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.updateDeadline(LAUNCH_TIME + 4 days); + } + function testUpdateDeadlineRevertWhenPaused() public { _pauseTreasury(); @@ -419,7 +453,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te // Verify assertEq(testToken.balanceOf(users.backer1Address), balanceBefore - TEST_PLEDGE_AMOUNT - TEST_TIP_AMOUNT); assertEq(keepWhatsRaised.getRaisedAmount(), TEST_PLEDGE_AMOUNT); - assertTrue(keepWhatsRaised.getAvailableRaisedAmount() < TEST_PLEDGE_AMOUNT); // Less due to fees (no Colombian tax yet) + assertTrue(keepWhatsRaised.getAvailableRaisedAmount() < TEST_PLEDGE_AMOUNT); // Less due to fees assertEq(keepWhatsRaised.balanceOf(users.backer1Address), 1); } @@ -438,7 +472,8 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, 0, rewardSelection); // Try to pledge with same ID - vm.expectRevert(abi.encodeWithSelector(KeepWhatsRaised.KeepWhatsRaisedPledgeAlreadyProcessed.selector, TEST_PLEDGE_ID)); + bytes32 internalPledgeId = keccak256(abi.encodePacked(TEST_PLEDGE_ID, users.backer1Address)); + vm.expectRevert(abi.encodeWithSelector(KeepWhatsRaised.KeepWhatsRaisedPledgeAlreadyProcessed.selector, internalPledgeId)); keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, 0, rewardSelection); vm.stopPrank(); } @@ -497,8 +532,9 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te // First pledge keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); - // Try to pledge with same ID - vm.expectRevert(abi.encodeWithSelector(KeepWhatsRaised.KeepWhatsRaisedPledgeAlreadyProcessed.selector, TEST_PLEDGE_ID)); + // Try to pledge with same ID - internal pledge ID includes caller + bytes32 internalPledgeId = keccak256(abi.encodePacked(TEST_PLEDGE_ID, users.backer1Address)); + vm.expectRevert(abi.encodeWithSelector(KeepWhatsRaised.KeepWhatsRaisedPledgeAlreadyProcessed.selector, internalPledgeId)); keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); vm.stopPrank(); } @@ -544,11 +580,12 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te bytes32[] memory rewardSelection = new bytes32[](1); rewardSelection[0] = TEST_REWARD_NAME; - vm.startPrank(users.backer1Address); + // Fund admin with tokens since they will be the token source + deal(address(testToken), users.platform2AdminAddress, TEST_PLEDGE_AMOUNT + TEST_TIP_AMOUNT); + + vm.startPrank(users.platform2AdminAddress); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT + TEST_TIP_AMOUNT); - vm.stopPrank(); - vm.prank(users.platform2AdminAddress); keepWhatsRaised.setFeeAndPledge( TEST_PLEDGE_ID, users.backer1Address, @@ -558,6 +595,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te rewardSelection, true ); + vm.stopPrank(); // Verify fee was set assertEq(keepWhatsRaised.getPaymentGatewayFee(TEST_PLEDGE_ID), PAYMENT_GATEWAY_FEE); @@ -582,8 +620,9 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te address owner = CampaignInfo(campaignAddress).owner(); uint256 ownerBalanceBefore = testToken.balanceOf(owner); - // Withdraw after deadline + // Withdraw after deadline (as platform admin) vm.warp(DEADLINE + 1); + vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(0); uint256 ownerBalanceAfter = testToken.balanceOf(owner); @@ -604,14 +643,15 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te uint256 partialAmount = 500e18; uint256 availableBefore = keepWhatsRaised.getAvailableRaisedAmount(); - // Withdraw partial amount before deadline + // Withdraw partial amount before deadline (as platform admin) vm.warp(LAUNCH_TIME + 1 days); + vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(partialAmount); uint256 availableAfter = keepWhatsRaised.getAvailableRaisedAmount(); - // Verify - assertTrue(availableAfter < availableBefore); + // Verify - available is reduced by withdrawal plus fees + assertTrue(availableAfter < availableBefore - partialAmount); } function testWithdrawRevertWhenNotApproved() public { @@ -619,6 +659,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(DEADLINE + 1); vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedDisabled.selector); + vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(0); } @@ -632,6 +673,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(LAUNCH_TIME + 1 days); vm.expectRevert(); + vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(available + 1e18); } @@ -643,10 +685,12 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te // First withdrawal vm.warp(DEADLINE + 1); + vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(0); // Second withdrawal attempt vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedAlreadyWithdrawn.selector); + vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(0); } @@ -661,15 +705,18 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te // Try to withdraw vm.warp(DEADLINE + 1); vm.expectRevert(); + vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(0); } function testWithdrawWithMinimumFeeExemption() public { // Calculate pledge amount needed to have available amount above exemption after fees - // We need: pledgeAmount * (1 - totalFeePercentage) > MINIMUM_WITHDRAWAL_FOR_FEE_EXEMPTION - // totalFeePercentage = platformFee (10%) + vakiCommission (6%) = 16% - // So: pledgeAmount > MINIMUM_WITHDRAWAL_FOR_FEE_EXEMPTION / 0.84 - uint256 largePledge = (MINIMUM_WITHDRAWAL_FOR_FEE_EXEMPTION * 100) / 84 + 1000e18; // ~60,000e18 + // We need the available amount after all pledge fees to be > MINIMUM_WITHDRAWAL_FOR_FEE_EXEMPTION + // Total fees during pledge: platform (10%) + vaki (6%) + protocol (20%) = 36% + // So available = pledge * 0.64 + // We need: pledge * 0.64 > 50,000e18 + // Therefore: pledge > 78,125e18 + uint256 largePledge = 80_000e18; setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, 0); @@ -692,22 +739,22 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te uint256 ownerBalanceBefore = testToken.balanceOf(owner); vm.warp(DEADLINE + 1); + vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(0); uint256 ownerBalanceAfter = testToken.balanceOf(owner); uint256 received = ownerBalanceAfter - ownerBalanceBefore; - // Should only have protocol fee deducted, not flat fee - uint256 expectedProtocolFee = (availableAfterPledge * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; - uint256 expectedAmount = availableAfterPledge - expectedProtocolFee; - - assertApproxEqAbs(received, expectedAmount, 10, "Should receive amount minus only protocol fee"); + // For final withdrawal above exemption threshold, no flat fee is applied + // The owner should receive the full available amount + assertEq(received, availableAfterPledge, "Should receive full available amount without flat fee"); } function testWithdrawWithColombianCreatorTax() public { // Configure with Colombian creator + KeepWhatsRaised.FeeValues memory feeValues = _createFeeValues(); vm.prank(users.platform2AdminAddress); - keepWhatsRaised.configureTreasury(CONFIG_COLOMBIAN, CAMPAIGN_DATA, FEE_KEYS); + keepWhatsRaised.configureTreasury(CONFIG_COLOMBIAN, CAMPAIGN_DATA, FEE_KEYS, feeValues); // Make a pledge setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, PAYMENT_GATEWAY_FEE); @@ -728,6 +775,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te // Withdraw after deadline vm.warp(DEADLINE + 1); + vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(0); uint256 ownerBalanceAfter = testToken.balanceOf(owner); @@ -735,14 +783,13 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te // Calculate expected amount after Colombian tax uint256 flatFee = uint256(FLAT_FEE_VALUE); - uint256 protocolFee = (availableBeforeWithdraw * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; - uint256 amountAfterFees = availableBeforeWithdraw - flatFee - protocolFee; + uint256 amountAfterFlatFee = availableBeforeWithdraw - flatFee; - // Colombian tax: (amountAfterFees * 0.004) / 1.004 - uint256 colombianTax = (amountAfterFees * 40) / 10040; - uint256 expectedAmount = amountAfterFees - colombianTax; + // Colombian tax: (availableBeforeWithdraw * 0.004) / 1.004 + uint256 colombianTax = (availableBeforeWithdraw * 40) / 10040; + uint256 expectedAmount = amountAfterFlatFee - colombianTax; - assertApproxEqAbs(received, expectedAmount, 10, "Should receive amount minus fees and Colombian tax"); + assertApproxEqAbs(received, expectedAmount, 10, "Should receive amount minus flat fee and Colombian tax"); } /*////////////////////////////////////////////////////////////// @@ -767,10 +814,11 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.prank(users.backer1Address); keepWhatsRaised.claimRefund(tokenId); - // Calculate expected refund (pledge minus fees) + // Calculate expected refund (pledge minus all fees including protocol) uint256 platformFee = (TEST_PLEDGE_AMOUNT * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; uint256 vakiCommission = (TEST_PLEDGE_AMOUNT * uint256(VAKI_COMMISSION_VALUE)) / PERCENT_DIVIDER; - uint256 expectedRefund = TEST_PLEDGE_AMOUNT - PAYMENT_GATEWAY_FEE - platformFee - vakiCommission; + uint256 protocolFee = (TEST_PLEDGE_AMOUNT * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 expectedRefund = TEST_PLEDGE_AMOUNT - PAYMENT_GATEWAY_FEE - platformFee - vakiCommission - protocolFee; // Verify refund amount is pledge minus fees assertEq(testToken.balanceOf(users.backer1Address), balanceBefore + expectedRefund); @@ -818,10 +866,11 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.prank(users.backer1Address); keepWhatsRaised.claimRefund(tokenId); - // Calculate expected refund (pledge minus fees) + // Calculate expected refund (pledge minus all fees) uint256 platformFee = (TEST_PLEDGE_AMOUNT * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; uint256 vakiCommission = (TEST_PLEDGE_AMOUNT * uint256(VAKI_COMMISSION_VALUE)) / PERCENT_DIVIDER; - uint256 expectedRefund = TEST_PLEDGE_AMOUNT - PAYMENT_GATEWAY_FEE - platformFee - vakiCommission; + uint256 protocolFee = (TEST_PLEDGE_AMOUNT * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 expectedRefund = TEST_PLEDGE_AMOUNT - PAYMENT_GATEWAY_FEE - platformFee - vakiCommission - protocolFee; // Verify refund amount is pledge minus fees assertEq(testToken.balanceOf(users.backer1Address), balanceBefore + expectedRefund); @@ -862,6 +911,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.prank(users.platform2AdminAddress); keepWhatsRaised.approveWithdrawal(); vm.warp(DEADLINE + 1); + vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(0); // Try to claim refund @@ -998,13 +1048,15 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te //////////////////////////////////////////////////////////////*/ function testDisburseFees() public { - // Setup pledges and withdraw to generate fees + // Setup pledges - protocol fees are collected during pledge _setupPledges(); + // Approve and withdraw to generate withdrawal fees vm.prank(users.platform2AdminAddress); keepWhatsRaised.approveWithdrawal(); vm.warp(DEADLINE + 1); + vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(0); uint256 protocolBalanceBefore = testToken.balanceOf(users.protocolAdminAddress); @@ -1024,6 +1076,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.prank(users.platform2AdminAddress); keepWhatsRaised.approveWithdrawal(); vm.warp(DEADLINE + 1); + vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(0); _pauseTreasury(); @@ -1082,27 +1135,36 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te uint256 available = keepWhatsRaised.getAvailableRaisedAmount(); // First withdrawal: small amount that will incur cumulative fee - uint256 firstWithdrawal = 500e18; - // Second withdrawal: medium amount that will still incur cumulative fee - uint256 secondWithdrawal = 1000e18; + // Need to ensure available >= withdrawal + cumulativeFee + uint256 firstWithdrawal = 200e18; // Reduced to ensure enough for fee // First withdrawal vm.warp(LAUNCH_TIME + 1 days); uint256 availableBefore1 = keepWhatsRaised.getAvailableRaisedAmount(); + vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(firstWithdrawal); uint256 availableAfter1 = keepWhatsRaised.getAvailableRaisedAmount(); - // Verify first withdrawal reduced available amount - assertTrue(availableAfter1 < availableBefore1, "First withdrawal should reduce available"); + // Verify first withdrawal reduced available amount by withdrawal + fees + uint256 expectedReduction1 = firstWithdrawal + uint256(CUMULATIVE_FLAT_FEE_VALUE); + assertApproxEqAbs(availableBefore1 - availableAfter1, expectedReduction1, 10, "First withdrawal should reduce by amount plus cumulative fee"); // Second withdrawal - vm.warp(LAUNCH_TIME + 2 days); - uint256 availableBefore2 = keepWhatsRaised.getAvailableRaisedAmount(); - keepWhatsRaised.withdraw(secondWithdrawal); - uint256 availableAfter2 = keepWhatsRaised.getAvailableRaisedAmount(); - - // Verify second withdrawal reduced available amount - assertTrue(availableAfter2 < availableBefore2, "Second withdrawal should reduce available"); + // Calculate safe amount based on remaining balance + uint256 secondWithdrawal = 150e18; // Reduced to ensure enough for fee + + // Only do second withdrawal if we have enough funds + if (availableAfter1 >= secondWithdrawal + uint256(CUMULATIVE_FLAT_FEE_VALUE)) { + vm.warp(LAUNCH_TIME + 2 days); + uint256 availableBefore2 = keepWhatsRaised.getAvailableRaisedAmount(); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.withdraw(secondWithdrawal); + uint256 availableAfter2 = keepWhatsRaised.getAvailableRaisedAmount(); + + // Verify second withdrawal reduced available amount by withdrawal + fees + uint256 expectedReduction2 = secondWithdrawal + uint256(CUMULATIVE_FLAT_FEE_VALUE); + assertApproxEqAbs(availableBefore2 - availableAfter2, expectedReduction2, 10, "Second withdrawal should reduce by amount plus cumulative fee"); + } // Verify remaining amount assertTrue(keepWhatsRaised.getAvailableRaisedAmount() > 0, "Should still have funds available"); @@ -1110,7 +1172,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te function testWithdrawalRevertWhenFeesExceedAmount() public { // Make a small pledge - uint256 smallPledge = 2500e18; + uint256 smallPledge = 300e18; // Small enough that fees might exceed available setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, 0); vm.warp(LAUNCH_TIME); @@ -1122,9 +1184,14 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.prank(users.platform2AdminAddress); keepWhatsRaised.approveWithdrawal(); + // Try to withdraw partial amount that would cause available < withdrawal + fees vm.warp(LAUNCH_TIME + 1 days); + uint256 available = keepWhatsRaised.getAvailableRaisedAmount(); + + // Try to withdraw an amount that with fees would exceed available + uint256 withdrawAmount = available - 50e18; // Leave less than cumulative fee vm.expectRevert(); - keepWhatsRaised.withdraw(190e18); + keepWhatsRaised.withdraw(withdrawAmount); } function testZeroTipPledge() public { @@ -1152,7 +1219,8 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te uint256 available = keepWhatsRaised.getAvailableRaisedAmount(); uint256 platformFee = (TEST_PLEDGE_AMOUNT * uint256(PLATFORM_FEE_VALUE)) / PERCENT_DIVIDER; uint256 vakiCommission = (TEST_PLEDGE_AMOUNT * uint256(VAKI_COMMISSION_VALUE)) / PERCENT_DIVIDER; - uint256 totalFees = platformFee + vakiCommission + PAYMENT_GATEWAY_FEE; + uint256 protocolFee = (TEST_PLEDGE_AMOUNT * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 totalFees = platformFee + vakiCommission + PAYMENT_GATEWAY_FEE + protocolFee; uint256 expectedAvailable = TEST_PLEDGE_AMOUNT - totalFees; @@ -1171,6 +1239,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(DEADLINE + 1); vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedAlreadyWithdrawn.selector); + vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(0); } @@ -1182,8 +1251,9 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te // Testing multiple pledges with different fee structures // Configure Colombian creator for complex fee testing + KeepWhatsRaised.FeeValues memory feeValues = _createFeeValues(); vm.prank(users.platform2AdminAddress); - keepWhatsRaised.configureTreasury(CONFIG_COLOMBIAN, CAMPAIGN_DATA, FEE_KEYS); + keepWhatsRaised.configureTreasury(CONFIG_COLOMBIAN, CAMPAIGN_DATA, FEE_KEYS, feeValues); // Add rewards _setupReward(); @@ -1222,13 +1292,14 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te uint256 ownerBalanceBefore = testToken.balanceOf(owner); vm.warp(LAUNCH_TIME + 1 days); + vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(partialWithdrawAmount); uint256 ownerBalanceAfter = testToken.balanceOf(owner); uint256 netReceived = ownerBalanceAfter - ownerBalanceBefore; - // Verify withdrawal amount minus fees and Colombian tax - assertTrue(netReceived < partialWithdrawAmount); + // Verify withdrawal amount equals requested (fees deducted from available) + assertEq(netReceived, partialWithdrawAmount); } function testWithdrawalFeeStructure() public { @@ -1250,15 +1321,37 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te address owner = CampaignInfo(campaignAddress).owner(); uint256 balanceBefore = testToken.balanceOf(owner); + // Calculate available after pledge fees + uint256 availableBeforeWithdraw = keepWhatsRaised.getAvailableRaisedAmount(); + // Withdraw before deadline - should apply cumulative fee vm.warp(LAUNCH_TIME + 1 days); - keepWhatsRaised.withdraw(keepWhatsRaised.getAvailableRaisedAmount()); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.withdraw(availableBeforeWithdraw - uint256(CUMULATIVE_FLAT_FEE_VALUE) - 10); // Leave small buffer uint256 received = testToken.balanceOf(owner) - balanceBefore; assertTrue(received > 0, "Should receive something"); } + /*////////////////////////////////////////////////////////////// + FEE VALUE TESTS + //////////////////////////////////////////////////////////////*/ + + function testGetFeeValue() public { + // Test retrieval of stored fee values + assertEq(keepWhatsRaised.getFeeValue(FLAT_FEE_KEY), uint256(FLAT_FEE_VALUE)); + assertEq(keepWhatsRaised.getFeeValue(CUMULATIVE_FLAT_FEE_KEY), uint256(CUMULATIVE_FLAT_FEE_VALUE)); + assertEq(keepWhatsRaised.getFeeValue(PLATFORM_FEE_KEY), uint256(PLATFORM_FEE_VALUE)); + assertEq(keepWhatsRaised.getFeeValue(VAKI_COMMISSION_KEY), uint256(VAKI_COMMISSION_VALUE)); + } + + function testGetFeeValueForNonExistentKey() public { + // Should return 0 for non-existent keys + bytes32 nonExistentKey = keccak256("nonExistentFee"); + assertEq(keepWhatsRaised.getFeeValue(nonExistentKey), 0); + } + /*////////////////////////////////////////////////////////////// HELPER FUNCTIONS //////////////////////////////////////////////////////////////*/ @@ -1323,4 +1416,14 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.prank(users.platform2AdminAddress); keepWhatsRaised.pauseTreasury(message); } + + function _createFeeValues() internal pure returns (KeepWhatsRaised.FeeValues memory) { + KeepWhatsRaised.FeeValues memory feeValues; + feeValues.flatFeeValue = uint256(FLAT_FEE_VALUE); + feeValues.cumulativeFlatFeeValue = uint256(CUMULATIVE_FLAT_FEE_VALUE); + feeValues.grossPercentageFeeValues = new uint256[](2); + feeValues.grossPercentageFeeValues[0] = uint256(PLATFORM_FEE_VALUE); + feeValues.grossPercentageFeeValues[1] = uint256(VAKI_COMMISSION_VALUE); + return feeValues; + } } \ No newline at end of file From b25c2410a82b499c2706ffe039c403be1c9416b6 Mon Sep 17 00:00:00 2001 From: Mahabub Alahi Date: Tue, 12 Aug 2025 13:12:55 +0600 Subject: [PATCH 38/63] Update contracts doc --- .../CampaignInfo.sol/contract.CampaignInfo.md | 17 +- .../contract.CampaignInfoFactory.md | 8 +- .../GlobalParams.sol/contract.GlobalParams.md | 2 +- .../contract.TreasuryFactory.md | 2 +- .../interface.ICampaignData.md | 2 +- .../interface.ICampaignInfo.md | 11 +- .../interface.ICampaignInfoFactory.md | 8 +- .../interface.ICampaignTreasury.md | 2 +- .../interface.IGlobalParams.md | 2 +- .../interfaces/IItem.sol/interface.IItem.md | 2 +- .../IReward.sol/interface.IReward.md | 2 +- .../interface.ITreasuryFactory.md | 2 +- .../AllOrNothing.sol/contract.AllOrNothing.md | 2 +- .../contract.KeepWhatsRaised.md | 1155 ++++++++++++++++- .../abstract.AdminAccessChecker.md | 2 +- .../BaseTreasury.sol/abstract.BaseTreasury.md | 2 +- .../abstract.CampaignAccessChecker.md | 2 +- .../utils/Counters.sol/library.Counters.md | 2 +- .../FiatEnabled.sol/abstract.FiatEnabled.md | 2 +- .../ItemRegistry.sol/contract.ItemRegistry.md | 2 +- .../abstract.PausableCancellable.md | 2 +- .../abstract.TimestampChecker.md | 2 +- 22 files changed, 1198 insertions(+), 35 deletions(-) diff --git a/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md b/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md index fa856637..da768f0f 100644 --- a/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md +++ b/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md @@ -1,5 +1,5 @@ # CampaignInfo -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/CampaignInfo.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/CampaignInfo.sol) **Inherits:** [ICampaignData](/src/interfaces/ICampaignData.sol/interface.ICampaignData.md), [ICampaignInfo](/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md), Ownable, [PausableCancellable](/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md), [TimestampChecker](/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), [AdminAccessChecker](/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md), Initializable @@ -437,13 +437,12 @@ Updates the selection status of a platform for the campaign. ```solidity -function updateSelectedPlatform(bytes32 platformHash, bool selection) - external - override - onlyOwner - currentTimeIsLess(getLaunchTime()) - whenNotPaused - whenNotCancelled; +function updateSelectedPlatform( + bytes32 platformHash, + bool selection, + bytes32[] calldata platformDataKey, + bytes32[] calldata platformDataValue +) external override onlyOwner currentTimeIsLess(getLaunchTime()) whenNotPaused whenNotCancelled; ``` **Parameters** @@ -451,6 +450,8 @@ function updateSelectedPlatform(bytes32 platformHash, bool selection) |----|----|-----------| |`platformHash`|`bytes32`|The bytes32 identifier of the platform.| |`selection`|`bool`|The new selection status (true or false).| +|`platformDataKey`|`bytes32[]`|An array of platform-specific data keys.| +|`platformDataValue`|`bytes32[]`|An array of platform-specific data values.| ### _pauseCampaign diff --git a/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md b/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md index 9ae1b6f6..60704680 100644 --- a/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md +++ b/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md @@ -1,5 +1,5 @@ # CampaignInfoFactory -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/CampaignInfoFactory.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/CampaignInfoFactory.sol) **Inherits:** Initializable, [ICampaignInfoFactory](/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md), Ownable @@ -85,6 +85,12 @@ function _initialize(address treasuryFactoryAddress, address globalParams) exter Creates a new campaign information contract. +*IMPORTANT: Protocol and platform fees are retrieved at execution time and locked +permanently in the campaign contract. Users should verify current fees before +calling this function or using intermediate contracts that check fees haven't +changed from expected values. The protocol fee is stored as immutable in the cloned +contract and platform fees are stored during initialization.* + ```solidity function createCampaign( diff --git a/docs/src/src/GlobalParams.sol/contract.GlobalParams.md b/docs/src/src/GlobalParams.sol/contract.GlobalParams.md index 597a882a..8595aaff 100644 --- a/docs/src/src/GlobalParams.sol/contract.GlobalParams.md +++ b/docs/src/src/GlobalParams.sol/contract.GlobalParams.md @@ -1,5 +1,5 @@ # GlobalParams -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/GlobalParams.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/GlobalParams.sol) **Inherits:** [IGlobalParams](/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md), Ownable diff --git a/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md b/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md index b18d8e9a..adfc50cb 100644 --- a/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md +++ b/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md @@ -1,5 +1,5 @@ # TreasuryFactory -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/TreasuryFactory.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/TreasuryFactory.sol) **Inherits:** [ITreasuryFactory](/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md), [AdminAccessChecker](/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md) diff --git a/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md b/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md index ba386fea..5b924e5c 100644 --- a/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md +++ b/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md @@ -1,5 +1,5 @@ # ICampaignData -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/interfaces/ICampaignData.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/interfaces/ICampaignData.sol) An interface for managing campaign data in a CCP. diff --git a/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md b/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md index 92515c8e..d0e78480 100644 --- a/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md +++ b/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md @@ -1,5 +1,5 @@ # ICampaignInfo -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/interfaces/ICampaignInfo.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/interfaces/ICampaignInfo.sol) An interface for managing campaign information in a crowdfunding system. @@ -292,7 +292,12 @@ Updates the selection status of a platform for the campaign. ```solidity -function updateSelectedPlatform(bytes32 platformHash, bool selection) external; +function updateSelectedPlatform( + bytes32 platformHash, + bool selection, + bytes32[] calldata platformDataKey, + bytes32[] calldata platformDataValue +) external; ``` **Parameters** @@ -300,6 +305,8 @@ function updateSelectedPlatform(bytes32 platformHash, bool selection) external; |----|----|-----------| |`platformHash`|`bytes32`|The bytes32 identifier of the platform.| |`selection`|`bool`|The new selection status (true or false).| +|`platformDataKey`|`bytes32[]`|An array of platform-specific data keys.| +|`platformDataValue`|`bytes32[]`|An array of platform-specific data values.| ### paused diff --git a/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md b/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md index 83fdb398..8953d56c 100644 --- a/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md +++ b/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md @@ -1,5 +1,5 @@ # ICampaignInfoFactory -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/interfaces/ICampaignInfoFactory.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/interfaces/ICampaignInfoFactory.sol) **Inherits:** [ICampaignData](/src/interfaces/ICampaignData.sol/interface.ICampaignData.md) @@ -12,6 +12,12 @@ An interface for creating and managing campaign information contracts. Creates a new campaign information contract. +*IMPORTANT: Protocol and platform fees are retrieved at execution time and locked +permanently in the campaign contract. Users should verify current fees before +calling this function or using intermediate contracts that check fees haven't +changed from expected values. The protocol fee is stored as immutable in the cloned +contract and platform fees are stored during initialization.* + ```solidity function createCampaign( diff --git a/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md b/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md index 9d3a5eb6..a69caa0a 100644 --- a/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md +++ b/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md @@ -1,5 +1,5 @@ # ICampaignTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/interfaces/ICampaignTreasury.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/interfaces/ICampaignTreasury.sol) An interface for managing campaign treasury contracts. diff --git a/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md b/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md index da479844..4309f0e5 100644 --- a/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md +++ b/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md @@ -1,5 +1,5 @@ # IGlobalParams -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/interfaces/IGlobalParams.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/interfaces/IGlobalParams.sol) An interface for accessing and managing global parameters of the protocol. diff --git a/docs/src/src/interfaces/IItem.sol/interface.IItem.md b/docs/src/src/interfaces/IItem.sol/interface.IItem.md index c0a88b8d..c2a8852d 100644 --- a/docs/src/src/interfaces/IItem.sol/interface.IItem.md +++ b/docs/src/src/interfaces/IItem.sol/interface.IItem.md @@ -1,5 +1,5 @@ # IItem -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/interfaces/IItem.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/interfaces/IItem.sol) An interface for managing items and their attributes. diff --git a/docs/src/src/interfaces/IReward.sol/interface.IReward.md b/docs/src/src/interfaces/IReward.sol/interface.IReward.md index 19f51a56..29bd5932 100644 --- a/docs/src/src/interfaces/IReward.sol/interface.IReward.md +++ b/docs/src/src/interfaces/IReward.sol/interface.IReward.md @@ -1,5 +1,5 @@ # IReward -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/interfaces/IReward.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/interfaces/IReward.sol) An interface for managing rewards in a campaign. diff --git a/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md b/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md index e95ad0c5..a1410243 100644 --- a/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md +++ b/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md @@ -1,5 +1,5 @@ # ITreasuryFactory -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/interfaces/ITreasuryFactory.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/interfaces/ITreasuryFactory.sol) *Interface for the TreasuryFactory contract, which registers, approves, and deploys treasury clones.* diff --git a/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md b/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md index 8382b7c6..38e0393c 100644 --- a/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md +++ b/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md @@ -1,5 +1,5 @@ # AllOrNothing -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/treasuries/AllOrNothing.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/treasuries/AllOrNothing.sol) **Inherits:** [IReward](/src/interfaces/IReward.sol/interface.IReward.md), [BaseTreasury](/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md), [TimestampChecker](/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), ERC721Burnable diff --git a/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md b/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md index 286bd7bf..f86eda45 100644 --- a/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md +++ b/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md @@ -1,13 +1,172 @@ # KeepWhatsRaised - -[Git Source](https://github.com/ccprotocol/campaign-utils-contracts-aggregator/blob/79d78188e565502f83e2c0309c9a4ea3b35cee91/src/treasuries/KeepWhatsRaised.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/treasuries/KeepWhatsRaised.sol) **Inherits:** [IReward](/src/interfaces/IReward.sol/interface.IReward.md), [BaseTreasury](/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md), [TimestampChecker](/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), ERC721Burnable, [ICampaignData](/src/interfaces/ICampaignData.sol/interface.ICampaignData.md) A contract that keeps all the funds raised, regardless of the success condition. -_This contract inherits from the `AllOrNothing` contract and overrides the `_checkSuccessCondition` function to always return true._ + +## State Variables +### s_tokenToPledgedAmount + +```solidity +mapping(uint256 => uint256) private s_tokenToPledgedAmount; +``` + + +### s_tokenToTippedAmount + +```solidity +mapping(uint256 => uint256) private s_tokenToTippedAmount; +``` + + +### s_tokenToPaymentFee + +```solidity +mapping(uint256 => uint256) private s_tokenToPaymentFee; +``` + + +### s_reward + +```solidity +mapping(bytes32 => Reward) private s_reward; +``` + + +### s_processedPledges +Tracks whether a pledge with a specific ID has already been processed + + +```solidity +mapping(bytes32 => bool) public s_processedPledges; +``` + + +### s_paymentGatewayFees +Mapping to store payment gateway fees by unique pledge ID + + +```solidity +mapping(bytes32 => uint256) public s_paymentGatewayFees; +``` + + +### s_feeValues +Mapping that stores fee values indexed by their corresponding fee keys. + + +```solidity +mapping(bytes32 => uint256) private s_feeValues; +``` + + +### s_tokenIdCounter + +```solidity +Counters.Counter private s_tokenIdCounter; +``` + + +### s_rewardCounter + +```solidity +Counters.Counter private s_rewardCounter; +``` + + +### s_name + +```solidity +string private s_name; +``` + + +### s_symbol + +```solidity +string private s_symbol; +``` + + +### s_tip + +```solidity +uint256 private s_tip; +``` + + +### s_platformFee + +```solidity +uint256 private s_platformFee; +``` + + +### s_protocolFee + +```solidity +uint256 private s_protocolFee; +``` + + +### s_availablePledgedAmount + +```solidity +uint256 private s_availablePledgedAmount; +``` + + +### s_cancellationTime + +```solidity +uint256 private s_cancellationTime; +``` + + +### s_isWithdrawalApproved + +```solidity +bool private s_isWithdrawalApproved; +``` + + +### s_tipClaimed + +```solidity +bool private s_tipClaimed; +``` + + +### s_fundClaimed + +```solidity +bool private s_fundClaimed; +``` + + +### s_feeKeys + +```solidity +FeeKeys private s_feeKeys; +``` + + +### s_config + +```solidity +Config private s_config; +``` + + +### s_campaignData + +```solidity +CampaignData private s_campaignData; +``` + ## Functions @@ -35,6 +194,990 @@ function _checkSuccessCondition() internal pure override returns (bool); **Returns** -| Name | Type | Description | -| -------- | ------ | ------------------------------------- | -| `` | `bool` | Whether the success condition is met. | +|Name|Type|Description| +|----|----|-----------| +|`reward`|`Reward`|The details of the reward as a `Reward` struct.| + + +### getRaisedAmount + +Retrieves the total raised amount in the treasury. + + +```solidity +function getRaisedAmount() external view override returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The total raised amount as a uint256 value.| + + +### getAvailableRaisedAmount + +Retrieves the currently available raised amount in the treasury. + + +```solidity +function getAvailableRaisedAmount() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The current available raised amount as a uint256 value.| + + +### getLaunchTime + +Retrieves the campaign's launch time. + + +```solidity +function getLaunchTime() public view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The timestamp when the campaign was launched.| + + +### getDeadline + +Retrieves the campaign's deadline. + + +```solidity +function getDeadline() public view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The timestamp when the campaign ends.| + + +### getGoalAmount + +Retrieves the campaign's funding goal amount. + + +```solidity +function getGoalAmount() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The funding goal amount of the campaign.| + + +### getPaymentGatewayFee + +Retrieves the payment gateway fee for a given pledge ID. + + +```solidity +function getPaymentGatewayFee(bytes32 pledgeId) public view returns (uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`pledgeId`|`bytes32`|The unique identifier of the pledge.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The fixed gateway fee amount associated with the pledge ID.| + + +### getFeeValue + +*Retrieves the fee value associated with a specific fee key from storage.* + + +```solidity +function getFeeValue(bytes32 feeKey) public view returns (uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`feeKey`|`bytes32`|| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|{uint256} The fee value corresponding to the provided fee key.| + + +### setPaymentGatewayFee + +Sets the fixed payment gateway fee for a specific pledge. + + +```solidity +function setPaymentGatewayFee(bytes32 pledgeId, uint256 fee) + public + onlyPlatformAdmin(PLATFORM_HASH) + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`pledgeId`|`bytes32`|The unique identifier of the pledge.| +|`fee`|`uint256`|The gateway fee amount to be associated with the given pledge ID.| + + +### approveWithdrawal + +Approves the withdrawal of the treasury by the platform admin. + + +```solidity +function approveWithdrawal() + external + onlyPlatformAdmin(PLATFORM_HASH) + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled; +``` + +### configureTreasury + +*Configures the treasury for a campaign by setting the system parameters, +campaign-specific data, and fee configuration keys.* + + +```solidity +function configureTreasury( + Config memory config, + CampaignData memory campaignData, + FeeKeys memory feeKeys, + FeeValues memory feeValues +) + external + onlyPlatformAdmin(PLATFORM_HASH) + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`config`|`Config`|The configuration settings including withdrawal delay, refund delay, fee exemption threshold, and configuration lock period.| +|`campaignData`|`CampaignData`|The campaign-related metadata such as deadlines and funding goals.| +|`feeKeys`|`FeeKeys`|The set of keys used to reference applicable flat and percentage-based fees.| +|`feeValues`|`FeeValues`|The fee values corresponding to the fee keys.| + + +### updateDeadline + +*Updates the campaign's deadline.* + + +```solidity +function updateDeadline(uint256 deadline) + external + onlyPlatformAdminOrCampaignOwner + onlyBeforeConfigLock + whenNotPaused + whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`deadline`|`uint256`|The new deadline timestamp for the campaign. Requirements: - Must be called before the configuration lock period (see `onlyBeforeConfigLock`). - The new deadline must be a future timestamp.| + + +### updateGoalAmount + +*Updates the funding goal amount for the campaign.* + + +```solidity +function updateGoalAmount(uint256 goalAmount) + external + onlyPlatformAdminOrCampaignOwner + onlyBeforeConfigLock + whenNotPaused + whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`goalAmount`|`uint256`|The new goal amount. Requirements: - Must be called before the configuration lock period (see `onlyBeforeConfigLock`).| + + +### addRewards + +Adds multiple rewards in a batch. + +*This function allows for both reward tiers and non-reward tiers. +For both types, rewards must have non-zero value. +If items are specified (non-empty arrays), the itemId, itemValue, and itemQuantity arrays must match in length. +Empty arrays are allowed for both reward tiers and non-reward tiers.* + + +```solidity +function addRewards(bytes32[] calldata rewardNames, Reward[] calldata rewards) + external + onlyCampaignOwner + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`rewardNames`|`bytes32[]`|An array of reward names.| +|`rewards`|`Reward[]`|An array of `Reward` structs containing reward details.| + + +### removeReward + +Removes a reward from the campaign. + + +```solidity +function removeReward(bytes32 rewardName) + external + onlyCampaignOwner + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`rewardName`|`bytes32`|The name of the reward.| + + +### setFeeAndPledge + +Sets the payment gateway fee and executes a pledge in a single transaction. + + +```solidity +function setFeeAndPledge( + bytes32 pledgeId, + address backer, + uint256 pledgeAmount, + uint256 tip, + uint256 fee, + bytes32[] calldata reward, + bool isPledgeForAReward +) + external + onlyPlatformAdmin(PLATFORM_HASH) + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`pledgeId`|`bytes32`|The unique identifier of the pledge.| +|`backer`|`address`|The address of the backer making the pledge.| +|`pledgeAmount`|`uint256`|The amount of the pledge.| +|`tip`|`uint256`|An optional tip can be added during the process.| +|`fee`|`uint256`|The payment gateway fee to associate with this pledge.| +|`reward`|`bytes32[]`|An array of reward names.| +|`isPledgeForAReward`|`bool`|A boolean indicating whether this pledge is for a reward or without..| + + +### pledgeForAReward + +Allows a backer to pledge for a reward. + +*The first element of the `reward` array must be a reward tier and the other elements can be either reward tiers or non-reward tiers. +The non-reward tiers cannot be pledged for without a reward.* + + +```solidity +function pledgeForAReward(bytes32 pledgeId, address backer, uint256 tip, bytes32[] calldata reward) + public + currentTimeIsWithinRange(getLaunchTime(), getDeadline()) + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`pledgeId`|`bytes32`|The unique identifier of the pledge.| +|`backer`|`address`|The address of the backer making the pledge.| +|`tip`|`uint256`|An optional tip can be added during the process.| +|`reward`|`bytes32[]`|An array of reward names.| + + +### _pledgeForAReward + +Internal function that allows a backer to pledge for a reward with tokens transferred from a specified source. + +*The first element of the `reward` array must be a reward tier and the other elements can be either reward tiers or non-reward tiers. +The non-reward tiers cannot be pledged for without a reward. +This function is called internally by both public pledgeForAReward (with backer as token source) and +setFeeAndPledge (with admin as token source).* + + +```solidity +function _pledgeForAReward( + bytes32 pledgeId, + address backer, + uint256 tip, + bytes32[] calldata reward, + address tokenSource +) + internal + currentTimeIsWithinRange(getLaunchTime(), getDeadline()) + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`pledgeId`|`bytes32`|The unique identifier of the pledge.| +|`backer`|`address`|The address of the backer making the pledge (receives the NFT).| +|`tip`|`uint256`|An optional tip can be added during the process.| +|`reward`|`bytes32[]`|An array of reward names.| +|`tokenSource`|`address`|The address from which tokens will be transferred (either backer for direct calls or admin for setFeeAndPledge calls).| + + +### pledgeWithoutAReward + +Allows a backer to pledge without selecting a reward. + + +```solidity +function pledgeWithoutAReward(bytes32 pledgeId, address backer, uint256 pledgeAmount, uint256 tip) + public + currentTimeIsWithinRange(getLaunchTime(), getDeadline()) + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`pledgeId`|`bytes32`|The unique identifier of the pledge.| +|`backer`|`address`|The address of the backer making the pledge.| +|`pledgeAmount`|`uint256`|The amount of the pledge.| +|`tip`|`uint256`|An optional tip can be added during the process.| + + +### _pledgeWithoutAReward + +Internal function that allows a backer to pledge without selecting a reward with tokens transferred from a specified source. + +*This function is called internally by both public pledgeWithoutAReward (with backer as token source) and +setFeeAndPledge (with admin as token source).* + + +```solidity +function _pledgeWithoutAReward(bytes32 pledgeId, address backer, uint256 pledgeAmount, uint256 tip, address tokenSource) + internal + currentTimeIsWithinRange(getLaunchTime(), getDeadline()) + whenCampaignNotPaused + whenNotPaused + whenCampaignNotCancelled + whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`pledgeId`|`bytes32`|The unique identifier of the pledge.| +|`backer`|`address`|The address of the backer making the pledge (receives the NFT).| +|`pledgeAmount`|`uint256`|The amount of the pledge.| +|`tip`|`uint256`|An optional tip can be added during the process.| +|`tokenSource`|`address`|The address from which tokens will be transferred (either backer for direct calls or admin for setFeeAndPledge calls).| + + +### withdraw + +Withdraws funds from the treasury. + + +```solidity +function withdraw() public view override whenNotPaused whenNotCancelled; +``` + +### withdraw + +*Allows the campaign owner or platform admin to withdraw funds, applying required fees and taxes.* + + +```solidity +function withdraw(uint256 amount) + public + onlyPlatformAdminOrCampaignOwner + currentTimeIsLess(getDeadline() + s_config.withdrawalDelay) + whenNotPaused + whenNotCancelled + withdrawalEnabled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`amount`|`uint256`|The withdrawal amount (ignored for final withdrawals). Requirements: - Caller must be authorized. - Withdrawals must be enabled, not paused, and within the allowed time. - For partial withdrawals: - `amount` > 0 and `amount + fees` ≤ available balance. - For final withdrawals: - Available balance > 0 and fees ≤ available balance. Effects: - Deducts fees (flat, cumulative, and Colombian tax if applicable). - Updates available balance. - Transfers net funds to the recipient. Reverts: - If insufficient funds or invalid input. Emits: - `WithdrawalWithFeeSuccessful`.| + + +### claimRefund + +*Allows a backer to claim a refund associated with a specific pledge (token ID).* + + +```solidity +function claimRefund(uint256 tokenId) + external + currentTimeIsGreater(getLaunchTime()) + whenCampaignNotPaused + whenNotPaused; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|The ID of the token representing the backer's pledge. Requirements: - Refund delay must have passed. - The token must be eligible for a refund and not previously claimed.| + + +### disburseFees + +*Disburses all accumulated fees to the appropriate fee collector or treasury. +Requirements: +- Only callable when fees are available.* + + +```solidity +function disburseFees() public override whenNotPaused whenNotCancelled; +``` + +### claimTip + +*Allows an authorized claimer to collect tips contributed during the campaign. +Requirements: +- Caller must be authorized to claim tips. +- Tip amount must be non-zero.* + + +```solidity +function claimTip() external onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenNotPaused; +``` + +### claimFund + +*Allows the platform admin to claim the remaining funds from a campaign. +Requirements: +- Claim period must have started and funds must be available. +- Cannot be previously claimed.* + + +```solidity +function claimFund() external onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenNotPaused; +``` + +### cancelTreasury + +*This function is overridden to allow the platform admin and the campaign owner to cancel a treasury.* + + +```solidity +function cancelTreasury(bytes32 message) public override onlyPlatformAdminOrCampaignOwner; +``` + +### _checkSuccessCondition + +*Internal function to check the success condition for fee disbursement.* + + +```solidity +function _checkSuccessCondition() internal view virtual override returns (bool); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|Whether the success condition is met.| + + +### _pledge + + +```solidity +function _pledge( + bytes32 pledgeId, + address backer, + bytes32 reward, + uint256 pledgeAmount, + uint256 tip, + uint256 tokenId, + bytes32[] memory rewards, + address tokenSource +) private; +``` + +### _calculateNetAvailable + +Calculates the net amount available from a pledge after deducting +all applicable fees. + +*The function performs the following: +- Applies all configured gross percentage-based fees +- Applies payment gateway fee for the given pledge +- Applies protocol fee based on protocol configuration +- Accumulates total platform and protocol fees +- Records the total deducted fee for the token* + + +```solidity +function _calculateNetAvailable(bytes32 pledgeId, uint256 tokenId, uint256 pledgeAmount) internal returns (uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`pledgeId`|`bytes32`|The unique identifier of the pledge| +|`tokenId`|`uint256`|The token ID representing the pledge| +|`pledgeAmount`|`uint256`|The original pledged amount before deductions| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The net available amount after all fees are deducted| + + +### _checkRefundPeriodStatus + +Refund period logic: +- If campaign is cancelled: refund period is active until s_cancellationTime + s_config.refundDelay +- If campaign is not cancelled: refund period is active until deadline + s_config.refundDelay +- Before deadline (non-cancelled): not in refund period + +*Checks the refund period status based on campaign state* + +*This function handles both cancelled and non-cancelled campaign scenarios* + + +```solidity +function _checkRefundPeriodStatus(bool checkIfOver) internal view returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`checkIfOver`|`bool`|If true, returns whether refund period is over; if false, returns whether currently within refund period| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|bool Status based on checkIfOver parameter| + + +### supportsInterface + + +```solidity +function supportsInterface(bytes4 interfaceId) public view override returns (bool); +``` + +## Events +### Receipt +*Emitted when a backer makes a pledge.* + + +```solidity +event Receipt( + address indexed backer, + bytes32 indexed reward, + uint256 pledgeAmount, + uint256 tip, + uint256 tokenId, + bytes32[] rewards +); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`backer`|`address`|The address of the backer making the pledge.| +|`reward`|`bytes32`|The name of the reward.| +|`pledgeAmount`|`uint256`|The amount pledged.| +|`tip`|`uint256`|An optional tip can be added during the process.| +|`tokenId`|`uint256`|The ID of the token representing the pledge.| +|`rewards`|`bytes32[]`|An array of reward names.| + +### RewardsAdded +*Emitted when rewards are added to the campaign.* + + +```solidity +event RewardsAdded(bytes32[] rewardNames, Reward[] rewards); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`rewardNames`|`bytes32[]`|The names of the rewards.| +|`rewards`|`Reward[]`|The details of the rewards.| + +### RewardRemoved +*Emitted when a reward is removed from the campaign.* + + +```solidity +event RewardRemoved(bytes32 indexed rewardName); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`rewardName`|`bytes32`|The name of the reward.| + +### WithdrawalApproved +*Emitted when withdrawal functionality has been approved by the platform admin.* + + +```solidity +event WithdrawalApproved(); +``` + +### TreasuryConfigured +*Emitted when the treasury configuration is updated.* + + +```solidity +event TreasuryConfigured(Config config, CampaignData campaignData, FeeKeys feeKeys, FeeValues feeValues); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`config`|`Config`|The updated configuration parameters (e.g., delays, exemptions).| +|`campaignData`|`CampaignData`|The campaign-related data associated with the treasury setup.| +|`feeKeys`|`FeeKeys`|The set of keys used to determine applicable fees.| +|`feeValues`|`FeeValues`|The fee values corresponding to the fee keys.| + +### WithdrawalWithFeeSuccessful +*Emitted when a withdrawal is successfully processed along with the applied fee.* + + +```solidity +event WithdrawalWithFeeSuccessful(address indexed to, uint256 amount, uint256 fee); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`to`|`address`|The recipient address receiving the funds.| +|`amount`|`uint256`|The total amount withdrawn (excluding fee).| +|`fee`|`uint256`|The fee amount deducted from the withdrawal.| + +### TipClaimed +*Emitted when a tip is claimed from the contract.* + + +```solidity +event TipClaimed(uint256 amount, address indexed claimer); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`amount`|`uint256`|The amount of tip claimed.| +|`claimer`|`address`|The address that claimed the tip.| + +### FundClaimed +*Emitted when campaign or user's remaining funds are successfully claimed by the platform admin.* + + +```solidity +event FundClaimed(uint256 amount, address indexed claimer); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`amount`|`uint256`|The amount of funds claimed.| +|`claimer`|`address`|The address that claimed the funds.| + +### RefundClaimed +*Emitted when a refund is claimed.* + + +```solidity +event RefundClaimed(uint256 indexed tokenId, uint256 refundAmount, address indexed claimer); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|The ID of the token representing the pledge.| +|`refundAmount`|`uint256`|The refund amount claimed.| +|`claimer`|`address`|The address of the claimer.| + +### KeepWhatsRaisedDeadlineUpdated +*Emitted when the deadline of the campaign is updated.* + + +```solidity +event KeepWhatsRaisedDeadlineUpdated(uint256 newDeadline); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`newDeadline`|`uint256`|The new deadline.| + +### KeepWhatsRaisedGoalAmountUpdated +*Emitted when the goal amount for a campaign is updated.* + + +```solidity +event KeepWhatsRaisedGoalAmountUpdated(uint256 newGoalAmount); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`newGoalAmount`|`uint256`|The new goal amount set for the campaign.| + +### KeepWhatsRaisedPaymentGatewayFeeSet +*Emitted when a gateway fee is set for a specific pledge.* + + +```solidity +event KeepWhatsRaisedPaymentGatewayFeeSet(bytes32 indexed pledgeId, uint256 fee); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`pledgeId`|`bytes32`|The unique identifier of the pledge.| +|`fee`|`uint256`|The amount of the payment gateway fee set.| + +## Errors +### KeepWhatsRaisedUnAuthorized +*Emitted when an unauthorized action is attempted.* + + +```solidity +error KeepWhatsRaisedUnAuthorized(); +``` + +### KeepWhatsRaisedInvalidInput +*Emitted when an invalid input is detected.* + + +```solidity +error KeepWhatsRaisedInvalidInput(); +``` + +### KeepWhatsRaisedRewardExists +*Emitted when a `Reward` already exists for given input.* + + +```solidity +error KeepWhatsRaisedRewardExists(); +``` + +### KeepWhatsRaisedDisabled +*Emitted when anyone called a disabled function.* + + +```solidity +error KeepWhatsRaisedDisabled(); +``` + +### KeepWhatsRaisedAlreadyEnabled +*Emitted when any functionality is already enabled and cannot be re-enabled.* + + +```solidity +error KeepWhatsRaisedAlreadyEnabled(); +``` + +### KeepWhatsRaisedInsufficientFundsForWithdrawalAndFee +*Emitted when a withdrawal attempt exceeds the available funds after accounting for the fee.* + + +```solidity +error KeepWhatsRaisedInsufficientFundsForWithdrawalAndFee( + uint256 availableAmount, uint256 withdrawalAmount, uint256 fee +); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`availableAmount`|`uint256`|The maximum amount that can be withdrawn.| +|`withdrawalAmount`|`uint256`|The attempted withdrawal amount.| +|`fee`|`uint256`|The fee that would be applied to the withdrawal.| + +### KeepWhatsRaisedInsufficientFundsForFee +Emitted when the fee exceeds the requested withdrawal amount. + + +```solidity +error KeepWhatsRaisedInsufficientFundsForFee(uint256 withdrawalAmount, uint256 fee); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`withdrawalAmount`|`uint256`|The amount requested for withdrawal.| +|`fee`|`uint256`|The calculated fee, which is greater than the withdrawal amount.| + +### KeepWhatsRaisedAlreadyWithdrawn +*Emitted when a withdrawal has already been made and cannot be repeated.* + + +```solidity +error KeepWhatsRaisedAlreadyWithdrawn(); +``` + +### KeepWhatsRaisedAlreadyClaimed +*Emitted when funds or rewards have already been claimed for the given context.* + + +```solidity +error KeepWhatsRaisedAlreadyClaimed(); +``` + +### KeepWhatsRaisedNotClaimable +*Emitted when a token or pledge is not eligible for claiming (e.g., claim period not reached or not valid).* + + +```solidity +error KeepWhatsRaisedNotClaimable(uint256 tokenId); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|The ID of the token that was attempted to be claimed.| + +### KeepWhatsRaisedNotClaimableAdmin +*Emitted when an admin attempts to claim funds that are not yet claimable according to the rules.* + + +```solidity +error KeepWhatsRaisedNotClaimableAdmin(); +``` + +### KeepWhatsRaisedConfigLocked +*Emitted when a configuration change is attempted during the lock period.* + + +```solidity +error KeepWhatsRaisedConfigLocked(); +``` + +### KeepWhatsRaisedDisbursementBlocked +*Emitted when a disbursement is attempted before the refund period has ended.* + + +```solidity +error KeepWhatsRaisedDisbursementBlocked(); +``` + +### KeepWhatsRaisedPledgeAlreadyProcessed +*Emitted when a pledge is submitted using a pledgeId that has already been processed.* + + +```solidity +error KeepWhatsRaisedPledgeAlreadyProcessed(bytes32 pledgeId); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`pledgeId`|`bytes32`|The unique identifier of the pledge that was already used.| + +## Structs +### FeeKeys +*Represents keys used to reference different fee configurations. +These keys are typically used to look up fee values stored in `s_platformData`.* + + +```solidity +struct FeeKeys { + bytes32 flatFeeKey; + bytes32 cumulativeFlatFeeKey; + bytes32[] grossPercentageFeeKeys; +} +``` + +### FeeValues +*Represents the complete fee structure values for treasury operations. +These values correspond to the fees that will be applied to transactions +and are typically retrieved using keys from `FeeKeys` struct.* + + +```solidity +struct FeeValues { + uint256 flatFeeValue; + uint256 cumulativeFlatFeeValue; + uint256[] grossPercentageFeeValues; +} +``` + +### Config +*System configuration parameters related to withdrawal and refund behavior.* + + +```solidity +struct Config { + uint256 minimumWithdrawalForFeeExemption; + uint256 withdrawalDelay; + uint256 refundDelay; + uint256 configLockPeriod; + bool isColombianCreator; +} +``` + diff --git a/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md b/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md index c8c5e343..5b28fcfd 100644 --- a/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md +++ b/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md @@ -1,5 +1,5 @@ # AdminAccessChecker -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/utils/AdminAccessChecker.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/utils/AdminAccessChecker.sol) *This abstract contract provides access control mechanisms to restrict the execution of specific functions to authorized protocol administrators and platform administrators.* diff --git a/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md b/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md index 2696fddf..0b841fc6 100644 --- a/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md +++ b/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md @@ -1,5 +1,5 @@ # BaseTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/utils/BaseTreasury.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/utils/BaseTreasury.sol) **Inherits:** Initializable, [ICampaignTreasury](/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md), [CampaignAccessChecker](/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md), [PausableCancellable](/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md) diff --git a/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md b/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md index 5e7e86f3..b4bec1f2 100644 --- a/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md +++ b/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md @@ -1,5 +1,5 @@ # CampaignAccessChecker -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/utils/CampaignAccessChecker.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/utils/CampaignAccessChecker.sol) *This abstract contract provides access control mechanisms to restrict the execution of specific functions to authorized protocol administrators, platform administrators, and campaign owners.* diff --git a/docs/src/src/utils/Counters.sol/library.Counters.md b/docs/src/src/utils/Counters.sol/library.Counters.md index e77e31ec..21571265 100644 --- a/docs/src/src/utils/Counters.sol/library.Counters.md +++ b/docs/src/src/utils/Counters.sol/library.Counters.md @@ -1,5 +1,5 @@ # Counters -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/utils/Counters.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/utils/Counters.sol) ## Functions diff --git a/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md b/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md index 931e48e2..7a09c472 100644 --- a/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md +++ b/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md @@ -1,5 +1,5 @@ # FiatEnabled -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/utils/FiatEnabled.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/utils/FiatEnabled.sol) A contract that provides functionality for tracking and managing fiat transactions. This contract allows tracking the amount of fiat raised, individual fiat transactions, and the state of fiat fee disbursement. diff --git a/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md b/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md index daf05851..ebea1819 100644 --- a/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md +++ b/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md @@ -1,5 +1,5 @@ # ItemRegistry -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/utils/ItemRegistry.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/utils/ItemRegistry.sol) **Inherits:** [IItem](/src/interfaces/IItem.sol/interface.IItem.md), Context diff --git a/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md b/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md index 971399a6..c9a5c6b9 100644 --- a/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md +++ b/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md @@ -1,5 +1,5 @@ # PausableCancellable -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/utils/PausableCancellable.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/utils/PausableCancellable.sol) Abstract contract providing pause and cancel state management with events and modifiers diff --git a/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md b/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md index 07857448..597abd3a 100644 --- a/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md +++ b/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md @@ -1,5 +1,5 @@ # TimestampChecker -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/7ba93df0a979ce4ef420098855e6b4bfadbb6ecd/src/utils/TimestampChecker.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/utils/TimestampChecker.sol) A contract that provides timestamp-related checks for contract functions. From 8e8c72767e1529cd81b47398db396660e92b5d60 Mon Sep 17 00:00:00 2001 From: mahabubAlahi <32974385+mahabubAlahi@users.noreply.github.com> Date: Tue, 19 Aug 2025 16:59:51 +0600 Subject: [PATCH 39/63] Update Payment Treasury (#28) * Refactor buyer address with buyer id in payment (#25) * Refactor buyer address with buyer id in payment * Fix payment treasury tests * Update payment and refund - Add support for crypto payment - Add direct claim refund for buyer * Fix the disbursement fee and withdrawal functionality - Add support for multiple withdrawals with perfect fee disbursement * Fix potential payment ID collusion part * Add input validation to `claimRefund` function in PaymentTreasury * Update `claimRefund(paymentId)` in payment treasury - Add support for a platform admin who can call claimRefund on behalf of buyers - Update the jsdoc - Leverage this claim refund function in the payment treasury contract * Fix redundant fee disbursement logic * Add payment management function overrides to PaymentTreasury - createPayment - createCryptoPayment - cancelPayment - confirmPayment - confirmPaymentBatch * Refactor `createCryptoPayment` function name to `processCryptoPayment` - Better reflects the immediate processing and confirmation of crypto payments * Refactor withdraw and disburseFee in payment treasury * Add extra validation to `claimRefund` in payment treasury --- src/interfaces/ICampaignPaymentTreasury.sol | 27 ++- src/treasuries/PaymentTreasury.sol | 64 ++++- src/utils/BasePaymentTreasury.sol | 228 ++++++++++++++---- .../PaymentTreasury/PaymentTreasury.t.sol | 18 +- .../PaymentTreasuryFunction.t.sol | 10 +- test/foundry/unit/PaymentTreasury.t.sol | 88 +++---- 6 files changed, 334 insertions(+), 101 deletions(-) diff --git a/src/interfaces/ICampaignPaymentTreasury.sol b/src/interfaces/ICampaignPaymentTreasury.sol index cd9f62ae..db7631d8 100644 --- a/src/interfaces/ICampaignPaymentTreasury.sol +++ b/src/interfaces/ICampaignPaymentTreasury.sol @@ -10,19 +10,34 @@ interface ICampaignPaymentTreasury { /** * @notice Creates a new payment entry with the specified details. * @param paymentId A unique identifier for the payment. - * @param buyerAddress The address of the buyer initiating the payment. + * @param buyerId The id of the buyer initiating the payment. * @param itemId The identifier of the item being purchased. * @param amount The amount to be paid for the item. * @param expiration The timestamp after which the payment expires. */ function createPayment( bytes32 paymentId, - address buyerAddress, + bytes32 buyerId, bytes32 itemId, uint256 amount, uint256 expiration ) external; + /** + * @notice Allows a buyer to make a direct crypto payment for an item. + * @dev This function transfers tokens directly from the buyer's wallet and confirms the payment immediately. + * @param paymentId The unique identifier of the payment. + * @param itemId The identifier of the item being purchased. + * @param buyerAddress The address of the buyer making the payment. + * @param amount The amount to be paid for the item. + */ + function processCryptoPayment( + bytes32 paymentId, + bytes32 itemId, + address buyerAddress, + uint256 amount + ) external; + /** * @notice Cancels an existing payment with the given payment ID. * @param paymentId The unique identifier of the payment to cancel. @@ -64,6 +79,14 @@ interface ICampaignPaymentTreasury { */ function claimRefund(bytes32 paymentId, address refundAddress) external; + /** + * @notice Allows buyers to claim refunds for crypto payments, or platform admin to process refunds on behalf of buyers. + * @param paymentId The unique identifier of the refundable payment. + */ + function claimRefund( + bytes32 paymentId + ) external; + /** * @notice Retrieves the platform identifier associated with the treasury. * @return The platform identifier as a bytes32 value. diff --git a/src/treasuries/PaymentTreasury.sol b/src/treasuries/PaymentTreasury.sol index e9f18e1f..3c9d146c 100644 --- a/src/treasuries/PaymentTreasury.sol +++ b/src/treasuries/PaymentTreasury.sol @@ -48,6 +48,58 @@ contract PaymentTreasury is return s_symbol; } + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function createPayment( + bytes32 paymentId, + bytes32 buyerId, + bytes32 itemId, + uint256 amount, + uint256 expiration + ) public override whenNotPaused whenNotCancelled { + super.createPayment(paymentId, buyerId, itemId, amount, expiration); + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function processCryptoPayment( + bytes32 paymentId, + bytes32 itemId, + address buyerAddress, + uint256 amount + ) public override whenNotPaused whenNotCancelled { + super.processCryptoPayment(paymentId, itemId, buyerAddress, amount); + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function cancelPayment( + bytes32 paymentId + ) public override whenNotPaused whenNotCancelled { + super.cancelPayment(paymentId); + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function confirmPayment( + bytes32 paymentId + ) public override whenNotPaused whenNotCancelled { + super.confirmPayment(paymentId); + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function confirmPaymentBatch( + bytes32[] calldata paymentIds + ) public override whenNotPaused whenNotCancelled { + super.confirmPaymentBatch(paymentIds); + } + /** * @inheritdoc ICampaignPaymentTreasury */ @@ -58,6 +110,15 @@ contract PaymentTreasury is super.claimRefund(paymentId, refundAddress); } + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function claimRefund( + bytes32 paymentId + ) public override whenNotPaused whenNotCancelled { + super.claimRefund(paymentId); + } + /** * @inheritdoc ICampaignPaymentTreasury */ @@ -67,9 +128,6 @@ contract PaymentTreasury is whenNotPaused whenNotCancelled { - if (s_feesDisbursed) { - revert PaymentTreasuryFeeAlreadyDisbursed(); - } super.disburseFees(); } diff --git a/src/utils/BasePaymentTreasury.sol b/src/utils/BasePaymentTreasury.sol index 86dbddf3..4b167401 100644 --- a/src/utils/BasePaymentTreasury.sol +++ b/src/utils/BasePaymentTreasury.sol @@ -23,14 +23,26 @@ abstract contract BasePaymentTreasury is bytes32 internal PLATFORM_HASH; uint256 internal PLATFORM_FEE_PERCENT; IERC20 internal TOKEN; - bool internal s_feesDisbursed; - + uint256 internal s_platformFee; + uint256 internal s_protocolFee; + /** + * @dev Stores information about a payment in the treasury. + * @param buyerAddress The address of the buyer who made the payment. + * @param buyerId The ID of the buyer. + * @param itemId The identifier of the item being purchased. + * @param amount The amount to be paid for the item. + * @param expiration The timestamp after which the payment expires. + * @param isConfirmed Boolean indicating whether the payment has been confirmed. + * @param isCryptoPayment Boolean indicating whether the payment is made using direct crypto payment. + */ struct PaymentInfo { address buyerAddress; + bytes32 buyerId; bytes32 itemId; uint256 amount; uint256 expiration; bool isConfirmed; + bool isCryptoPayment; } mapping (bytes32 => PaymentInfo) internal s_payment; @@ -40,18 +52,22 @@ abstract contract BasePaymentTreasury is /** * @dev Emitted when a new payment is created. + * @param buyerAddress The address of the buyer making the payment. * @param paymentId The unique identifier of the payment. - * @param buyerAddress The address of the buyer who initiated the payment. + * @param buyerId The id of the buyer. * @param itemId The identifier of the item being purchased. * @param amount The amount to be paid for the item. * @param expiration The timestamp after which the payment expires. + * @param isCryptoPayment Boolean indicating whether the payment is made using direct crypto payment. */ event PaymentCreated( + address buyerAddress, bytes32 indexed paymentId, - address indexed buyerAddress, + bytes32 buyerId, bytes32 indexed itemId, uint256 amount, - uint256 expiration + uint256 expiration, + bool isCryptoPayment ); /** @@ -86,11 +102,12 @@ abstract contract BasePaymentTreasury is event FeesDisbursed(uint256 protocolShare, uint256 platformShare); /** - * @notice Emitted when a withdrawal is successful. - * @param to The recipient of the withdrawal. - * @param amount The amount withdrawn. + * @dev Emitted when a withdrawal is successfully processed along with the applied fee. + * @param to The recipient address receiving the funds. + * @param amount The total amount withdrawn (excluding fee). + * @param fee The fee amount deducted from the withdrawal. */ - event WithdrawalSuccessful(address indexed to, uint256 amount); + event WithdrawalWithFeeSuccessful(address indexed to, uint256 amount, uint256 fee); /** * @dev Emitted when a refund is claimed. @@ -156,6 +173,20 @@ abstract contract BasePaymentTreasury is */ error PaymentTreasuryAlreadyWithdrawn(); + /** + * @dev This error is thrown when an operation is attempted on a crypto payment that is only valid for non-crypto payments. + * @param paymentId The unique identifier of the payment that caused the error. + */ + error PaymentTreasuryCryptoPayment(bytes32 paymentId); + + /** + * @notice Emitted when the fee exceeds the requested withdrawal amount. + * + * @param withdrawalAmount The amount requested for withdrawal. + * @param fee The calculated fee, which is greater than the withdrawal amount. + */ + error PaymentTreasuryInsufficientFundsForFee(uint256 withdrawalAmount, uint256 fee); + function __BaseContract_init( bytes32 platformHash, address infoAddress @@ -179,6 +210,23 @@ abstract contract BasePaymentTreasury is _; } + /** + * @notice Ensures that the caller is either the payment's buyer or the platform admin. + * @param paymentId The unique identifier of the payment to validate access for. + */ + modifier onlyBuyerOrPlatformAdmin(bytes32 paymentId) { + PaymentInfo memory payment = s_payment[paymentId]; + address buyerAddress = payment.buyerAddress; + + if ( + msg.sender != buyerAddress && + msg.sender != INFO.getPlatformAdminAddress(PLATFORM_HASH) + ) { + revert PaymentTreasuryPaymentNotClaimable(paymentId); + } + _; + } + /** * @inheritdoc ICampaignPaymentTreasury */ @@ -212,13 +260,13 @@ abstract contract BasePaymentTreasury is */ function createPayment( bytes32 paymentId, - address buyerAddress, + bytes32 buyerId, bytes32 itemId, uint256 amount, uint256 expiration ) public override virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { - if(buyerAddress == address(0) || + if(buyerId == ZERO_BYTES || amount == 0 || expiration <= block.timestamp || paymentId == ZERO_BYTES || @@ -227,30 +275,82 @@ abstract contract BasePaymentTreasury is revert PaymentTreasuryInvalidInput(); } - if(s_payment[paymentId].buyerAddress != address(0)){ + if(s_payment[paymentId].buyerId != ZERO_BYTES || s_payment[paymentId].buyerAddress != address(0)){ revert PaymentTreasuryPaymentAlreadyExist(paymentId); } s_payment[paymentId] = PaymentInfo({ - buyerAddress: buyerAddress, + buyerId: buyerId, + buyerAddress: address(0), itemId: itemId, amount: amount, expiration: expiration, - isConfirmed: false + isConfirmed: false, + isCryptoPayment: false }); s_pendingPaymentAmount += amount; emit PaymentCreated( + address(0), paymentId, - buyerAddress, + buyerId, itemId, amount, - expiration + expiration, + false ); } + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function processCryptoPayment( + bytes32 paymentId, + bytes32 itemId, + address buyerAddress, + uint256 amount + ) public override virtual whenCampaignNotPaused whenCampaignNotCancelled { + + if(buyerAddress == address(0) || + amount == 0 || + paymentId == ZERO_BYTES || + itemId == ZERO_BYTES + ){ + revert PaymentTreasuryInvalidInput(); + } + + if(s_payment[paymentId].buyerAddress != address(0) || s_payment[paymentId].buyerId != ZERO_BYTES){ + revert PaymentTreasuryPaymentAlreadyExist(paymentId); + } + + TOKEN.safeTransferFrom(buyerAddress, address(this), amount); + + s_payment[paymentId] = PaymentInfo({ + buyerId: ZERO_BYTES, + buyerAddress: buyerAddress, + itemId: itemId, + amount: amount, + expiration: 0, + isConfirmed: true, + isCryptoPayment: true + }); + + s_confirmedPaymentAmount += amount; + s_availableConfirmedPaymentAmount += amount; + + emit PaymentCreated( + buyerAddress, + paymentId, + ZERO_BYTES, + itemId, + amount, + 0, + true + ); + } + /** * @inheritdoc ICampaignPaymentTreasury */ @@ -313,22 +413,28 @@ abstract contract BasePaymentTreasury is } + /** + * @inheritdoc ICampaignPaymentTreasury + */ function claimRefund( bytes32 paymentId, address refundAddress ) public override virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { + if(refundAddress == address(0)){ + revert PaymentTreasuryInvalidInput(); + } PaymentInfo memory payment = s_payment[paymentId]; + uint256 amountToRefund = payment.amount; + uint256 availablePaymentAmount = s_availableConfirmedPaymentAmount; - if (payment.buyerAddress == address(0)) { + if (payment.buyerId == ZERO_BYTES) { revert PaymentTreasuryPaymentNotExist(paymentId); } if(!payment.isConfirmed){ revert PaymentTreasuryPaymentNotConfirmed(paymentId); } - - uint256 amountToRefund = payment.amount; - if (amountToRefund == 0) { + if (amountToRefund == 0 || availablePaymentAmount < amountToRefund) { revert PaymentTreasuryPaymentNotClaimable(paymentId); } @@ -341,6 +447,34 @@ abstract contract BasePaymentTreasury is emit RefundClaimed(paymentId, amountToRefund, refundAddress); } + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function claimRefund( + bytes32 paymentId + ) public override virtual onlyBuyerOrPlatformAdmin(paymentId) whenCampaignNotPaused whenCampaignNotCancelled + { + PaymentInfo memory payment = s_payment[paymentId]; + address buyerAddress = payment.buyerAddress; + uint256 amountToRefund = payment.amount; + uint256 availablePaymentAmount = s_availableConfirmedPaymentAmount; + + if (buyerAddress == address(0)) { + revert PaymentTreasuryPaymentNotExist(paymentId); + } + if (amountToRefund == 0 || availablePaymentAmount < amountToRefund) { + revert PaymentTreasuryPaymentNotClaimable(paymentId); + } + + delete s_payment[paymentId]; + + s_confirmedPaymentAmount -= amountToRefund; + s_availableConfirmedPaymentAmount -= amountToRefund; + + TOKEN.safeTransfer(buyerAddress, amountToRefund); + emit RefundClaimed(paymentId, amountToRefund, buyerAddress); + } + /** * @inheritdoc ICampaignPaymentTreasury */ @@ -351,26 +485,17 @@ abstract contract BasePaymentTreasury is whenCampaignNotPaused whenCampaignNotCancelled { - if (!_checkSuccessCondition()) { - revert PaymentTreasurySuccessConditionNotFulfilled(); - } - uint256 balance = s_availableConfirmedPaymentAmount; - uint256 protocolShare = (balance * INFO.getProtocolFeePercent()) / - PERCENT_DIVIDER; - uint256 platformShare = (balance * - INFO.getPlatformFeePercent(PLATFORM_HASH)) / PERCENT_DIVIDER; - - s_availableConfirmedPaymentAmount -= protocolShare; - s_availableConfirmedPaymentAmount -= platformShare; - + uint256 protocolShare = s_protocolFee; + uint256 platformShare = s_platformFee; + (s_protocolFee, s_platformFee) = (0, 0); + TOKEN.safeTransfer(INFO.getProtocolAdminAddress(), protocolShare); - + TOKEN.safeTransfer( INFO.getPlatformAdminAddress(PLATFORM_HASH), platformShare ); - - s_feesDisbursed = true; + emit FeesDisbursed(protocolShare, platformShare); } @@ -384,20 +509,36 @@ abstract contract BasePaymentTreasury is whenCampaignNotPaused whenCampaignNotCancelled { - if (!s_feesDisbursed) { - revert PaymentTreasuryFeeNotDisbursed(); + if (!_checkSuccessCondition()) { + revert PaymentTreasurySuccessConditionNotFulfilled(); } + + address recipient = INFO.owner(); uint256 balance = s_availableConfirmedPaymentAmount; if (balance == 0) { revert PaymentTreasuryAlreadyWithdrawn(); } - address recipient = INFO.owner(); + // Calculate fees + uint256 protocolShare = (balance * INFO.getProtocolFeePercent()) / PERCENT_DIVIDER; + uint256 platformShare = (balance * INFO.getPlatformFeePercent(PLATFORM_HASH)) / PERCENT_DIVIDER; + + s_protocolFee += protocolShare; + s_platformFee += platformShare; + + uint256 totalFee = protocolShare + platformShare; + + if(balance < totalFee) { + revert PaymentTreasuryInsufficientFundsForFee(balance, totalFee); + } + uint256 withdrawalAmount = balance - totalFee; + + // Reset balance s_availableConfirmedPaymentAmount = 0; - TOKEN.safeTransfer(recipient, balance); + TOKEN.safeTransfer(recipient, withdrawalAmount); - emit WithdrawalSuccessful(recipient, balance); + emit WithdrawalWithFeeSuccessful(recipient, withdrawalAmount, totalFee); } /** @@ -449,12 +590,13 @@ abstract contract BasePaymentTreasury is * - The payment does not exist. * - The payment has already been confirmed. * - The payment has already expired. + * - The payment is a crypto payment * @param paymentId The unique identifier of the payment to validate. */ function _validatePaymentForAction(bytes32 paymentId) internal view { PaymentInfo memory payment = s_payment[paymentId]; - if (payment.buyerAddress == address(0)) { + if (payment.buyerId == ZERO_BYTES) { revert PaymentTreasuryPaymentNotExist(paymentId); } @@ -465,6 +607,10 @@ abstract contract BasePaymentTreasury is if (payment.expiration <= block.timestamp) { revert PaymentTreasuryPaymentAlreadyExpired(paymentId); } + + if (payment.isCryptoPayment) { + revert PaymentTreasuryCryptoPayment(paymentId); + } } /** diff --git a/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol b/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol index 8f6d8f79..9a411fd3 100644 --- a/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol +++ b/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol @@ -24,6 +24,9 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te uint256 internal constant PAYMENT_AMOUNT_1 = 1000e18; uint256 internal constant PAYMENT_AMOUNT_2 = 2000e18; uint256 internal constant PAYMENT_EXPIRATION = 7 days; + bytes32 internal constant BUYER_ID_1 = keccak256("buyer1"); + bytes32 internal constant BUYER_ID_2 = keccak256("buyer2"); + bytes32 internal constant BUYER_ID_3 = keccak256("buyer3"); /// @dev Initial dependent functions setup included for PaymentTreasury Integration Tests. function setUp() public virtual override { @@ -137,13 +140,13 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te function createPayment( address caller, bytes32 paymentId, - address buyerAddress, + bytes32 buyerId, bytes32 itemId, uint256 amount, uint256 expiration ) internal { vm.prank(caller); - paymentTreasury.createPayment(paymentId, buyerAddress, itemId, amount, expiration); + paymentTreasury.createPayment(paymentId, buyerId, itemId, amount, expiration); } /** @@ -260,9 +263,10 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te */ function _createAndFundPayment( bytes32 paymentId, - address buyerAddress, + bytes32 buyerId, bytes32 itemId, - uint256 amount + uint256 amount, + address buyerAddress ) internal { // Fund buyer deal(address(testToken), buyerAddress, amount); @@ -273,7 +277,7 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te // Create payment uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; - createPayment(users.platform1AdminAddress, paymentId, buyerAddress, itemId, amount, expiration); + createPayment(users.platform1AdminAddress, paymentId, buyerId, itemId, amount, expiration); // Transfer tokens from buyer to treasury vm.prank(buyerAddress); @@ -284,7 +288,7 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te * @notice Helper to create multiple test payments */ function _createTestPayments() internal { - _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); - _createAndFundPayment(PAYMENT_ID_2, users.backer2Address, ITEM_ID_2, PAYMENT_AMOUNT_2); + _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); + _createAndFundPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, PAYMENT_AMOUNT_2, users.backer2Address); } } \ No newline at end of file diff --git a/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol b/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol index ce193e9a..95b3dce4 100644 --- a/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol +++ b/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol @@ -22,9 +22,10 @@ contract PaymentTreasuryFunction_Integration_Test is function test_confirmPayment() public { _createAndFundPayment( PAYMENT_ID_1, - users.backer1Address, + BUYER_ID_1, ITEM_ID_1, - PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_1, + users.backer1Address ); assertEq(testToken.balanceOf(treasuryAddress), PAYMENT_AMOUNT_1); @@ -73,9 +74,10 @@ contract PaymentTreasuryFunction_Integration_Test is function test_claimRefund() public { _createAndFundPayment( PAYMENT_ID_1, - users.backer1Address, + BUYER_ID_1, ITEM_ID_1, - PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_1, + users.backer1Address ); confirmPayment(users.platform1AdminAddress, PAYMENT_ID_1); uint256 backerBalanceBefore = testToken.balanceOf(users.backer1Address); diff --git a/test/foundry/unit/PaymentTreasury.t.sol b/test/foundry/unit/PaymentTreasury.t.sol index cb585cbc..691a55f4 100644 --- a/test/foundry/unit/PaymentTreasury.t.sol +++ b/test/foundry/unit/PaymentTreasury.t.sol @@ -72,7 +72,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_1, - users.backer1Address, + BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, expiration @@ -88,20 +88,20 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.backer1Address); paymentTreasury.createPayment( PAYMENT_ID_1, - users.backer1Address, + BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, expiration ); } - function testCreatePaymentRevertWhenZeroBuyerAddress() public { + function testCreatePaymentRevertWhenZeroBuyerId() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.expectRevert(); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_1, - address(0), + bytes32(0), ITEM_ID_1, PAYMENT_AMOUNT_1, expiration @@ -114,7 +114,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_1, - users.backer1Address, + BUYER_ID_1, ITEM_ID_1, 0, expiration @@ -126,7 +126,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_1, - users.backer1Address, + BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, block.timestamp - 1 @@ -139,7 +139,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( bytes32(0), - users.backer1Address, + BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, expiration @@ -152,7 +152,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_1, - users.backer1Address, + BUYER_ID_1, bytes32(0), PAYMENT_AMOUNT_1, expiration @@ -164,7 +164,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.startPrank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_1, - users.backer1Address, + BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, expiration @@ -172,7 +172,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.expectRevert(); paymentTreasury.createPayment( PAYMENT_ID_1, - users.backer2Address, + BUYER_ID_2, ITEM_ID_2, PAYMENT_AMOUNT_2, expiration @@ -195,7 +195,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_1, - users.backer1Address, + BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, expiration @@ -213,7 +213,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_1, - users.backer1Address, + BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, expiration @@ -230,7 +230,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_1, - users.backer1Address, + BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, expiration @@ -249,7 +249,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te } function testCancelPaymentRevertWhenAlreadyConfirmed() public { - _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1); @@ -263,7 +263,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_1, - users.backer1Address, + BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, expiration @@ -281,7 +281,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te //////////////////////////////////////////////////////////////*/ function testConfirmPayment() public { - _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1); @@ -290,9 +290,9 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te } function testConfirmPaymentBatch() public { - _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); - _createAndFundPayment(PAYMENT_ID_2, users.backer2Address, ITEM_ID_2, PAYMENT_AMOUNT_2); - _createAndFundPayment(PAYMENT_ID_3, users.backer1Address, ITEM_ID_1, 500e18); + _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); + _createAndFundPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, PAYMENT_AMOUNT_2, users.backer2Address); + _createAndFundPayment(PAYMENT_ID_3, BUYER_ID_1, ITEM_ID_1, 500e18, users.backer1Address); bytes32[] memory paymentIds = new bytes32[](3); paymentIds[0] = PAYMENT_ID_1; @@ -314,7 +314,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te } function testConfirmPaymentRevertWhenAlreadyConfirmed() public { - _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.startPrank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1); @@ -328,7 +328,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te //////////////////////////////////////////////////////////////*/ function testClaimRefund() public { - _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1); @@ -349,7 +349,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_1, - users.backer1Address, + BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, expiration @@ -366,7 +366,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te } function testClaimRefundRevertWhenPaused() public { - _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1); @@ -384,7 +384,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te //////////////////////////////////////////////////////////////*/ function testDisburseFees() public { - _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1); @@ -400,7 +400,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te } function testDisburseFeesRevertWhenAlreadyDisbursed() public { - _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1); @@ -411,7 +411,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te } function testDisburseFeesRevertWhenPaused() public { - _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1); @@ -428,7 +428,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te //////////////////////////////////////////////////////////////*/ function testWithdraw() public { - _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1); @@ -446,7 +446,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te } function testWithdrawRevertWhenFeesNotDisbursed() public { - _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1); @@ -455,7 +455,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te } function testWithdrawRevertWhenAlreadyWithdrawn() public { - _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1); @@ -467,7 +467,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te } function testWithdrawRevertWhenPaused() public { - _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1); paymentTreasury.disburseFees(); @@ -486,7 +486,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testPauseTreasury() public { // First create and confirm a payment to test functions that require it - _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1); @@ -508,7 +508,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_2, - users.backer2Address, + BUYER_ID_1, ITEM_ID_2, PAYMENT_AMOUNT_2, expiration @@ -527,7 +527,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_1, - users.backer1Address, + BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, expiration @@ -535,7 +535,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te } function testCancelTreasuryByPlatformAdmin() public { - _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1); @@ -549,7 +549,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_2, - users.backer2Address, + BUYER_ID_1, ITEM_ID_2, PAYMENT_AMOUNT_2, expiration @@ -557,7 +557,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te } function testCancelTreasuryByCampaignOwner() public { - _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); + _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1); @@ -572,7 +572,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_2, - users.backer2Address, + BUYER_ID_1, ITEM_ID_2, PAYMENT_AMOUNT_2, expiration @@ -591,9 +591,9 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testMultipleRefundsAfterBatchConfirm() public { // Create multiple payments - _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); - _createAndFundPayment(PAYMENT_ID_2, users.backer2Address, ITEM_ID_2, PAYMENT_AMOUNT_2); - _createAndFundPayment(PAYMENT_ID_3, users.backer1Address, ITEM_ID_1, 500e18); + _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); + _createAndFundPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, PAYMENT_AMOUNT_2, users.backer2Address); + _createAndFundPayment(PAYMENT_ID_3, BUYER_ID_1, ITEM_ID_1, 500e18, users.backer1Address); // Confirm all in batch bytes32[] memory paymentIds = new bytes32[](3); @@ -621,8 +621,8 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te } function testZeroBalanceAfterAllRefunds() public { - _createAndFundPayment(PAYMENT_ID_1, users.backer1Address, ITEM_ID_1, PAYMENT_AMOUNT_1); - _createAndFundPayment(PAYMENT_ID_2, users.backer2Address, ITEM_ID_2, PAYMENT_AMOUNT_2); + _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); + _createAndFundPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, PAYMENT_AMOUNT_2, users.backer2Address); vm.startPrank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1); @@ -651,14 +651,14 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.startPrank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_1, - users.backer1Address, + BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, shortExpiration ); paymentTreasury.createPayment( PAYMENT_ID_2, - users.backer2Address, + BUYER_ID_2, ITEM_ID_2, PAYMENT_AMOUNT_2, longExpiration From a39e0017a39cd29c168089bf81120e543a70c9df Mon Sep 17 00:00:00 2001 From: mahabubAlahi <32974385+mahabubAlahi@users.noreply.github.com> Date: Tue, 19 Aug 2025 17:06:17 +0600 Subject: [PATCH 40/63] Add updated payment treasury tests (#29) Co-authored-by: AdnanHKx --- .../PaymentTreasury/PaymentTreasury.t.sol | 63 ++++++- .../PaymentTreasuryFunction.t.sol | 122 +++++++----- test/foundry/unit/PaymentTreasury.t.sol | 176 +++++++++++++++--- 3 files changed, 289 insertions(+), 72 deletions(-) diff --git a/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol b/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol index 9a411fd3..418c6911 100644 --- a/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol +++ b/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol @@ -149,6 +149,20 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te paymentTreasury.createPayment(paymentId, buyerId, itemId, amount, expiration); } + /** + * @notice Processes a crypto payment + */ + function processCryptoPayment( + address caller, + bytes32 paymentId, + bytes32 itemId, + address buyerAddress, + uint256 amount + ) internal { + vm.prank(caller); + paymentTreasury.processCryptoPayment(paymentId, itemId, buyerAddress, amount); + } + /** * @notice Cancels a payment */ @@ -196,6 +210,29 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te vm.stopPrank(); } + /** + * @notice Claims a refund (buyer-initiated) + */ + function claimRefund(address caller, bytes32 paymentId) + internal + returns (uint256 refundAmount) + { + vm.startPrank(caller); + vm.recordLogs(); + + paymentTreasury.claimRefund(paymentId); + + Vm.Log[] memory logs = vm.getRecordedLogs(); + + (bytes32[] memory topics, bytes memory data) = decodeTopicsAndData( + logs, "RefundClaimed(bytes32,uint256,address)", treasuryAddress + ); + + refundAmount = abi.decode(data, (uint256)); + + vm.stopPrank(); + } + /** * @notice Disburses fees */ @@ -219,7 +256,7 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te */ function withdraw(address treasury) internal - returns (address to, uint256 amount) + returns (address to, uint256 amount, uint256 fee) { vm.recordLogs(); @@ -228,10 +265,10 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te Vm.Log[] memory logs = vm.getRecordedLogs(); (bytes32[] memory topics, bytes memory data) = - decodeTopicsAndData(logs, "WithdrawalSuccessful(address,uint256)", treasury); + decodeTopicsAndData(logs, "WithdrawalWithFeeSuccessful(address,uint256,uint256)", treasury); to = address(uint160(uint256(topics[1]))); - amount = abi.decode(data, (uint256)); + (amount, fee) = abi.decode(data, (uint256, uint256)); } /** @@ -284,6 +321,26 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te testToken.transfer(treasuryAddress, amount); } + /** + * @notice Helper to create and process a crypto payment + */ + function _createAndProcessCryptoPayment( + bytes32 paymentId, + bytes32 itemId, + uint256 amount, + address buyerAddress + ) internal { + // Fund buyer + deal(address(testToken), buyerAddress, amount); + + // Buyer approves treasury + vm.prank(buyerAddress); + testToken.approve(treasuryAddress, amount); + + // Process crypto payment + processCryptoPayment(buyerAddress, paymentId, itemId, buyerAddress, amount); + } + /** * @notice Helper to create multiple test payments */ diff --git a/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol b/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol index 95b3dce4..cef0e151 100644 --- a/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol +++ b/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol @@ -88,7 +88,7 @@ contract PaymentTreasuryFunction_Integration_Test is users.backer1Address ); - // Assert: The refund amount is correct and all balances are updated as expected. + // Verify the refund amount is correct and all balances are updated as expected. assertEq(refundAmount, PAYMENT_AMOUNT_1, "Refunded amount is incorrect"); assertEq( testToken.balanceOf(users.backer1Address), @@ -99,11 +99,47 @@ contract PaymentTreasuryFunction_Integration_Test is assertEq(paymentTreasury.getAvailableRaisedAmount(), 0, "Available amount should be zero after refund"); assertEq(testToken.balanceOf(treasuryAddress), 0, "Treasury token balance should be zero after refund"); } + + /** + * @notice Tests the processing of a crypto payment. + */ + function test_processCryptoPayment() public { + uint256 amount = 1500e18; + deal(address(testToken), users.backer1Address, amount); + + vm.prank(users.backer1Address); + testToken.approve(treasuryAddress, amount); + + processCryptoPayment(users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, amount); + + assertEq(paymentTreasury.getRaisedAmount(), amount, "Raised amount should match crypto payment"); + assertEq(paymentTreasury.getAvailableRaisedAmount(), amount, "Available amount should match crypto payment"); + assertEq(testToken.balanceOf(treasuryAddress), amount, "Treasury should hold the tokens"); + } + + /** + * @notice Tests buyer-initiated refund for crypto payment. + */ + function test_claimRefundBuyerInitiated() public { + uint256 amount = 1500e18; + _createAndProcessCryptoPayment(PAYMENT_ID_1, ITEM_ID_1, amount, users.backer1Address); + + uint256 buyerBalanceBefore = testToken.balanceOf(users.backer1Address); + uint256 refundAmount = claimRefund(users.backer1Address, PAYMENT_ID_1); + + assertEq(refundAmount, amount, "Refund amount should match payment"); + assertEq( + testToken.balanceOf(users.backer1Address), + buyerBalanceBefore + amount, + "Buyer should receive refund" + ); + assertEq(paymentTreasury.getRaisedAmount(), 0, "Raised amount should be zero after refund"); + } /** - * @notice Tests the correct disbursement of fees to the protocol and platform. + * @notice Tests the final withdrawal of funds by the campaign owner after fees have been calculated. */ - function test_disburseFees() public { + function test_withdraw() public { _createTestPayments(); uint256 totalAmount = PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2; bytes32[] memory paymentIds = new bytes32[](2); @@ -111,64 +147,66 @@ contract PaymentTreasuryFunction_Integration_Test is paymentIds[1] = PAYMENT_ID_2; confirmPaymentBatch(users.platform1AdminAddress, paymentIds); - uint256 protocolAdminBalanceBefore = testToken.balanceOf(users.protocolAdminAddress); - uint256 platformAdminBalanceBefore = testToken.balanceOf(users.platform1AdminAddress); - uint256 treasuryAvailableAmountBefore = paymentTreasury.getAvailableRaisedAmount(); - - (uint256 protocolShare, uint256 platformShare) = disburseFees(treasuryAddress); + address campaignOwner = CampaignInfo(campaignAddress).owner(); + uint256 ownerBalanceBefore = testToken.balanceOf(campaignOwner); - // Assert: Fees are calculated and transferred correctly. - uint256 expectedProtocolShare = (totalAmount * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; - uint256 expectedPlatformShare = (totalAmount * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; + (address recipient, uint256 withdrawnAmount, uint256 fee) = withdraw(treasuryAddress); + uint256 ownerBalanceAfter = testToken.balanceOf(campaignOwner); - assertEq(protocolShare, expectedProtocolShare, "Incorrect protocol fee disbursed"); - assertEq(platformShare, expectedPlatformShare, "Incorrect platform fee disbursed"); + // Check that the correct amount is withdrawn to the campaign owner's address. + uint256 expectedProtocolFee = (totalAmount * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 expectedPlatformFee = (totalAmount * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 expectedTotalFee = expectedProtocolFee + expectedPlatformFee; + uint256 expectedWithdrawalAmount = totalAmount - expectedTotalFee; + assertEq(recipient, campaignOwner, "Funds withdrawn to incorrect address"); + assertEq(withdrawnAmount, expectedWithdrawalAmount, "Incorrect amount withdrawn"); + assertEq(fee, expectedTotalFee, "Incorrect fee amount"); assertEq( - testToken.balanceOf(users.protocolAdminAddress), - protocolAdminBalanceBefore + expectedProtocolShare, - "Protocol admin did not receive correct fee amount" - ); - assertEq( - testToken.balanceOf(users.platform1AdminAddress), - platformAdminBalanceBefore + expectedPlatformShare, - "Platform admin did not receive correct fee amount" - ); - assertEq( - paymentTreasury.getAvailableRaisedAmount(), - treasuryAvailableAmountBefore - protocolShare - platformShare, - "Treasury available amount not reduced correctly after disbursing fees" + ownerBalanceAfter - ownerBalanceBefore, + expectedWithdrawalAmount, + "Campaign owner did not receive correct withdrawn amount" ); + assertEq(paymentTreasury.getAvailableRaisedAmount(), 0, "Available amount should be zero after withdrawal"); } /** - * @notice Tests the final withdrawal of funds by the campaign owner after fees have been disbursed. + * @notice Tests the correct disbursement of fees to the protocol and platform after withdrawal. */ - function test_withdraw() public { + function test_disburseFeesAfterWithdraw() public { _createTestPayments(); uint256 totalAmount = PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2; bytes32[] memory paymentIds = new bytes32[](2); paymentIds[0] = PAYMENT_ID_1; paymentIds[1] = PAYMENT_ID_2; confirmPaymentBatch(users.platform1AdminAddress, paymentIds); + + // Withdraw first to calculate fees + withdraw(treasuryAddress); + + uint256 protocolAdminBalanceBefore = testToken.balanceOf(users.protocolAdminAddress); + uint256 platformAdminBalanceBefore = testToken.balanceOf(users.platform1AdminAddress); + (uint256 protocolShare, uint256 platformShare) = disburseFees(treasuryAddress); - address campaignOwner = CampaignInfo(campaignAddress).owner(); - uint256 ownerBalanceBefore = testToken.balanceOf(campaignOwner); + // Verify fees are calculated and transferred correctly. + uint256 expectedProtocolShare = (totalAmount * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 expectedPlatformShare = (totalAmount * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; - (address recipient, uint256 withdrawnAmount) = withdraw(treasuryAddress); - uint256 ownerBalanceAfter = testToken.balanceOf(campaignOwner); + assertEq(protocolShare, expectedProtocolShare, "Incorrect protocol fee disbursed"); + assertEq(platformShare, expectedPlatformShare, "Incorrect platform fee disbursed"); - // Check that the correct amount is withdrawn to the campaign owner's address. - uint256 expectedWithdrawalAmount = totalAmount - protocolShare - platformShare; - assertEq(recipient, campaignOwner, "Funds withdrawn to incorrect address"); - assertEq(withdrawnAmount, expectedWithdrawalAmount, "Incorrect amount withdrawn"); assertEq( - ownerBalanceAfter - ownerBalanceBefore, - expectedWithdrawalAmount, - "Campaign owner did not receive correct withdrawn amount" + testToken.balanceOf(users.protocolAdminAddress), + protocolAdminBalanceBefore + expectedProtocolShare, + "Protocol admin did not receive correct fee amount" ); - assertEq(paymentTreasury.getAvailableRaisedAmount(), 0, "Available amount should be zero after withdrawal"); - assertEq(testToken.balanceOf(treasuryAddress), 0, "Treasury token balance should be zero after withdrawal"); + assertEq( + testToken.balanceOf(users.platform1AdminAddress), + platformAdminBalanceBefore + expectedPlatformShare, + "Platform admin did not receive correct fee amount" + ); + + assertEq(testToken.balanceOf(treasuryAddress), 0, "Treasury should have zero balance after disbursing fees"); } -} +} \ No newline at end of file diff --git a/test/foundry/unit/PaymentTreasury.t.sol b/test/foundry/unit/PaymentTreasury.t.sol index 691a55f4..687294ef 100644 --- a/test/foundry/unit/PaymentTreasury.t.sol +++ b/test/foundry/unit/PaymentTreasury.t.sol @@ -182,15 +182,11 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testCreatePaymentRevertWhenPaused() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; - // Pause the treasury - but this won't affect createPayment + // Pause the treasury vm.prank(users.platform1AdminAddress); paymentTreasury.pauseTreasury(keccak256("Pause")); - // createPayment checks campaign pause, not treasury pause - CampaignInfo actualCampaignInfo = CampaignInfo(campaignAddress); - vm.prank(users.protocolAdminAddress); - actualCampaignInfo._pauseCampaign(keccak256("Pause")); - + // createPayment checks both treasury and campaign pause vm.expectRevert(); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( @@ -220,6 +216,47 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te ); } + /*////////////////////////////////////////////////////////////// + CRYPTO PAYMENT PROCESSING + //////////////////////////////////////////////////////////////*/ + + function testProcessCryptoPayment() public { + uint256 amount = 1500e18; + deal(address(testToken), users.backer1Address, amount); + + vm.prank(users.backer1Address); + testToken.approve(treasuryAddress, amount); + + processCryptoPayment(users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, amount); + + assertEq(paymentTreasury.getRaisedAmount(), amount); + assertEq(paymentTreasury.getAvailableRaisedAmount(), amount); + assertEq(testToken.balanceOf(treasuryAddress), amount); + } + + function testProcessCryptoPaymentRevertWhenZeroBuyerAddress() public { + vm.expectRevert(); + processCryptoPayment(users.platform1AdminAddress, PAYMENT_ID_1, ITEM_ID_1, address(0), 1000e18); + } + + function testProcessCryptoPaymentRevertWhenZeroAmount() public { + vm.expectRevert(); + processCryptoPayment(users.platform1AdminAddress, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, 0); + } + + function testProcessCryptoPaymentRevertWhenPaymentExists() public { + uint256 amount = 1500e18; + deal(address(testToken), users.backer1Address, amount * 2); + + vm.prank(users.backer1Address); + testToken.approve(treasuryAddress, amount * 2); + + processCryptoPayment(users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, amount); + + vm.expectRevert(); + processCryptoPayment(users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, amount); + } + /*////////////////////////////////////////////////////////////// PAYMENT CANCELLATION //////////////////////////////////////////////////////////////*/ @@ -276,6 +313,15 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te paymentTreasury.cancelPayment(PAYMENT_ID_1); } + function testCancelPaymentRevertWhenCryptoPayment() public { + uint256 amount = 1500e18; + _createAndProcessCryptoPayment(PAYMENT_ID_1, ITEM_ID_1, amount, users.backer1Address); + + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.cancelPayment(PAYMENT_ID_1); + } + /*////////////////////////////////////////////////////////////// PAYMENT CONFIRMATION //////////////////////////////////////////////////////////////*/ @@ -323,6 +369,15 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.stopPrank(); } + function testConfirmPaymentRevertWhenCryptoPayment() public { + uint256 amount = 1500e18; + _createAndProcessCryptoPayment(PAYMENT_ID_1, ITEM_ID_1, amount, users.backer1Address); + + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + } + /*////////////////////////////////////////////////////////////// REFUNDS //////////////////////////////////////////////////////////////*/ @@ -344,6 +399,37 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te assertEq(paymentTreasury.getAvailableRaisedAmount(), 0); } + function testClaimRefundBuyerInitiated() public { + uint256 amount = 1500e18; + _createAndProcessCryptoPayment(PAYMENT_ID_1, ITEM_ID_1, amount, users.backer1Address); + + uint256 balanceBefore = testToken.balanceOf(users.backer1Address); + + vm.prank(users.backer1Address); + paymentTreasury.claimRefund(PAYMENT_ID_1); + + uint256 balanceAfter = testToken.balanceOf(users.backer1Address); + + assertEq(balanceAfter - balanceBefore, amount); + assertEq(paymentTreasury.getRaisedAmount(), 0); + assertEq(paymentTreasury.getAvailableRaisedAmount(), 0); + } + + function testClaimRefundByPlatformAdminForCryptoPayment() public { + uint256 amount = 1500e18; + _createAndProcessCryptoPayment(PAYMENT_ID_1, ITEM_ID_1, amount, users.backer1Address); + + uint256 balanceBefore = testToken.balanceOf(users.backer1Address); + + vm.prank(users.platform1AdminAddress); + paymentTreasury.claimRefund(PAYMENT_ID_1); + + uint256 balanceAfter = testToken.balanceOf(users.backer1Address); + + assertEq(balanceAfter - balanceBefore, amount); + assertEq(paymentTreasury.getRaisedAmount(), 0); + } + function testClaimRefundRevertWhenNotConfirmed() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.prank(users.platform1AdminAddress); @@ -379,6 +465,15 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te paymentTreasury.claimRefund(PAYMENT_ID_1, users.backer1Address); } + function testClaimRefundRevertWhenUnauthorizedForCryptoPayment() public { + uint256 amount = 1500e18; + _createAndProcessCryptoPayment(PAYMENT_ID_1, ITEM_ID_1, amount, users.backer1Address); + + vm.expectRevert(); + vm.prank(users.backer2Address); // Different buyer + paymentTreasury.claimRefund(PAYMENT_ID_1); + } + /*////////////////////////////////////////////////////////////// FEE DISBURSEMENT //////////////////////////////////////////////////////////////*/ @@ -388,6 +483,9 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1); + // Withdraw first to calculate fees + paymentTreasury.withdraw(); + uint256 protocolBalanceBefore = testToken.balanceOf(users.protocolAdminAddress); uint256 platformBalanceBefore = testToken.balanceOf(users.platform1AdminAddress); @@ -399,14 +497,22 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te assertTrue(platformBalanceAfter > platformBalanceBefore); } - function testDisburseFeesRevertWhenAlreadyDisbursed() public { + function testDisburseFeesMultipleTimes() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); + _createAndFundPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, PAYMENT_AMOUNT_2, users.backer2Address); + vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1); + // First withdrawal and disbursement + paymentTreasury.withdraw(); paymentTreasury.disburseFees(); - vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_2); + + // Second withdrawal and disbursement + paymentTreasury.withdraw(); paymentTreasury.disburseFees(); } @@ -415,6 +521,8 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.withdraw(); + // Pause treasury vm.prank(users.platform1AdminAddress); paymentTreasury.pauseTreasury(keccak256("Pause")); @@ -432,26 +540,19 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1); - paymentTreasury.disburseFees(); - address owner = CampaignInfo(campaignAddress).owner(); uint256 ownerBalanceBefore = testToken.balanceOf(owner); - uint256 availableAmount = paymentTreasury.getAvailableRaisedAmount(); paymentTreasury.withdraw(); uint256 ownerBalanceAfter = testToken.balanceOf(owner); - assertEq(ownerBalanceAfter - ownerBalanceBefore, availableAmount); - assertEq(paymentTreasury.getAvailableRaisedAmount(), 0); - } - - function testWithdrawRevertWhenFeesNotDisbursed() public { - _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); - vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); - vm.expectRevert(); - paymentTreasury.withdraw(); + uint256 expectedProtocolFee = (PAYMENT_AMOUNT_1 * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 expectedPlatformFee = (PAYMENT_AMOUNT_1 * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 expectedWithdrawal = PAYMENT_AMOUNT_1 - expectedProtocolFee - expectedPlatformFee; + + assertEq(ownerBalanceAfter - ownerBalanceBefore, expectedWithdrawal); + assertEq(paymentTreasury.getAvailableRaisedAmount(), 0); } function testWithdrawRevertWhenAlreadyWithdrawn() public { @@ -459,8 +560,8 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1); - paymentTreasury.disburseFees(); paymentTreasury.withdraw(); + paymentTreasury.disburseFees(); vm.expectRevert(); paymentTreasury.withdraw(); @@ -470,7 +571,6 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1); - paymentTreasury.disburseFees(); // Pause treasury vm.prank(users.platform1AdminAddress); @@ -503,8 +603,9 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.expectRevert(); paymentTreasury.disburseFees(); - // createPayment checks campaign pause, not treasury pause + // createPayment checks treasury pause as well uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.expectRevert(); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_2, @@ -546,6 +647,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te paymentTreasury.disburseFees(); uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.expectRevert(); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_2, @@ -569,6 +671,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te paymentTreasury.disburseFees(); uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.expectRevert(); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_2, @@ -636,9 +739,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te assertEq(paymentTreasury.getRaisedAmount(), 0); assertEq(paymentTreasury.getAvailableRaisedAmount(), 0); - // Disbursing fees with zero balance should succeed (transferring 0 amounts) - paymentTreasury.disburseFees(); - // But withdraw should revert because balance is 0 + // Withdraw should revert because balance is 0 vm.expectRevert(); paymentTreasury.withdraw(); } @@ -686,4 +787,25 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te assertEq(paymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2); } + + function testMixedPaymentTypes() public { + // Create both regular and crypto payments + _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); + _createAndProcessCryptoPayment(PAYMENT_ID_2, ITEM_ID_2, PAYMENT_AMOUNT_2, users.backer2Address); + + // Confirm regular payment + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + + // Both should contribute to raised amount + uint256 totalAmount = PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2; + assertEq(paymentTreasury.getRaisedAmount(), totalAmount); + assertEq(paymentTreasury.getAvailableRaisedAmount(), totalAmount); + + // Withdraw and disburse fees + paymentTreasury.withdraw(); + paymentTreasury.disburseFees(); + + assertEq(paymentTreasury.getAvailableRaisedAmount(), 0); + } } \ No newline at end of file From 6024472d35f12a39acc3bbf96544972507d273dd Mon Sep 17 00:00:00 2001 From: AdnanHKx Date: Tue, 7 Oct 2025 16:35:33 +0600 Subject: [PATCH 41/63] Add Phantom Balances Fix for PaymentTreasury (#30) * Add phantom balances fix and additional unit tests * Add batch payment gas test script * Gas optimization for batch payment --- foundry.lock | 5 + src/utils/BasePaymentTreasury.sol | 67 +++++++++---- .../PaymentTreasuryBatchLimitTest.t.sol | 97 +++++++++++++++++++ test/foundry/unit/PaymentTreasury.t.sol | 77 +++++++++++++++ 4 files changed, 226 insertions(+), 20 deletions(-) create mode 100644 foundry.lock create mode 100644 test/foundry/integration/PaymentTreasury/PaymentTreasuryBatchLimitTest.t.sol diff --git a/foundry.lock b/foundry.lock new file mode 100644 index 00000000..b67633ee --- /dev/null +++ b/foundry.lock @@ -0,0 +1,5 @@ +{ + "lib/forge-std": { + "rev": "1d9650e951204a0ddce9ff89c32f1997984cef4d" + } +} \ No newline at end of file diff --git a/src/utils/BasePaymentTreasury.sol b/src/utils/BasePaymentTreasury.sol index 4b167401..e7a8e5d3 100644 --- a/src/utils/BasePaymentTreasury.sol +++ b/src/utils/BasePaymentTreasury.sol @@ -187,6 +187,8 @@ abstract contract BasePaymentTreasury is */ error PaymentTreasuryInsufficientFundsForFee(uint256 withdrawalAmount, uint256 fee); + error PaymentTreasuryInsufficientBalance(uint256 required, uint256 available); + function __BaseContract_init( bytes32 platformHash, address infoAddress @@ -376,17 +378,27 @@ abstract contract BasePaymentTreasury is function confirmPayment( bytes32 paymentId ) public override virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { - _validatePaymentForAction(paymentId); - + + uint256 paymentAmount = s_payment[paymentId].amount; + + // Check that we have enough unallocated tokens for this payment + uint256 actualBalance = TOKEN.balanceOf(address(this)); + uint256 currentlyCommitted = s_availableConfirmedPaymentAmount + s_protocolFee + s_platformFee; + + if (currentlyCommitted + paymentAmount > actualBalance) { + revert PaymentTreasuryInsufficientBalance( + currentlyCommitted + paymentAmount, + actualBalance + ); + } + s_payment[paymentId].isConfirmed = true; - - uint256 amount = s_payment[paymentId].amount; - - s_pendingPaymentAmount -= amount; - s_confirmedPaymentAmount += amount; - s_availableConfirmedPaymentAmount += amount; - + + s_pendingPaymentAmount -= paymentAmount; + s_confirmedPaymentAmount += paymentAmount; + s_availableConfirmedPaymentAmount += paymentAmount; + emit PaymentConfirmed(paymentId); } @@ -395,22 +407,37 @@ abstract contract BasePaymentTreasury is */ function confirmPaymentBatch( bytes32[] calldata paymentIds - ) public override virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { - - for(uint256 i = 0; i < paymentIds.length; i++){ - _validatePaymentForAction(paymentIds[i]); - - s_payment[paymentIds[i]].isConfirmed = true; - - uint256 amount = s_payment[paymentIds[i]].amount; - + ) public override virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { + uint256 actualBalance = TOKEN.balanceOf(address(this)); + bytes32 currentPaymentId; + + for(uint256 i = 0; i < paymentIds.length;){ + currentPaymentId = paymentIds[i]; + _validatePaymentForAction(currentPaymentId); + + uint256 amount = s_payment[currentPaymentId].amount; + + // Check if this confirmation would exceed balance + uint256 currentlyCommitted = s_availableConfirmedPaymentAmount + s_protocolFee + s_platformFee; + + if (currentlyCommitted + amount > actualBalance) { + revert PaymentTreasuryInsufficientBalance( + currentlyCommitted + amount, + actualBalance + ); + } + + s_payment[currentPaymentId].isConfirmed = true; s_pendingPaymentAmount -= amount; s_confirmedPaymentAmount += amount; s_availableConfirmedPaymentAmount += amount; - } + unchecked { + ++i; + } + } + emit PaymentBatchConfirmed(paymentIds); - } /** diff --git a/test/foundry/integration/PaymentTreasury/PaymentTreasuryBatchLimitTest.t.sol b/test/foundry/integration/PaymentTreasury/PaymentTreasuryBatchLimitTest.t.sol new file mode 100644 index 00000000..8b2d3f5b --- /dev/null +++ b/test/foundry/integration/PaymentTreasury/PaymentTreasuryBatchLimitTest.t.sol @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.20; + +import "./PaymentTreasury.t.sol"; +import "forge-std/Vm.sol"; +import "forge-std/console.sol"; +import "forge-std/Test.sol"; +import {LogDecoder} from "../../utils/LogDecoder.sol"; +import {PaymentTreasury} from "src/treasuries/PaymentTreasury.sol"; + +contract PaymentTreasuryBatchLimit_Test is PaymentTreasury_Integration_Shared_Test { + uint256 constant CELO_BLOCK_GAS_LIMIT = 30_000_000; + + function setUp() public override { + super.setUp(); + console.log("=== CELO BATCH LIMIT TEST ==="); + console.log("Block Gas Limit: 30,000,000"); + console.log("Block gas target: 6,000,000"); + console.log(""); + } + + /** + * @notice Creates payments for testing + */ + function _createBatchPayments(uint256 count) internal returns (bytes32[] memory paymentIds) { + paymentIds = new bytes32[](count); + uint256 paymentAmount = 10e18; + uint256 expiration = block.timestamp + 7 days; + + vm.startPrank(users.platform1AdminAddress); + for (uint256 i = 0; i < count; i++) { + bytes32 paymentId = keccak256(abi.encodePacked("payment", i)); + bytes32 buyerId = keccak256(abi.encodePacked("buyer", i)); + bytes32 itemId = keccak256(abi.encodePacked("item", i)); + + paymentTreasury.createPayment(paymentId, buyerId, itemId, paymentAmount, expiration); + + paymentIds[i] = paymentId; + } + vm.stopPrank(); + + // Fund the treasury + deal(address(testToken), treasuryAddress, paymentAmount * count); + + return paymentIds; + } + + /** + * @notice Test to find batch limits + */ + function test_FindBatchLimits() public { + uint256[] memory batchSizes = new uint256[](5); + batchSizes[0] = 100; + batchSizes[1] = 200; + batchSizes[2] = 300; + batchSizes[3] = 400; + batchSizes[4] = 500; + + console.log("TESTING BATCH SIZES FROM 100 TO 500"); + console.log("===================================="); + + for (uint256 i = 0; i < batchSizes.length; i++) { + uint256 batchSize = batchSizes[i]; + + bytes32[] memory paymentIds = _createBatchPayments(batchSize); + + vm.prank(users.platform1AdminAddress); + uint256 gasStart = gasleft(); + + try paymentTreasury.confirmPaymentBatch(paymentIds) { + uint256 gasUsed = gasStart - gasleft(); + uint256 percentOfBlock = (gasUsed * 100) / CELO_BLOCK_GAS_LIMIT; + + console.log(string(abi.encodePacked("Batch Size: ", vm.toString(batchSize)))); + console.log(string(abi.encodePacked("Gas Used: ", vm.toString(gasUsed)))); + console.log(string(abi.encodePacked("Percent of Block: ", vm.toString(percentOfBlock), "%"))); + + // Check safety thresholds + if (percentOfBlock <= 30) { + console.log("Status: SAFE"); + } else { + console.log("Status: RISKY"); + } + console.log("----------------------------"); + + } catch { + console.log(string(abi.encodePacked("Batch Size: ", vm.toString(batchSize)))); + console.log("FAILED - Exceeds gas limit or reverted"); + console.log("----------------------------"); + break; + } + + setUp(); + } + } +} + diff --git a/test/foundry/unit/PaymentTreasury.t.sol b/test/foundry/unit/PaymentTreasury.t.sol index 687294ef..14f87c8e 100644 --- a/test/foundry/unit/PaymentTreasury.t.sol +++ b/test/foundry/unit/PaymentTreasury.t.sol @@ -808,4 +808,81 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te assertEq(paymentTreasury.getAvailableRaisedAmount(), 0); } + + function testCannotCreatePhantomBalances() public { + // Create payment for 1000 USDC + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + 1000e18, + expiration + ); + + // Try to confirm without any tokens - should revert + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + + // Send the tokens + deal(address(testToken), users.backer1Address, 1000e18); + vm.prank(users.backer1Address); + testToken.transfer(treasuryAddress, 1000e18); + + // Now confirmation works + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + + assertEq(paymentTreasury.getRaisedAmount(), 1000e18); + } + + function testCannotConfirmMoreThanBalance() public { + // Create two payments of 500 each + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.startPrank(users.platform1AdminAddress); + paymentTreasury.createPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, 500e18, expiration); + paymentTreasury.createPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, 500e18, expiration); + vm.stopPrank(); + + // Send only 500 tokens total + deal(address(testToken), users.backer1Address, 500e18); + vm.prank(users.backer1Address); + testToken.transfer(treasuryAddress, 500e18); + + // Can confirm one payment + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + + // Cannot confirm second payment - total would exceed balance + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_2); + + assertEq(paymentTreasury.getRaisedAmount(), 500e18); + } + + function testBatchConfirmRespectsBalance() public { + // Create two payments + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.startPrank(users.platform1AdminAddress); + paymentTreasury.createPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, 500e18, expiration); + paymentTreasury.createPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, 500e18, expiration); + vm.stopPrank(); + + // Send only 500 tokens + deal(address(testToken), users.backer1Address, 500e18); + vm.prank(users.backer1Address); + testToken.transfer(treasuryAddress, 500e18); + + // Try to confirm both + bytes32[] memory paymentIds = new bytes32[](2); + paymentIds[0] = PAYMENT_ID_1; + paymentIds[1] = PAYMENT_ID_2; + + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPaymentBatch(paymentIds); + } } \ No newline at end of file From 0cfb87798daa969018f6baaadb60e8a0676661a7 Mon Sep 17 00:00:00 2001 From: mahabubAlahi <32974385+mahabubAlahi@users.noreply.github.com> Date: Fri, 17 Oct 2025 15:22:35 +0600 Subject: [PATCH 42/63] Refactor admin rights transfer in deployment scripts (#31) - Consolidate the transfer of protocol admin rights to ensure ownership is correctly assigned to final addresses. - Update logging to provide clearer output regarding ownership transfers for GlobalParams and CampaignInfoFactory. - Change environment variable name from TEST_USD_ADDRESS to TOKEN_ADDRESS for consistency across scripts. --- script/DeployAllAndSetupAllOrNothing.s.sol | 28 ++++++++++------ script/DeployAllAndSetupKeepWhatsRaised.s.sol | 24 +++++++++----- script/DeployAllAndSetupPaymentTreasury.s.sol | 32 ++++++++++++------- 3 files changed, 54 insertions(+), 30 deletions(-) diff --git a/script/DeployAllAndSetupAllOrNothing.s.sol b/script/DeployAllAndSetupAllOrNothing.s.sol index 6ec89e72..836c2050 100644 --- a/script/DeployAllAndSetupAllOrNothing.s.sol +++ b/script/DeployAllAndSetupAllOrNothing.s.sol @@ -321,16 +321,6 @@ contract DeployAllAndSetupAllOrNothing is Script { console2.log("Transferring admin rights to final addresses..."); // Only transfer if the final addresses are different from deployer - if (finalProtocolAdmin != deployerAddress) { - console2.log( - "Transferring protocol admin rights to:", - finalProtocolAdmin - ); - GlobalParams(globalParams).updateProtocolAdminAddress( - finalProtocolAdmin - ); - } - if (finalPlatformAdmin != deployerAddress) { console2.log( "Updating platform admin address for platform hash:", @@ -342,6 +332,22 @@ contract DeployAllAndSetupAllOrNothing is Script { ); } + if (finalProtocolAdmin != deployerAddress) { + console2.log( + "Transferring protocol admin rights to:", + finalProtocolAdmin + ); + GlobalParams(globalParams).updateProtocolAdminAddress( + finalProtocolAdmin + ); + + //Transfer admin rights to the final protocol admin + GlobalParams(globalParams).transferOwnership(finalProtocolAdmin); + console2.log("GlobalParams transferred to:", finalProtocolAdmin); + CampaignInfoFactory(campaignInfoFactory).transferOwnership(finalProtocolAdmin); + console2.log("CampaignInfoFactory transferred to:", finalProtocolAdmin); + } + adminRightsTransferred = true; console2.log("Admin rights transferred successfully"); } @@ -392,6 +398,8 @@ contract DeployAllAndSetupAllOrNothing is Script { ); console2.log("Protocol Admin:", finalProtocolAdmin); console2.log("Platform Admin:", finalPlatformAdmin); + console2.log("GlobalParams owner:", GlobalParams(globalParams).owner()); + console2.log("CampaignInfoFactory owner:", CampaignInfoFactory(campaignInfoFactory).owner()); if (backer1 != address(0)) { console2.log("Backer1 (tokens minted):", backer1); diff --git a/script/DeployAllAndSetupKeepWhatsRaised.s.sol b/script/DeployAllAndSetupKeepWhatsRaised.s.sol index 8b134030..f18d25e5 100644 --- a/script/DeployAllAndSetupKeepWhatsRaised.s.sol +++ b/script/DeployAllAndSetupKeepWhatsRaised.s.sol @@ -71,7 +71,7 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { backer2 = vm.envOr("BACKER2_ADDRESS", address(0)); // Check for existing contract addresses - testToken = vm.envOr("TEST_USD_ADDRESS", address(0)); + testToken = vm.envOr("TOKEN_ADDRESS", address(0)); globalParams = vm.envOr("GLOBAL_PARAMS_ADDRESS", address(0)); treasuryFactory = vm.envOr("TREASURY_FACTORY_ADDRESS", address(0)); campaignInfoFactory = vm.envOr("CAMPAIGN_INFO_FACTORY_ADDRESS", address(0)); @@ -268,18 +268,24 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { } console2.log("Transferring admin rights to final addresses..."); - + // Only transfer if the final addresses are different from deployer - if (finalProtocolAdmin != deployerAddress) { - console2.log("Transferring protocol admin rights to:", finalProtocolAdmin); - GlobalParams(globalParams).updateProtocolAdminAddress(finalProtocolAdmin); - } - if (finalPlatformAdmin != deployerAddress) { console2.log("Updating platform admin address for platform hash:", vm.toString(platformHash)); GlobalParams(globalParams).updatePlatformAdminAddress(platformHash, finalPlatformAdmin); } + if (finalProtocolAdmin != deployerAddress) { + console2.log("Transferring protocol admin rights to:", finalProtocolAdmin); + GlobalParams(globalParams).updateProtocolAdminAddress(finalProtocolAdmin); + + //Transfer admin rights to the final protocol admin + GlobalParams(globalParams).transferOwnership(finalProtocolAdmin); + console2.log("GlobalParams transferred to:", finalProtocolAdmin); + CampaignInfoFactory(campaignInfoFactory).transferOwnership(finalProtocolAdmin); + console2.log("CampaignInfoFactory transferred to:", finalProtocolAdmin); + } + adminRightsTransferred = true; console2.log("Admin rights transferred successfully"); } @@ -314,7 +320,7 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { // Output summary console2.log("\n--- Deployment & Setup Summary ---"); console2.log("Platform Name Hash:", vm.toString(platformHash)); - console2.log("TEST_TOKEN_ADDRESS:", testToken); + console2.log("TOKEN_ADDRESS:", testToken); console2.log("GLOBAL_PARAMS_ADDRESS:", globalParams); if (campaignInfo != address(0)) { console2.log("CAMPAIGN_INFO_ADDRESS:", campaignInfo); @@ -324,6 +330,8 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { console2.log("KEEP_WHATS_RAISED_IMPLEMENTATION_ADDRESS:", keepWhatsRaisedImplementation); console2.log("Protocol Admin:", finalProtocolAdmin); console2.log("Platform Admin:", finalPlatformAdmin); + console2.log("GlobalParams owner:", GlobalParams(globalParams).owner()); + console2.log("CampaignInfoFactory owner:", CampaignInfoFactory(campaignInfoFactory).owner()); if (backer1 != address(0)) { console2.log("Backer1 (tokens minted):", backer1); diff --git a/script/DeployAllAndSetupPaymentTreasury.s.sol b/script/DeployAllAndSetupPaymentTreasury.s.sol index 9cc95ca8..205b4b74 100644 --- a/script/DeployAllAndSetupPaymentTreasury.s.sol +++ b/script/DeployAllAndSetupPaymentTreasury.s.sol @@ -144,7 +144,7 @@ contract DeployAllAndSetupPaymentTreasury is Script { // Deploy CampaignInfo implementation if needed for new deployments if (campaignInfoFactory == address(0)) { campaignInfoImplementation = address( - new CampaignInfo(address(this)) + new CampaignInfo(deployerAddress) ); console2.log( "CampaignInfo implementation deployed at:", @@ -321,16 +321,6 @@ contract DeployAllAndSetupPaymentTreasury is Script { console2.log("Transferring admin rights to final addresses..."); // Only transfer if the final addresses are different from deployer - if (finalProtocolAdmin != deployerAddress) { - console2.log( - "Transferring protocol admin rights to:", - finalProtocolAdmin - ); - GlobalParams(globalParams).updateProtocolAdminAddress( - finalProtocolAdmin - ); - } - if (finalPlatformAdmin != deployerAddress) { console2.log( "Updating platform admin address for platform hash:", @@ -342,6 +332,22 @@ contract DeployAllAndSetupPaymentTreasury is Script { ); } + if (finalProtocolAdmin != deployerAddress) { + console2.log( + "Transferring protocol admin rights to:", + finalProtocolAdmin + ); + GlobalParams(globalParams).updateProtocolAdminAddress( + finalProtocolAdmin + ); + + //Transfer admin rights to the final protocol admin + GlobalParams(globalParams).transferOwnership(finalProtocolAdmin); + console2.log("GlobalParams transferred to:", finalProtocolAdmin); + CampaignInfoFactory(campaignInfoFactory).transferOwnership(finalProtocolAdmin); + console2.log("CampaignInfoFactory transferred to:", finalProtocolAdmin); + } + adminRightsTransferred = true; console2.log("Admin rights transferred successfully"); } @@ -376,7 +382,7 @@ contract DeployAllAndSetupPaymentTreasury is Script { // Output summary console2.log("\n--- Deployment & Setup Summary ---"); console2.log("Platform Name Hash:", vm.toString(platformHash)); - console2.log("TOKEN_ADDRESS:", testToken); + console2.log("TEST_TOKEN_ADDRESS:", testToken); console2.log("GLOBAL_PARAMS_ADDRESS:", globalParams); if (campaignInfoImplementation != address(0)) { console2.log( @@ -392,6 +398,8 @@ contract DeployAllAndSetupPaymentTreasury is Script { ); console2.log("Protocol Admin:", finalProtocolAdmin); console2.log("Platform Admin:", finalPlatformAdmin); + console2.log("GlobalParams owner:", GlobalParams(globalParams).owner()); + console2.log("CampaignInfoFactory owner:", CampaignInfoFactory(campaignInfoFactory).owner()); if (backer1 != address(0)) { console2.log("Backer1 (tokens minted):", backer1); From bd7ad7506c350ac219ce8397311c8e092f5d76ce Mon Sep 17 00:00:00 2001 From: AdnanHKx Date: Sun, 19 Oct 2025 11:40:49 +0600 Subject: [PATCH 43/63] Implement UUPS Upgradeability with Multi-Token Support (#33) * Add multi-token support * Update deployment and test scripts, fix decimal normalization issue in reward and fee calculation * Make core contracts UUPS upgradeable with namespaced storage layout * Update documentation * Update solc and OpenZeppelin lib versions, fix ERC7201 storage location hashes and implement Context pattern * Add OpenZeppelin upgradeable contracts submodule - Added a new submodule for OpenZeppelin upgradeable contracts to the project. - Updated .gitmodules to include the path and URL for the new submodule. * Refactor storage implementation for core contracts - Introduced dedicated storage libraries for AdminAccessChecker, CampaignInfoFactory, GlobalParams, and TreasuryFactory to utilize ERC-7201 namespaced storage. - Updated contract methods to access storage using the new library functions, enhancing modularity and maintainability. - Removed inline storage definitions from contracts to streamline code and improve clarity. --------- Co-authored-by: AdnanHKx Co-authored-by: Mahabub Alahi --- .gitignore | 2 +- .gitmodules | 3 + docs/UPGRADES.md | 353 ++++++++++++ docs/book.toml | 1 + .../CampaignInfo.sol/contract.CampaignInfo.md | 74 ++- .../contract.CampaignInfoFactory.md | 132 +++-- .../GlobalParams.sol/contract.GlobalParams.md | 302 ++++++++--- .../contract.TreasuryFactory.md | 66 ++- .../interface.ICampaignData.md | 5 +- .../interface.ICampaignInfo.md | 54 +- .../interface.ICampaignInfoFactory.md | 4 +- .../interface.ICampaignPaymentTreasury.md | 57 +- .../interface.ICampaignTreasury.md | 2 +- .../interface.IGlobalParams.md | 81 ++- .../interfaces/IItem.sol/interface.IItem.md | 2 +- .../IReward.sol/interface.IReward.md | 2 +- .../interface.ITreasuryFactory.md | 2 +- .../AllOrNothing.sol/contract.AllOrNothing.md | 30 +- .../contract.KeepWhatsRaised.md | 171 ++++-- .../contract.PaymentTreasury.md | 126 ++++- .../abstract.AdminAccessChecker.md | 48 +- .../abstract.BasePaymentTreasury.md | 249 +++++++-- .../BaseTreasury.sol/abstract.BaseTreasury.md | 76 ++- .../abstract.CampaignAccessChecker.md | 5 +- .../utils/Counters.sol/library.Counters.md | 2 +- .../FiatEnabled.sol/abstract.FiatEnabled.md | 2 +- .../ItemRegistry.sol/contract.ItemRegistry.md | 2 +- .../abstract.PausableCancellable.md | 5 +- .../abstract.TimestampChecker.md | 2 +- foundry.toml | 5 +- script/DeployAll.s.sol | 134 +++-- script/DeployAllAndSetupAllOrNothing.s.sol | 68 ++- script/DeployAllAndSetupKeepWhatsRaised.s.sol | 68 ++- script/DeployAllAndSetupPaymentTreasury.s.sol | 68 ++- script/DeployAllOrNothingImplementation.s.sol | 2 +- script/DeployCampaignInfoFactory.s.sol | 34 +- script/DeployCampaignInfoImplementation.s.sol | 4 +- script/DeployGlobalParams.s.sol | 55 +- script/DeployKeepWhatsRaised.s.sol | 2 +- script/DeployTestToken.s.sol | 5 +- script/DeployTreasuryFactory.s.sol | 19 +- script/UpgradeCampaignInfoFactory.s.sol | 38 ++ script/UpgradeGlobalParams.s.sol | 38 ++ script/UpgradeTreasuryFactory.s.sol | 38 ++ script/lib/DeployBase.s.sol | 2 +- src/CampaignInfo.sol | 65 ++- src/CampaignInfoFactory.sol | 130 +++-- src/GlobalParams.sol | 286 +++++++--- src/TreasuryFactory.sol | 55 +- src/interfaces/ICampaignData.sol | 5 +- src/interfaces/ICampaignInfo.sol | 27 +- src/interfaces/ICampaignInfoFactory.sol | 4 +- src/interfaces/ICampaignPaymentTreasury.sol | 6 +- src/interfaces/ICampaignTreasury.sol | 2 +- src/interfaces/IGlobalParams.sol | 37 +- src/interfaces/IItem.sol | 2 +- src/interfaces/IReward.sol | 2 +- src/interfaces/ITreasuryFactory.sol | 2 +- src/storage/AdminAccessCheckerStorage.sol | 26 + src/storage/CampaignInfoFactoryStorage.sol | 30 + src/storage/GlobalParamsStorage.sol | 37 ++ src/storage/TreasuryFactoryStorage.sol | 25 + src/treasuries/AllOrNothing.sol | 84 ++- src/treasuries/KeepWhatsRaised.sol | 268 ++++++--- src/treasuries/PaymentTreasury.sol | 19 +- src/utils/AdminAccessChecker.sol | 30 +- src/utils/BasePaymentTreasury.sol | 275 +++++++--- src/utils/BaseTreasury.sol | 123 ++++- src/utils/CampaignAccessChecker.sol | 11 +- src/utils/Counters.sol | 2 +- src/utils/FiatEnabled.sol | 2 +- src/utils/ItemRegistry.sol | 2 +- src/utils/PausableCancellable.sol | 12 +- src/utils/TimestampChecker.sol | 2 +- test/foundry/Base.t.sol | 117 +++- .../AllOrNothing/AllOrNothing.t.sol | 33 +- .../AllOrNothing/AllOrNothingFunction.t.sol | 315 ++++++++++- .../KeepWhatsRaised/KeepWhatsRaised.t.sol | 37 +- .../KeepWhatsRaisedFunction.t.sol | 8 +- .../PaymentTreasury/PaymentTreasury.t.sol | 74 ++- .../PaymentTreasuryBatchLimitTest.t.sol | 4 +- .../PaymentTreasuryFunction.t.sol | 511 +++++++++++++++++- test/foundry/unit/CampaignInfoFactory.t.sol | 123 ++++- test/foundry/unit/GlobalParams.t.sol | 282 +++++++++- test/foundry/unit/KeepWhatsRaised.t.sol | 444 +++++++++++++-- test/foundry/unit/PaymentTreasury.t.sol | 486 +++++++++++++++-- test/foundry/unit/TestToken.t.sol | 4 +- test/foundry/unit/TreasuryFactory.t.sol | 77 ++- test/foundry/unit/Upgrades.t.sol | 382 +++++++++++++ test/foundry/utils/Constants.sol | 2 +- test/foundry/utils/Defaults.sol | 9 +- test/foundry/utils/LogDecoder.sol | 2 +- test/foundry/utils/Types.sol | 2 +- test/mocks/TestToken.sol | 15 +- 94 files changed, 5895 insertions(+), 1043 deletions(-) create mode 100644 docs/UPGRADES.md create mode 100644 script/UpgradeCampaignInfoFactory.s.sol create mode 100644 script/UpgradeGlobalParams.s.sol create mode 100644 script/UpgradeTreasuryFactory.s.sol create mode 100644 src/storage/AdminAccessCheckerStorage.sol create mode 100644 src/storage/CampaignInfoFactoryStorage.sol create mode 100644 src/storage/GlobalParamsStorage.sol create mode 100644 src/storage/TreasuryFactoryStorage.sol create mode 100644 test/foundry/unit/Upgrades.t.sol diff --git a/.gitignore b/.gitignore index 723c0dbd..7de7cd25 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ node_modules -lib +/lib .env .deps .temp diff --git a/.gitmodules b/.gitmodules index 690924b6..9296efd5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "lib/openzeppelin-contracts"] path = lib/openzeppelin-contracts url = https://github.com/OpenZeppelin/openzeppelin-contracts +[submodule "lib/openzeppelin-contracts-upgradeable"] + path = lib/openzeppelin-contracts-upgradeable + url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable diff --git a/docs/UPGRADES.md b/docs/UPGRADES.md new file mode 100644 index 00000000..ccf93f13 --- /dev/null +++ b/docs/UPGRADES.md @@ -0,0 +1,353 @@ +# UUPS Upgradeable Contracts Guide + +## Overview + +The core protocol contracts (`GlobalParams`, `TreasuryFactory`, and `CampaignInfoFactory`) have been converted to UUPS (Universal Upgradeable Proxy Standard) upgradeable contracts with ERC-7201 namespaced storage. This document provides a comprehensive guide on the implementation and usage. + +## Architecture + +### UUPS Pattern + +The UUPS proxy pattern was chosen for the following benefits: +- **Gas Efficiency**: Upgrade logic is in the implementation contract, reducing proxy contract complexity +- **Self-Contained**: Each implementation contains its own upgrade authorization logic +- **ERC-1967 Compatible**: Uses standardized storage slots for implementation addresses + +### ERC-7201 Namespaced Storage + +All upgradeable contracts use ERC-7201 namespaced storage to prevent storage collisions: +- Storage variables are grouped into structs +- Each contract has a unique storage namespace calculated using `keccak256` +- Storage slots are deterministically calculated to avoid collisions + +## Contracts Converted + +### 1. GlobalParams + +**Storage Namespace**: `ccprotocol.storage.GlobalParams` + +**Key Changes**: +- Converted from regular contract to UUPS upgradeable +- Constructor logic moved to `initialize()` function +- All state variables moved to `GlobalParamsStorage` struct +- Added `_authorizeUpgrade()` function restricted to owner + +**Upgrade Authorization**: Only the contract owner can upgrade + +### 2. TreasuryFactory + +**Storage Namespace**: `ccprotocol.storage.TreasuryFactory` + +**Key Changes**: +- Converted from regular contract to UUPS upgradeable +- Constructor logic moved to `initialize()` function +- All state variables moved to `TreasuryFactoryStorage` struct +- Added `_authorizeUpgrade()` function restricted to protocol admin + +**Upgrade Authorization**: Only the protocol admin can upgrade + +### 3. CampaignInfoFactory + +**Storage Namespace**: `ccprotocol.storage.CampaignInfoFactory` + +**Key Changes**: +- Converted from regular contract to UUPS upgradeable +- Constructor logic moved to `initialize()` function +- All state variables moved to `CampaignInfoFactoryStorage` struct +- Added `_authorizeUpgrade()` function restricted to owner +- Removed legacy `_initialize()` function + +**Upgrade Authorization**: Only the contract owner can upgrade + +### 4. AdminAccessChecker + +**Storage Namespace**: `ccprotocol.storage.AdminAccessChecker` + +**Key Changes**: +- Converted to use namespaced storage +- `GLOBAL_PARAMS` moved to `AdminAccessCheckerStorage` struct +- Compatible with upgradeable contracts inheriting from it + +## Security Considerations + +### Initialization Protection + +All upgradeable contracts implement the following security measures: + +1. **Constructor Disabling**: Implementation contracts call `_disableInitializers()` in their constructor to prevent direct initialization +2. **Single Initialization**: The `initializer` modifier ensures `initialize()` can only be called once +3. **Upgrade Authorization**: Each contract restricts upgrades to authorized addresses + +### Storage Safety + +1. **Namespaced Storage**: Prevents storage collisions between upgrades +2. **Storage Layout Preservation**: Existing storage variables maintain their positions +3. **Gap Variables**: Not used as namespaced storage makes them unnecessary + +### Upgrade Best Practices + +When creating new implementation versions: + +1. ✅ **DO**: + - Add new state variables to the storage struct + - Add new functions + - Fix bugs in existing functions + - Test thoroughly before upgrading + +2. ❌ **DON'T**: + - Change the order of existing storage variables + - Remove existing storage variables + - Change the namespace location constant + - Modify the inheritance hierarchy + +## Deployment + +### Initial Deployment + +1. Deploy the implementation contract +2. Deploy an ERC1967Proxy pointing to the implementation +3. Call the proxy with initialization data + +Example: +```solidity +// 1. Deploy implementation +GlobalParams implementation = new GlobalParams(); + +// 2. Prepare initialization data +bytes memory initData = abi.encodeWithSelector( + GlobalParams.initialize.selector, + protocolAdmin, + protocolFeePercent, + currencies, + tokensPerCurrency +); + +// 3. Deploy proxy +ERC1967Proxy proxy = new ERC1967Proxy(address(implementation), initData); + +// 4. Use proxy address as the contract address +GlobalParams globalParams = GlobalParams(address(proxy)); +``` + +### Upgrading + +To upgrade an existing proxy: + +```solidity +// 1. Deploy new implementation +GlobalParams newImplementation = new GlobalParams(); + +// 2. Call upgradeToAndCall on the proxy (through the current implementation) +GlobalParams(proxyAddress).upgradeToAndCall(address(newImplementation), ""); +``` + +## Scripts + +### Deployment Scripts + +- `DeployGlobalParams.s.sol` - Deploys GlobalParams with UUPS proxy +- `DeployTreasuryFactory.s.sol` - Deploys TreasuryFactory with UUPS proxy +- `DeployCampaignInfoFactory.s.sol` - Deploys CampaignInfoFactory with UUPS proxy +- `DeployAll.s.sol` - Deploys all contracts with proxies + +### Upgrade Scripts + +- `UpgradeGlobalParams.s.sol` - Upgrades GlobalParams implementation +- `UpgradeTreasuryFactory.s.sol` - Upgrades TreasuryFactory implementation +- `UpgradeCampaignInfoFactory.s.sol` - Upgrades CampaignInfoFactory implementation + +### Usage + +Deploy all contracts: +```bash +forge script script/DeployAll.s.sol:DeployAll --rpc-url $RPC_URL --broadcast +``` + +Upgrade GlobalParams: +```bash +forge script script/UpgradeGlobalParams.s.sol:UpgradeGlobalParams --rpc-url $RPC_URL --broadcast +``` + +## Testing + +### Unit Tests + +All existing unit tests have been updated to work with the proxy pattern: +- `GlobalParams.t.sol` - Tests GlobalParams functionality and upgrades +- `TreasuryFactory.t.sol` - Tests TreasuryFactory functionality and upgrades +- `CampaignInfoFactory.t.sol` - Tests CampaignInfoFactory functionality and upgrades + +### Upgrade Tests + +`Upgrades.t.sol` contains comprehensive upgrade scenarios: +- Basic upgrade functionality +- Authorization checks +- Storage slot integrity +- Cross-contract upgrades +- Storage collision prevention +- Double initialization prevention + +### Running Tests + +Run all tests: +```bash +forge test +``` + +Run only upgrade tests: +```bash +forge test --match-path test/foundry/unit/Upgrades.t.sol +``` + +Run with verbosity: +```bash +forge test -vvv +``` + +## Important Notes + +### Immutable Args Encoding + +`CampaignInfo` contracts are created using `clones-with-immutable-args` library, which requires **`abi.encodePacked`** encoding: + +```solidity +// CORRECT - in CampaignInfoFactory.sol +bytes memory args = abi.encodePacked( + treasuryFactoryAddress, // 20 bytes at offset 0 + protocolFeePercent, // 32 bytes at offset 20 + identifierHash // 32 bytes at offset 52 +); +address clone = ClonesWithImmutableArgs.clone(implementation, args); +``` + +```solidity +// CORRECT - in CampaignInfo.sol (reading) +function getCampaignConfig() public view returns (Config memory config) { + config.treasuryFactory = _getArgAddress(0); // Read 20 bytes at offset 0 + config.protocolFeePercent = _getArgUint256(20); // Read 32 bytes at offset 20 + config.identifierHash = bytes32(_getArgUint256(52)); // Read 32 bytes at offset 52 +} +``` + +⚠️ **Do NOT use `abi.encode`** - it adds padding that breaks the offset calculations! + +## Dependencies + +### OpenZeppelin Contracts + +The implementation uses OpenZeppelin's upgradeable contracts: +- `@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol` +- `@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol` +- `@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol` +- `@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol` + +### Installation + +The upgradeable contracts library is installed at: +``` +lib/openzeppelin-contracts-upgradeable/ +``` + +Remappings in `foundry.toml`: +```toml +remappings = [ + "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/", + "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/" +] +``` + +## Storage Layouts + +### GlobalParams Storage + +```solidity +struct GlobalParamsStorage { + address protocolAdminAddress; + uint256 protocolFeePercent; + mapping(bytes32 => bool) platformIsListed; + mapping(bytes32 => address) platformAdminAddress; + mapping(bytes32 => uint256) platformFeePercent; + mapping(bytes32 => bytes32) platformDataOwner; + mapping(bytes32 => bool) platformData; + mapping(bytes32 => bytes32) dataRegistry; + mapping(bytes32 => address[]) currencyToTokens; + Counters.Counter numberOfListedPlatforms; +} +``` + +Storage Location: `0x8c8b3f8e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e00` + +### TreasuryFactory Storage + +```solidity +struct TreasuryFactoryStorage { + mapping(bytes32 => mapping(uint256 => address)) implementationMap; + mapping(address => bool) approvedImplementations; +} +``` + +Storage Location: `0x9c9c4f9e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e00` + +### CampaignInfoFactory Storage + +```solidity +struct CampaignInfoFactoryStorage { + IGlobalParams globalParams; + address treasuryFactoryAddress; + address implementation; + mapping(address => bool) isValidCampaignInfo; + mapping(bytes32 => address) identifierToCampaignInfo; +} +``` + +Storage Location: `0xacac5f0e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e00` + +## Upgrade Checklist + +Before performing an upgrade in production: + +- [ ] New implementation contract deployed and verified +- [ ] All tests passing (including upgrade tests) +- [ ] Storage layout verified for compatibility +- [ ] Authorization requirements met +- [ ] Upgrade transaction prepared and reviewed +- [ ] Rollback plan in place +- [ ] Monitor contract state after upgrade + +## Common Issues and Solutions + +### Issue: Initialization Failed + +**Cause**: Trying to initialize an implementation contract directly + +**Solution**: Always initialize through the proxy, not the implementation + +### Issue: Unauthorized Upgrade + +**Cause**: Attempting upgrade from non-authorized address + +**Solution**: Ensure the caller is: +- GlobalParams: contract owner +- TreasuryFactory: protocol admin +- CampaignInfoFactory: contract owner + +### Issue: Storage Collision + +**Cause**: Modifying existing storage variables in upgrade + +**Solution**: Only add new variables, never modify or remove existing ones + +## References + +- [EIP-1967: Proxy Storage Slots](https://eips.ethereum.org/EIPS/eip-1967) +- [EIP-1822: Universal Upgradeable Proxy Standard (UUPS)](https://eips.ethereum.org/EIPS/eip-1822) +- [ERC-7201: Namespaced Storage Layout](https://eips.ethereum.org/EIPS/eip-7201) +- [OpenZeppelin UUPS Proxies](https://docs.openzeppelin.com/contracts/5.x/api/proxy#UUPSUpgradeable) + +## Support + +For questions or issues related to upgrades, please refer to: +- Project documentation +- OpenZeppelin Upgrades documentation +- Foundry documentation for testing upgradeable contracts + diff --git a/docs/book.toml b/docs/book.toml index a1a4f706..def08238 100644 --- a/docs/book.toml +++ b/docs/book.toml @@ -6,6 +6,7 @@ title = "" no-section-label = true additional-js = ["solidity.min.js"] additional-css = ["book.css"] +mathjax-support = true git-repository-url = "https://github.com/ccprotocol/ccprotocol-contracts-internal" [output.html.fold] diff --git a/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md b/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md index da768f0f..cd7c451b 100644 --- a/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md +++ b/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md @@ -1,5 +1,5 @@ # CampaignInfo -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/CampaignInfo.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/CampaignInfo.sol) **Inherits:** [ICampaignData](/src/interfaces/ICampaignData.sol/interface.ICampaignData.md), [ICampaignInfo](/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md), Ownable, [PausableCancellable](/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md), [TimestampChecker](/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), [AdminAccessChecker](/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md), Initializable @@ -57,6 +57,20 @@ bytes32[] private s_approvedPlatformHashes; ``` +### s_acceptedTokens + +```solidity +address[] private s_acceptedTokens; +``` + + +### s_isAcceptedToken + +```solidity +mapping(address => bool) private s_isAcceptedToken; +``` + + ## Functions ### getApprovedPlatformHashes @@ -69,7 +83,7 @@ function getApprovedPlatformHashes() external view returns (bytes32[] memory); ```solidity -constructor(address creator) Ownable(creator); +constructor() Ownable(_msgSender()); ``` ### initialize @@ -82,7 +96,8 @@ function initialize( bytes32[] calldata selectedPlatformHash, bytes32[] calldata platformDataKey, bytes32[] calldata platformDataValue, - CampaignData calldata campaignData + CampaignData calldata campaignData, + address[] calldata acceptedTokens ) external initializer; ``` @@ -246,34 +261,70 @@ function getGoalAmount() external view override returns (uint256); |``|`uint256`|The funding goal amount of the campaign.| -### getTokenAddress +### getProtocolFeePercent -Retrieves the address of the token used in the campaign. +Retrieves the protocol fee percentage for the campaign. ```solidity -function getTokenAddress() external view override returns (address); +function getProtocolFeePercent() external view override returns (uint256); ``` **Returns** |Name|Type|Description| |----|----|-----------| -|``|`address`|The address of the campaign's token.| +|``|`uint256`|The protocol fee percentage applied to the campaign.| -### getProtocolFeePercent +### getCampaignCurrency -Retrieves the protocol fee percentage for the campaign. +Retrieves the campaign's currency identifier. ```solidity -function getProtocolFeePercent() external view override returns (uint256); +function getCampaignCurrency() external view override returns (bytes32); ``` **Returns** |Name|Type|Description| |----|----|-----------| -|``|`uint256`|The protocol fee percentage applied to the campaign.| +|``|`bytes32`|The bytes32 currency identifier for the campaign.| + + +### getAcceptedTokens + +Retrieves the cached accepted tokens for the campaign. + + +```solidity +function getAcceptedTokens() external view override returns (address[] memory); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`address[]`|An array of token addresses accepted for the campaign.| + + +### isTokenAccepted + +Checks if a token is accepted for the campaign. + + +```solidity +function isTokenAccepted(address token) external view override returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`token`|`address`|The token address to check.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|True if the token is accepted; otherwise, false.| ### paused @@ -636,7 +687,6 @@ error CampaignInfoPlatformAlreadyApproved(bytes32 platformHash); ```solidity struct Config { address treasuryFactory; - address token; uint256 protocolFeePercent; bytes32 identifierHash; } diff --git a/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md b/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md index 60704680..9c5701d6 100644 --- a/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md +++ b/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md @@ -1,84 +1,76 @@ # CampaignInfoFactory -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/CampaignInfoFactory.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/CampaignInfoFactory.sol) **Inherits:** -Initializable, [ICampaignInfoFactory](/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md), Ownable +Initializable, [ICampaignInfoFactory](/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md), OwnableUpgradeable, UUPSUpgradeable Factory contract for creating campaign information contracts. +*UUPS Upgradeable contract with ERC-7201 namespaced storage* -## State Variables -### GLOBAL_PARAMS - -```solidity -IGlobalParams private GLOBAL_PARAMS; -``` - -### s_treasuryFactoryAddress +## State Variables +### CAMPAIGN_INFO_FACTORY_STORAGE_LOCATION ```solidity -address private s_treasuryFactoryAddress; +bytes32 private constant CAMPAIGN_INFO_FACTORY_STORAGE_LOCATION = + 0x2857858a392b093e1f8b3f368c2276ce911f27cef445605a2932ebe945968d00; ``` -### s_initialized - -```solidity -bool private s_initialized; -``` - +## Functions +### _getCampaignInfoFactoryStorage -### s_implementation ```solidity -address private s_implementation; +function _getCampaignInfoFactoryStorage() private pure returns (CampaignInfoFactoryStorage storage $); ``` +### constructor -### isValidCampaignInfo - -```solidity -mapping(address => bool) public isValidCampaignInfo; -``` - +*Constructor that disables initializers to prevent implementation contract initialization* -### identifierToCampaignInfo ```solidity -mapping(bytes32 => address) public identifierToCampaignInfo; +constructor(); ``` +### initialize -## Functions -### constructor +Initializes the CampaignInfoFactory contract. ```solidity -constructor(IGlobalParams globalParams, address campaignImplementation) Ownable(msg.sender); +function initialize( + address initialOwner, + IGlobalParams globalParams, + address campaignImplementation, + address treasuryFactoryAddress +) public initializer; ``` **Parameters** |Name|Type|Description| |----|----|-----------| +|`initialOwner`|`address`|The address that will own the factory| |`globalParams`|`IGlobalParams`|The address of the global parameters contract.| -|`campaignImplementation`|`address`|| +|`campaignImplementation`|`address`|The address of the campaign implementation contract.| +|`treasuryFactoryAddress`|`address`|The address of the treasury factory contract.| -### _initialize +### _authorizeUpgrade -*Initializes the factory with treasury factory address.* +*Function that authorizes an upgrade to a new implementation* ```solidity -function _initialize(address treasuryFactoryAddress, address globalParams) external onlyOwner initializer; +function _authorizeUpgrade(address newImplementation) internal override onlyOwner; ``` **Parameters** |Name|Type|Description| |----|----|-----------| -|`treasuryFactoryAddress`|`address`|The address of the treasury factory contract.| -|`globalParams`|`address`|The address of the global parameters contract.| +|`newImplementation`|`address`|Address of the new implementation| ### createCampaign @@ -111,7 +103,7 @@ function createCampaign( |`selectedPlatformHash`|`bytes32[]`|An array of platform identifiers selected for the campaign.| |`platformDataKey`|`bytes32[]`|An array of platform-specific data keys.| |`platformDataValue`|`bytes32[]`|An array of platform-specific data values.| -|`campaignData`|`CampaignData`|The struct containing campaign launch details.| +|`campaignData`|`CampaignData`|The struct containing campaign launch details (including currency).| ### updateImplementation @@ -129,15 +121,49 @@ function updateImplementation(address newImplementation) external override onlyO |`newImplementation`|`address`|The address of the camapaignInfo implementation contract.| -## Errors -### CampaignInfoFactoryAlreadyInitialized -*Emitted when the factory is initialized.* +### isValidCampaignInfo + +Check if a campaign info address is valid ```solidity -error CampaignInfoFactoryAlreadyInitialized(); +function isValidCampaignInfo(address campaignInfo) external view returns (bool); ``` +**Parameters** +|Name|Type|Description| +|----|----|-----------| +|`campaignInfo`|`address`|The campaign info address to check| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|bool True if valid, false otherwise| + + +### identifierToCampaignInfo + +Get campaign info address from identifier + + +```solidity +function identifierToCampaignInfo(bytes32 identifierHash) external view returns (address); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`identifierHash`|`bytes32`|The identifier hash| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`address`|address The campaign info address| + + +## Errors ### CampaignInfoFactoryInvalidInput *Emitted when invalid input is provided.* @@ -166,3 +192,27 @@ error CampaignInfoFactoryPlatformNotListed(bytes32 platformHash); error CampaignInfoFactoryCampaignWithSameIdentifierExists(bytes32 identifierHash, address cloneExists); ``` +### CampaignInfoInvalidTokenList +*Emitted when the campaign currency has no tokens.* + + +```solidity +error CampaignInfoInvalidTokenList(); +``` + +## Structs +### CampaignInfoFactoryStorage +**Note:** +storage-location: erc7201:ccprotocol.storage.CampaignInfoFactory + + +```solidity +struct CampaignInfoFactoryStorage { + IGlobalParams globalParams; + address treasuryFactoryAddress; + address implementation; + mapping(address => bool) isValidCampaignInfo; + mapping(bytes32 => address) identifierToCampaignInfo; +} +``` + diff --git a/docs/src/src/GlobalParams.sol/contract.GlobalParams.md b/docs/src/src/GlobalParams.sol/contract.GlobalParams.md index 8595aaff..4a19700f 100644 --- a/docs/src/src/GlobalParams.sol/contract.GlobalParams.md +++ b/docs/src/src/GlobalParams.sol/contract.GlobalParams.md @@ -1,130 +1,152 @@ # GlobalParams -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/GlobalParams.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/GlobalParams.sol) **Inherits:** -[IGlobalParams](/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md), Ownable +Initializable, [IGlobalParams](/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md), OwnableUpgradeable, UUPSUpgradeable Manages global parameters and platform information. +*UUPS Upgradeable contract with ERC-7201 namespaced storage* + ## State Variables -### ZERO_BYTES +### GLOBAL_PARAMS_STORAGE_LOCATION ```solidity -bytes32 private constant ZERO_BYTES = 0x0000000000000000000000000000000000000000000000000000000000000000; +bytes32 private constant GLOBAL_PARAMS_STORAGE_LOCATION = + 0x83d0145f7c1378f10048390769ec94f999b3ba6d94904b8fd7251512962b1c00; ``` -### s_protocolAdminAddress +### ZERO_BYTES ```solidity -address private s_protocolAdminAddress; +bytes32 private constant ZERO_BYTES = 0x0000000000000000000000000000000000000000000000000000000000000000; ``` -### s_tokenAddress - -```solidity -address private s_tokenAddress; -``` - +## Functions +### _getGlobalParamsStorage -### s_protocolFeePercent ```solidity -uint256 private s_protocolFeePercent; +function _getGlobalParamsStorage() private pure returns (GlobalParamsStorage storage $); ``` +### notAddressZero + +*Reverts if the input address is zero.* -### s_platformIsListed ```solidity -mapping(bytes32 => bool) private s_platformIsListed; +modifier notAddressZero(address account); ``` +### onlyPlatformAdmin + +*Modifier that restricts function access to platform administrators of a specific platform. +Users attempting to execute functions with this modifier must be the platform admin for the given platform.* -### s_platformAdminAddress ```solidity -mapping(bytes32 => address) private s_platformAdminAddress; +modifier onlyPlatformAdmin(bytes32 platformHash); ``` +**Parameters** +|Name|Type|Description| +|----|----|-----------| +|`platformHash`|`bytes32`|The unique identifier of the platform.| -### s_platformFeePercent - -```solidity -mapping(bytes32 => uint256) private s_platformFeePercent; -``` +### platformIsListed -### s_platformDataOwner ```solidity -mapping(bytes32 => bytes32) private s_platformDataOwner; +modifier platformIsListed(bytes32 platformHash); ``` +### constructor + +*Constructor that disables initializers to prevent implementation contract initialization* -### s_platformData ```solidity -mapping(bytes32 => bool) private s_platformData; +constructor(); ``` +### initialize + +*Initializer function (replaces constructor)* -### s_numberOfListedPlatforms ```solidity -Counters.Counter private s_numberOfListedPlatforms; +function initialize( + address protocolAdminAddress, + uint256 protocolFeePercent, + bytes32[] memory currencies, + address[][] memory tokensPerCurrency +) public initializer; ``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`protocolAdminAddress`|`address`|The address of the protocol admin.| +|`protocolFeePercent`|`uint256`|The protocol fee percentage.| +|`currencies`|`bytes32[]`|The array of currency identifiers.| +|`tokensPerCurrency`|`address[][]`|The array of token arrays for each currency.| -## Functions -### notAddressZero +### _authorizeUpgrade -*Reverts if the input address is zero.* +*Function that authorizes an upgrade to a new implementation* ```solidity -modifier notAddressZero(address account); +function _authorizeUpgrade(address newImplementation) internal override onlyOwner; ``` +**Parameters** -### onlyPlatformAdmin +|Name|Type|Description| +|----|----|-----------| +|`newImplementation`|`address`|Address of the new implementation| -*Modifier that restricts function access to platform administrators of a specific platform. -Users attempting to execute functions with this modifier must be the platform admin for the given platform.* + +### addToRegistry + +Adds a key-value pair to the data registry. ```solidity -modifier onlyPlatformAdmin(bytes32 platformHash); +function addToRegistry(bytes32 key, bytes32 value) external onlyOwner; ``` **Parameters** |Name|Type|Description| |----|----|-----------| -|`platformHash`|`bytes32`|The unique identifier of the platform.| - +|`key`|`bytes32`|The registry key.| +|`value`|`bytes32`|The registry value.| -### platformIsListed +### getFromRegistry -```solidity -modifier platformIsListed(bytes32 platformHash); -``` - -### constructor +Retrieves a value from the data registry. ```solidity -constructor(address protocolAdminAddress, address tokenAddress, uint256 protocolFeePercent) - Ownable(protocolAdminAddress); +function getFromRegistry(bytes32 key) external view returns (bytes32 value); ``` **Parameters** |Name|Type|Description| |----|----|-----------| -|`protocolAdminAddress`|`address`|The address of the protocol admin.| -|`tokenAddress`|`address`|The address of the token contract.| -|`protocolFeePercent`|`uint256`|The protocol fee percentage.| +|`key`|`bytes32`|The registry key.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`value`|`bytes32`|The registry value.| ### getPlatformAdminAddress @@ -183,21 +205,6 @@ function getProtocolAdminAddress() external view override returns (address); |``|`address`|The admin address of the protocol.| -### getTokenAddress - -Retrieves the address of the protocol's native token. - - -```solidity -function getTokenAddress() external view override returns (address); -``` -**Returns** - -|Name|Type|Description| -|----|----|-----------| -|``|`address`|The address of the native token.| - - ### getProtocolFeePercent Retrieves the protocol fee percentage. @@ -396,21 +403,6 @@ function updateProtocolAdminAddress(address protocolAdminAddress) |`protocolAdminAddress`|`address`|| -### updateTokenAddress - -Updates the address of the protocol's native token. - - -```solidity -function updateTokenAddress(address tokenAddress) external override onlyOwner notAddressZero(tokenAddress); -``` -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`tokenAddress`|`address`|| - - ### updateProtocolFeePercent Updates the protocol fee percentage. @@ -447,6 +439,59 @@ function updatePlatformAdminAddress(bytes32 platformHash, address platformAdminA |`platformAdminAddress`|`address`|| +### addTokenToCurrency + +Adds a token to a currency. + + +```solidity +function addTokenToCurrency(bytes32 currency, address token) external override onlyOwner notAddressZero(token); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`currency`|`bytes32`|The currency identifier.| +|`token`|`address`|The token address to add.| + + +### removeTokenFromCurrency + +Removes a token from a currency. + + +```solidity +function removeTokenFromCurrency(bytes32 currency, address token) external override onlyOwner notAddressZero(token); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`currency`|`bytes32`|The currency identifier.| +|`token`|`address`|The token address to remove.| + + +### getTokensForCurrency + +Retrieves all tokens accepted for a specific currency. + + +```solidity +function getTokensForCurrency(bytes32 currency) external view override returns (address[] memory); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`currency`|`bytes32`|The currency identifier.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`address[]`|An array of token addresses accepted for the currency.| + + ### _revertIfAddressZero *Reverts if the input address is zero.* @@ -517,19 +562,35 @@ event ProtocolAdminAddressUpdated(address indexed newAdminAddress); |----|----|-----------| |`newAdminAddress`|`address`|The new protocol admin address.| -### TokenAddressUpdated -*Emitted when the token address is updated.* +### TokenAddedToCurrency +*Emitted when a token is added to a currency.* ```solidity -event TokenAddressUpdated(address indexed newTokenAddress); +event TokenAddedToCurrency(bytes32 indexed currency, address indexed token); ``` **Parameters** |Name|Type|Description| |----|----|-----------| -|`newTokenAddress`|`address`|The new token address.| +|`currency`|`bytes32`|The currency identifier.| +|`token`|`address`|The token address added.| + +### TokenRemovedFromCurrency +*Emitted when a token is removed from a currency.* + + +```solidity +event TokenRemovedFromCurrency(bytes32 indexed currency, address indexed token); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`currency`|`bytes32`|The currency identifier.| +|`token`|`address`|The token address removed.| ### ProtocolFeePercentUpdated *Emitted when the protocol fee percent is updated.* @@ -590,6 +651,21 @@ event PlatformDataRemoved(bytes32 indexed platformHash, bytes32 platformDataKey) |`platformHash`|`bytes32`|The identifier of the platform.| |`platformDataKey`|`bytes32`|The data key removed from the platform.| +### DataAddedToRegistry +*Emitted when data is added to the registry.* + + +```solidity +event DataAddedToRegistry(bytes32 indexed key, bytes32 value); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`key`|`bytes32`|The registry key.| +|`value`|`bytes32`|The registry value.| + ## Errors ### GlobalParamsInvalidInput *Throws when the input address is zero.* @@ -687,3 +763,61 @@ error GlobalParamsPlatformDataSlotTaken(); error GlobalParamsUnauthorized(); ``` +### GlobalParamsCurrencyTokenLengthMismatch +*Throws when currency and token arrays length mismatch.* + + +```solidity +error GlobalParamsCurrencyTokenLengthMismatch(); +``` + +### GlobalParamsCurrencyHasNoTokens +*Throws when a currency has no tokens registered.* + + +```solidity +error GlobalParamsCurrencyHasNoTokens(bytes32 currency); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`currency`|`bytes32`|The currency identifier.| + +### GlobalParamsTokenNotInCurrency +*Throws when a token is not found in a currency.* + + +```solidity +error GlobalParamsTokenNotInCurrency(bytes32 currency, address token); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`currency`|`bytes32`|The currency identifier.| +|`token`|`address`|The token address.| + +## Structs +### GlobalParamsStorage +**Note:** +storage-location: erc7201:ccprotocol.storage.GlobalParams + + +```solidity +struct GlobalParamsStorage { + address protocolAdminAddress; + uint256 protocolFeePercent; + mapping(bytes32 => bool) platformIsListed; + mapping(bytes32 => address) platformAdminAddress; + mapping(bytes32 => uint256) platformFeePercent; + mapping(bytes32 => bytes32) platformDataOwner; + mapping(bytes32 => bool) platformData; + mapping(bytes32 => bytes32) dataRegistry; + mapping(bytes32 => address[]) currencyToTokens; + Counters.Counter numberOfListedPlatforms; +} +``` + diff --git a/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md b/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md index adfc50cb..5c414cd0 100644 --- a/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md +++ b/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md @@ -1,36 +1,69 @@ # TreasuryFactory -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/TreasuryFactory.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/TreasuryFactory.sol) **Inherits:** -[ITreasuryFactory](/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md), [AdminAccessChecker](/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md) +Initializable, [ITreasuryFactory](/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md), [AdminAccessChecker](/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md), UUPSUpgradeable + +Factory contract for creating treasury contracts + +*UUPS Upgradeable contract with ERC-7201 namespaced storage* ## State Variables -### implementationMap +### TREASURY_FACTORY_STORAGE_LOCATION ```solidity -mapping(bytes32 => mapping(uint256 => address)) private implementationMap; +bytes32 private constant TREASURY_FACTORY_STORAGE_LOCATION = + 0x96b7de8c171ef460648aea35787d043e89feb6b6de2623a1e6f17a91b9c9e900; ``` -### approvedImplementations +## Functions +### _getTreasuryFactoryStorage + ```solidity -mapping(address => bool) private approvedImplementations; +function _getTreasuryFactoryStorage() private pure returns (TreasuryFactoryStorage storage $); ``` - -## Functions ### constructor +*Constructor that disables initializers to prevent implementation contract initialization* + + +```solidity +constructor(); +``` + +### initialize + Initializes the TreasuryFactory contract. -*This constructor sets the address of the GlobalParams contract as the admin.* + +```solidity +function initialize(IGlobalParams globalParams) public initializer; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`globalParams`|`IGlobalParams`|The address of the GlobalParams contract| + + +### _authorizeUpgrade + +*Function that authorizes an upgrade to a new implementation* ```solidity -constructor(IGlobalParams globalParams); +function _authorizeUpgrade(address newImplementation) internal override onlyProtocolAdmin; ``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`newImplementation`|`address`|Address of the new implementation| + ### registerTreasuryImplementation @@ -191,3 +224,16 @@ error TreasuryFactoryTreasuryInitializationFailed(); error TreasuryFactorySettingPlatformInfoFailed(); ``` +## Structs +### TreasuryFactoryStorage +**Note:** +storage-location: erc7201:ccprotocol.storage.TreasuryFactory + + +```solidity +struct TreasuryFactoryStorage { + mapping(bytes32 => mapping(uint256 => address)) implementationMap; + mapping(address => bool) approvedImplementations; +} +``` + diff --git a/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md b/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md index 5b924e5c..a605c9bf 100644 --- a/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md +++ b/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md @@ -1,12 +1,12 @@ # ICampaignData -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/interfaces/ICampaignData.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/interfaces/ICampaignData.sol) An interface for managing campaign data in a CCP. ## Structs ### CampaignData -*Struct to represent campaign data, including launch time, deadline, and goal amount.* +*Struct to represent campaign data, including launch time, deadline, goal amount, and currency.* ```solidity @@ -14,6 +14,7 @@ struct CampaignData { uint256 launchTime; uint256 deadline; uint256 goalAmount; + bytes32 currency; } ``` diff --git a/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md b/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md index d0e78480..1844c384 100644 --- a/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md +++ b/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md @@ -1,5 +1,5 @@ # ICampaignInfo -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/interfaces/ICampaignInfo.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/interfaces/ICampaignInfo.sol) An interface for managing campaign information in a crowdfunding system. @@ -137,34 +137,70 @@ function getGoalAmount() external view returns (uint256); |``|`uint256`|The funding goal amount of the campaign.| -### getTokenAddress +### getProtocolFeePercent -Retrieves the address of the token used in the campaign. +Retrieves the protocol fee percentage for the campaign. ```solidity -function getTokenAddress() external view returns (address); +function getProtocolFeePercent() external view returns (uint256); ``` **Returns** |Name|Type|Description| |----|----|-----------| -|``|`address`|The address of the campaign's token.| +|``|`uint256`|The protocol fee percentage applied to the campaign.| -### getProtocolFeePercent +### getCampaignCurrency -Retrieves the protocol fee percentage for the campaign. +Retrieves the campaign's currency identifier. ```solidity -function getProtocolFeePercent() external view returns (uint256); +function getCampaignCurrency() external view returns (bytes32); ``` **Returns** |Name|Type|Description| |----|----|-----------| -|``|`uint256`|The protocol fee percentage applied to the campaign.| +|``|`bytes32`|The bytes32 currency identifier for the campaign.| + + +### getAcceptedTokens + +Retrieves the cached accepted tokens for the campaign. + + +```solidity +function getAcceptedTokens() external view returns (address[] memory); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`address[]`|An array of token addresses accepted for the campaign.| + + +### isTokenAccepted + +Checks if a token is accepted for the campaign. + + +```solidity +function isTokenAccepted(address token) external view returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`token`|`address`|The token address to check.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|True if the token is accepted; otherwise, false.| ### getPlatformFeePercent diff --git a/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md b/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md index 8953d56c..6f9bb218 100644 --- a/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md +++ b/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md @@ -1,5 +1,5 @@ # ICampaignInfoFactory -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/interfaces/ICampaignInfoFactory.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/interfaces/ICampaignInfoFactory.sol) **Inherits:** [ICampaignData](/src/interfaces/ICampaignData.sol/interface.ICampaignData.md) @@ -38,7 +38,7 @@ function createCampaign( |`selectedPlatformHash`|`bytes32[]`|An array of platform identifiers selected for the campaign.| |`platformDataKey`|`bytes32[]`|An array of platform-specific data keys.| |`platformDataValue`|`bytes32[]`|An array of platform-specific data values.| -|`campaignData`|`CampaignData`|The struct containing campaign launch details.| +|`campaignData`|`CampaignData`|The struct containing campaign launch details (including currency).| ### updateImplementation diff --git a/docs/src/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md b/docs/src/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md index e3206342..e542e253 100644 --- a/docs/src/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md +++ b/docs/src/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md @@ -1,5 +1,5 @@ # ICampaignPaymentTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/4076c45194ab23360a65e56402b026ef44f70a42/src/interfaces/ICampaignPaymentTreasury.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/interfaces/ICampaignPaymentTreasury.sol) An interface for managing campaign payment treasury contracts. @@ -11,20 +11,54 @@ Creates a new payment entry with the specified details. ```solidity -function createPayment(bytes32 paymentId, address buyerAddress, bytes32 itemId, uint256 amount, uint256 expiration) - external; +function createPayment( + bytes32 paymentId, + bytes32 buyerId, + bytes32 itemId, + address paymentToken, + uint256 amount, + uint256 expiration +) external; ``` **Parameters** |Name|Type|Description| |----|----|-----------| |`paymentId`|`bytes32`|A unique identifier for the payment.| -|`buyerAddress`|`address`|The address of the buyer initiating the payment.| +|`buyerId`|`bytes32`|The id of the buyer initiating the payment.| |`itemId`|`bytes32`|The identifier of the item being purchased.| +|`paymentToken`|`address`|The token to use for the payment.| |`amount`|`uint256`|The amount to be paid for the item.| |`expiration`|`uint256`|The timestamp after which the payment expires.| +### processCryptoPayment + +Allows a buyer to make a direct crypto payment for an item. + +*This function transfers tokens directly from the buyer's wallet and confirms the payment immediately.* + + +```solidity +function processCryptoPayment( + bytes32 paymentId, + bytes32 itemId, + address buyerAddress, + address paymentToken, + uint256 amount +) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the payment.| +|`itemId`|`bytes32`|The identifier of the item being purchased.| +|`buyerAddress`|`address`|The address of the buyer making the payment.| +|`paymentToken`|`address`|The token to use for the payment.| +|`amount`|`uint256`|The amount to be paid for the item.| + + ### cancelPayment Cancels an existing payment with the given payment ID. @@ -104,6 +138,21 @@ function claimRefund(bytes32 paymentId, address refundAddress) external; |`refundAddress`|`address`|The address where the refunded amount should be sent.| +### claimRefund + +Allows buyers to claim refunds for crypto payments, or platform admin to process refunds on behalf of buyers. + + +```solidity +function claimRefund(bytes32 paymentId) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the refundable payment.| + + ### getplatformHash Retrieves the platform identifier associated with the treasury. diff --git a/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md b/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md index a69caa0a..792e49ea 100644 --- a/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md +++ b/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md @@ -1,5 +1,5 @@ # ICampaignTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/interfaces/ICampaignTreasury.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/interfaces/ICampaignTreasury.sol) An interface for managing campaign treasury contracts. diff --git a/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md b/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md index 4309f0e5..227fcfce 100644 --- a/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md +++ b/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md @@ -1,5 +1,5 @@ # IGlobalParams -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/interfaces/IGlobalParams.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/interfaces/IGlobalParams.sol) An interface for accessing and managing global parameters of the protocol. @@ -77,21 +77,6 @@ function getProtocolAdminAddress() external view returns (address); |``|`address`|The admin address of the protocol.| -### getTokenAddress - -Retrieves the address of the protocol's native token. - - -```solidity -function getTokenAddress() external view returns (address); -``` -**Returns** - -|Name|Type|Description| -|----|----|-----------| -|``|`address`|The address of the native token.| - - ### getProtocolFeePercent Retrieves the protocol fee percentage. @@ -185,49 +170,87 @@ function updateProtocolAdminAddress(address _protocolAdminAddress) external; |`_protocolAdminAddress`|`address`|The new admin address of the protocol.| -### updateTokenAddress +### updateProtocolFeePercent -Updates the address of the protocol's native token. +Updates the protocol fee percentage. ```solidity -function updateTokenAddress(address _tokenAddress) external; +function updateProtocolFeePercent(uint256 _protocolFeePercent) external; ``` **Parameters** |Name|Type|Description| |----|----|-----------| -|`_tokenAddress`|`address`|The new address of the native token.| +|`_protocolFeePercent`|`uint256`|The new protocol fee percentage as a uint256 value.| -### updateProtocolFeePercent +### updatePlatformAdminAddress -Updates the protocol fee percentage. +Updates the admin address of a platform. ```solidity -function updateProtocolFeePercent(uint256 _protocolFeePercent) external; +function updatePlatformAdminAddress(bytes32 _platformHash, address _platformAdminAddress) external; ``` **Parameters** |Name|Type|Description| |----|----|-----------| -|`_protocolFeePercent`|`uint256`|The new protocol fee percentage as a uint256 value.| +|`_platformHash`|`bytes32`|The unique identifier of the platform.| +|`_platformAdminAddress`|`address`|The new admin address of the platform.| -### updatePlatformAdminAddress +### addTokenToCurrency -Updates the admin address of a platform. +Adds a token to a currency. ```solidity -function updatePlatformAdminAddress(bytes32 _platformHash, address _platformAdminAddress) external; +function addTokenToCurrency(bytes32 currency, address token) external; ``` **Parameters** |Name|Type|Description| |----|----|-----------| -|`_platformHash`|`bytes32`|The unique identifier of the platform.| -|`_platformAdminAddress`|`address`|The new admin address of the platform.| +|`currency`|`bytes32`|The currency identifier.| +|`token`|`address`|The token address to add.| + + +### removeTokenFromCurrency + +Removes a token from a currency. + + +```solidity +function removeTokenFromCurrency(bytes32 currency, address token) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`currency`|`bytes32`|The currency identifier.| +|`token`|`address`|The token address to remove.| + + +### getTokensForCurrency + +Retrieves all tokens accepted for a specific currency. + + +```solidity +function getTokensForCurrency(bytes32 currency) external view returns (address[] memory); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`currency`|`bytes32`|The currency identifier.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`address[]`|An array of token addresses accepted for the currency.| diff --git a/docs/src/src/interfaces/IItem.sol/interface.IItem.md b/docs/src/src/interfaces/IItem.sol/interface.IItem.md index c2a8852d..a1776f4f 100644 --- a/docs/src/src/interfaces/IItem.sol/interface.IItem.md +++ b/docs/src/src/interfaces/IItem.sol/interface.IItem.md @@ -1,5 +1,5 @@ # IItem -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/interfaces/IItem.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/interfaces/IItem.sol) An interface for managing items and their attributes. diff --git a/docs/src/src/interfaces/IReward.sol/interface.IReward.md b/docs/src/src/interfaces/IReward.sol/interface.IReward.md index 29bd5932..3320ff59 100644 --- a/docs/src/src/interfaces/IReward.sol/interface.IReward.md +++ b/docs/src/src/interfaces/IReward.sol/interface.IReward.md @@ -1,5 +1,5 @@ # IReward -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/interfaces/IReward.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/interfaces/IReward.sol) An interface for managing rewards in a campaign. diff --git a/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md b/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md index a1410243..608b890c 100644 --- a/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md +++ b/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md @@ -1,5 +1,5 @@ # ITreasuryFactory -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/interfaces/ITreasuryFactory.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/interfaces/ITreasuryFactory.sol) *Interface for the TreasuryFactory contract, which registers, approves, and deploys treasury clones.* diff --git a/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md b/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md index 38e0393c..3fb14987 100644 --- a/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md +++ b/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md @@ -1,5 +1,5 @@ # AllOrNothing -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/treasuries/AllOrNothing.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/treasuries/AllOrNothing.sol) **Inherits:** [IReward](/src/interfaces/IReward.sol/interface.IReward.md), [BaseTreasury](/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md), [TimestampChecker](/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), ERC721Burnable @@ -29,6 +29,13 @@ mapping(bytes32 => Reward) private s_reward; ``` +### s_tokenIdToPledgeToken + +```solidity +mapping(uint256 => address) private s_tokenIdToPledgeToken; +``` + + ### s_tokenIdCounter ```solidity @@ -183,7 +190,7 @@ The non-reward tiers cannot be pledged for without a reward.* ```solidity -function pledgeForAReward(address backer, uint256 shippingFee, bytes32[] calldata reward) +function pledgeForAReward(address backer, address pledgeToken, uint256 shippingFee, bytes32[] calldata reward) external currentTimeIsWithinRange(INFO.getLaunchTime(), INFO.getDeadline()) whenCampaignNotPaused @@ -196,7 +203,8 @@ function pledgeForAReward(address backer, uint256 shippingFee, bytes32[] calldat |Name|Type|Description| |----|----|-----------| |`backer`|`address`|The address of the backer making the pledge.| -|`shippingFee`|`uint256`|| +|`pledgeToken`|`address`|The token address to use for the pledge.| +|`shippingFee`|`uint256`|The shipping fee amount.| |`reward`|`bytes32[]`|An array of reward names.| @@ -206,7 +214,7 @@ Allows a backer to pledge without selecting a reward. ```solidity -function pledgeWithoutAReward(address backer, uint256 pledgeAmount) +function pledgeWithoutAReward(address backer, address pledgeToken, uint256 pledgeAmount) external currentTimeIsWithinRange(INFO.getLaunchTime(), INFO.getDeadline()) whenCampaignNotPaused @@ -219,6 +227,7 @@ function pledgeWithoutAReward(address backer, uint256 pledgeAmount) |Name|Type|Description| |----|----|-----------| |`backer`|`address`|The address of the backer making the pledge.| +|`pledgeToken`|`address`|The token address to use for the pledge.| |`pledgeAmount`|`uint256`|The amount of the pledge.| @@ -289,6 +298,7 @@ function _checkSuccessCondition() internal view virtual override returns (bool); ```solidity function _pledge( address backer, + address pledgeToken, bytes32 reward, uint256 pledgeAmount, uint256 shippingFee, @@ -312,7 +322,8 @@ function supportsInterface(bytes4 interfaceId) public view override returns (boo ```solidity event Receipt( address indexed backer, - bytes32 indexed reward, + address indexed pledgeToken, + bytes32 reward, uint256 pledgeAmount, uint256 shippingFee, uint256 tokenId, @@ -325,6 +336,7 @@ event Receipt( |Name|Type|Description| |----|----|-----------| |`backer`|`address`|The address of the backer making the pledge.| +|`pledgeToken`|`address`|The token used for the pledge.| |`reward`|`bytes32`|The name of the reward.| |`pledgeAmount`|`uint256`|The amount pledged.| |`shippingFee`|`uint256`|| @@ -433,6 +445,14 @@ error AllOrNothingFeeAlreadyDisbursed(); error AllOrNothingRewardExists(); ``` +### AllOrNothingTokenNotAccepted +*Emitted when a token is not accepted for the campaign.* + + +```solidity +error AllOrNothingTokenNotAccepted(address token); +``` + ### AllOrNothingNotClaimable *Emitted when claiming an unclaimable refund.* diff --git a/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md b/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md index f86eda45..f613d90f 100644 --- a/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md +++ b/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md @@ -1,5 +1,5 @@ # KeepWhatsRaised -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/treasuries/KeepWhatsRaised.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/treasuries/KeepWhatsRaised.sol) **Inherits:** [IReward](/src/interfaces/IReward.sol/interface.IReward.md), [BaseTreasury](/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md), [TimestampChecker](/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), ERC721Burnable, [ICampaignData](/src/interfaces/ICampaignData.sol/interface.ICampaignData.md) @@ -63,59 +63,66 @@ mapping(bytes32 => uint256) private s_feeValues; ``` -### s_tokenIdCounter +### s_tokenIdToPledgeToken ```solidity -Counters.Counter private s_tokenIdCounter; +mapping(uint256 => address) private s_tokenIdToPledgeToken; ``` -### s_rewardCounter +### s_protocolFeePerToken ```solidity -Counters.Counter private s_rewardCounter; +mapping(address => uint256) private s_protocolFeePerToken; ``` -### s_name +### s_platformFeePerToken ```solidity -string private s_name; +mapping(address => uint256) private s_platformFeePerToken; ``` -### s_symbol +### s_tipPerToken ```solidity -string private s_symbol; +mapping(address => uint256) private s_tipPerToken; ``` -### s_tip +### s_availablePerToken ```solidity -uint256 private s_tip; +mapping(address => uint256) private s_availablePerToken; ``` -### s_platformFee +### s_tokenIdCounter ```solidity -uint256 private s_platformFee; +Counters.Counter private s_tokenIdCounter; ``` -### s_protocolFee +### s_rewardCounter ```solidity -uint256 private s_protocolFee; +Counters.Counter private s_rewardCounter; +``` + + +### s_name + +```solidity +string private s_name; ``` -### s_availablePledgedAmount +### s_symbol ```solidity -uint256 private s_availablePledgedAmount; +string private s_symbol; ``` @@ -169,28 +176,93 @@ CampaignData private s_campaignData; ## Functions +### withdrawalEnabled + +*Ensures that withdrawals are currently enabled. +Reverts with `KeepWhatsRaisedDisabled` if the withdrawal approval flag is not set.* + + +```solidity +modifier withdrawalEnabled(); +``` + +### onlyBeforeConfigLock + +*Restricts execution to only occur before the configuration lock period. +Reverts with `KeepWhatsRaisedConfigLocked` if called too close to or after the campaign deadline. +The lock period is defined as the duration before the deadline during which configuration changes are not allowed.* + + +```solidity +modifier onlyBeforeConfigLock(); +``` + +### onlyPlatformAdminOrCampaignOwner + +Restricts access to only the platform admin or the campaign owner. + +*Checks if `_msgSender()` is either the platform admin (via `INFO.getPlatformAdminAddress`) +or the campaign owner (via `INFO.owner()`). Reverts with `KeepWhatsRaisedUnAuthorized` if not authorized.* + + +```solidity +modifier onlyPlatformAdminOrCampaignOwner(); +``` ### constructor -_Initializes the KeepWhatsRaised contract._ +*Constructor for the KeepWhatsRaised contract.* + ```solidity -constructor(bytes32 platformHash, address infoAddress) AllOrNothing(platformHash, infoAddress); +constructor() ERC721("", ""); ``` -**Parameters** -| Name | Type | Description | -| -------------- | --------- | ------------------------------------------------------------ | -| `platformHash` | `bytes32` | The unique identifier of the platform. | -| `infoAddress` | `address` | The address of the associated campaign information contract. | +### initialize -### \_checkSuccessCondition -_Internal function to check the success condition for fee disbursement._ +```solidity +function initialize(bytes32 _platformHash, address _infoAddress, string calldata _name, string calldata _symbol) + external + initializer; +``` + +### name + + +```solidity +function name() public view override returns (string memory); +``` + +### symbol + + +```solidity +function symbol() public view override returns (string memory); +``` + +### getWithdrawalApprovalStatus + +Retrieves the withdrawal approval status. + + +```solidity +function getWithdrawalApprovalStatus() public view returns (bool); +``` + +### getReward + +Retrieves the details of a reward. + ```solidity -function _checkSuccessCondition() internal pure override returns (bool); +function getReward(bytes32 rewardName) external view returns (Reward memory reward); ``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`rewardName`|`bytes32`|The name of the reward.| **Returns** @@ -480,6 +552,7 @@ Sets the payment gateway fee and executes a pledge in a single transaction. function setFeeAndPledge( bytes32 pledgeId, address backer, + address pledgeToken, uint256 pledgeAmount, uint256 tip, uint256 fee, @@ -499,6 +572,7 @@ function setFeeAndPledge( |----|----|-----------| |`pledgeId`|`bytes32`|The unique identifier of the pledge.| |`backer`|`address`|The address of the backer making the pledge.| +|`pledgeToken`|`address`|| |`pledgeAmount`|`uint256`|The amount of the pledge.| |`tip`|`uint256`|An optional tip can be added during the process.| |`fee`|`uint256`|The payment gateway fee to associate with this pledge.| @@ -515,7 +589,7 @@ The non-reward tiers cannot be pledged for without a reward.* ```solidity -function pledgeForAReward(bytes32 pledgeId, address backer, uint256 tip, bytes32[] calldata reward) +function pledgeForAReward(bytes32 pledgeId, address backer, address pledgeToken, uint256 tip, bytes32[] calldata reward) public currentTimeIsWithinRange(getLaunchTime(), getDeadline()) whenCampaignNotPaused @@ -529,6 +603,7 @@ function pledgeForAReward(bytes32 pledgeId, address backer, uint256 tip, bytes32 |----|----|-----------| |`pledgeId`|`bytes32`|The unique identifier of the pledge.| |`backer`|`address`|The address of the backer making the pledge.| +|`pledgeToken`|`address`|The token to use for the pledge.| |`tip`|`uint256`|An optional tip can be added during the process.| |`reward`|`bytes32[]`|An array of reward names.| @@ -547,6 +622,7 @@ setFeeAndPledge (with admin as token source).* function _pledgeForAReward( bytes32 pledgeId, address backer, + address pledgeToken, uint256 tip, bytes32[] calldata reward, address tokenSource @@ -564,6 +640,7 @@ function _pledgeForAReward( |----|----|-----------| |`pledgeId`|`bytes32`|The unique identifier of the pledge.| |`backer`|`address`|The address of the backer making the pledge (receives the NFT).| +|`pledgeToken`|`address`|The token to use for the pledge.| |`tip`|`uint256`|An optional tip can be added during the process.| |`reward`|`bytes32[]`|An array of reward names.| |`tokenSource`|`address`|The address from which tokens will be transferred (either backer for direct calls or admin for setFeeAndPledge calls).| @@ -575,7 +652,7 @@ Allows a backer to pledge without selecting a reward. ```solidity -function pledgeWithoutAReward(bytes32 pledgeId, address backer, uint256 pledgeAmount, uint256 tip) +function pledgeWithoutAReward(bytes32 pledgeId, address backer, address pledgeToken, uint256 pledgeAmount, uint256 tip) public currentTimeIsWithinRange(getLaunchTime(), getDeadline()) whenCampaignNotPaused @@ -589,6 +666,7 @@ function pledgeWithoutAReward(bytes32 pledgeId, address backer, uint256 pledgeAm |----|----|-----------| |`pledgeId`|`bytes32`|The unique identifier of the pledge.| |`backer`|`address`|The address of the backer making the pledge.| +|`pledgeToken`|`address`|The token to use for the pledge.| |`pledgeAmount`|`uint256`|The amount of the pledge.| |`tip`|`uint256`|An optional tip can be added during the process.| @@ -602,7 +680,14 @@ setFeeAndPledge (with admin as token source).* ```solidity -function _pledgeWithoutAReward(bytes32 pledgeId, address backer, uint256 pledgeAmount, uint256 tip, address tokenSource) +function _pledgeWithoutAReward( + bytes32 pledgeId, + address backer, + address pledgeToken, + uint256 pledgeAmount, + uint256 tip, + address tokenSource +) internal currentTimeIsWithinRange(getLaunchTime(), getDeadline()) whenCampaignNotPaused @@ -616,6 +701,7 @@ function _pledgeWithoutAReward(bytes32 pledgeId, address backer, uint256 pledgeA |----|----|-----------| |`pledgeId`|`bytes32`|The unique identifier of the pledge.| |`backer`|`address`|The address of the backer making the pledge (receives the NFT).| +|`pledgeToken`|`address`|The token to use for the pledge.| |`pledgeAmount`|`uint256`|The amount of the pledge.| |`tip`|`uint256`|An optional tip can be added during the process.| |`tokenSource`|`address`|The address from which tokens will be transferred (either backer for direct calls or admin for setFeeAndPledge calls).| @@ -636,7 +722,7 @@ function withdraw() public view override whenNotPaused whenNotCancelled; ```solidity -function withdraw(uint256 amount) +function withdraw(address token, uint256 amount) public onlyPlatformAdminOrCampaignOwner currentTimeIsLess(getDeadline() + s_config.withdrawalDelay) @@ -648,7 +734,8 @@ function withdraw(uint256 amount) |Name|Type|Description| |----|----|-----------| -|`amount`|`uint256`|The withdrawal amount (ignored for final withdrawals). Requirements: - Caller must be authorized. - Withdrawals must be enabled, not paused, and within the allowed time. - For partial withdrawals: - `amount` > 0 and `amount + fees` ≤ available balance. - For final withdrawals: - Available balance > 0 and fees ≤ available balance. Effects: - Deducts fees (flat, cumulative, and Colombian tax if applicable). - Updates available balance. - Transfers net funds to the recipient. Reverts: - If insufficient funds or invalid input. Emits: - `WithdrawalWithFeeSuccessful`.| +|`token`|`address`|The token to withdraw.| +|`amount`|`uint256`|The withdrawal amount (ignored for final withdrawals). Requirements: - Caller must be authorized. - Withdrawals must be enabled, not paused, and within the allowed time. - Token must be accepted for the campaign. - For partial withdrawals: - `amount` > 0 and `amount + fees` ≤ available balance. - For final withdrawals: - Available balance > 0 and fees ≤ available balance. Effects: - Deducts fees (flat, cumulative, and Colombian tax if applicable). - Updates available balance per token. - Transfers net funds to the recipient. Reverts: - If insufficient funds or invalid input. Emits: - `WithdrawalWithFeeSuccessful`.| ### claimRefund @@ -736,6 +823,7 @@ function _checkSuccessCondition() internal view virtual override returns (bool); function _pledge( bytes32 pledgeId, address backer, + address pledgeToken, bytes32 reward, uint256 pledgeAmount, uint256 tip, @@ -754,18 +842,21 @@ all applicable fees. - Applies all configured gross percentage-based fees - Applies payment gateway fee for the given pledge - Applies protocol fee based on protocol configuration -- Accumulates total platform and protocol fees +- Accumulates total platform and protocol fees per token - Records the total deducted fee for the token* ```solidity -function _calculateNetAvailable(bytes32 pledgeId, uint256 tokenId, uint256 pledgeAmount) internal returns (uint256); +function _calculateNetAvailable(bytes32 pledgeId, address pledgeToken, uint256 tokenId, uint256 pledgeAmount) + internal + returns (uint256); ``` **Parameters** |Name|Type|Description| |----|----|-----------| |`pledgeId`|`bytes32`|The unique identifier of the pledge| +|`pledgeToken`|`address`|The token used for the pledge| |`tokenId`|`uint256`|The token ID representing the pledge| |`pledgeAmount`|`uint256`|The original pledged amount before deductions| @@ -819,7 +910,8 @@ function supportsInterface(bytes4 interfaceId) public view override returns (boo ```solidity event Receipt( address indexed backer, - bytes32 indexed reward, + address indexed pledgeToken, + bytes32 reward, uint256 pledgeAmount, uint256 tip, uint256 tokenId, @@ -832,6 +924,7 @@ event Receipt( |Name|Type|Description| |----|----|-----------| |`backer`|`address`|The address of the backer making the pledge.| +|`pledgeToken`|`address`|The token used for the pledge.| |`reward`|`bytes32`|The name of the reward.| |`pledgeAmount`|`uint256`|The amount pledged.| |`tip`|`uint256`|An optional tip can be added during the process.| @@ -1014,6 +1107,14 @@ error KeepWhatsRaisedUnAuthorized(); error KeepWhatsRaisedInvalidInput(); ``` +### KeepWhatsRaisedTokenNotAccepted +*Emitted when a token is not accepted for the campaign.* + + +```solidity +error KeepWhatsRaisedTokenNotAccepted(address token); +``` + ### KeepWhatsRaisedRewardExists *Emitted when a `Reward` already exists for given input.* diff --git a/docs/src/src/treasuries/PaymentTreasury.sol/contract.PaymentTreasury.md b/docs/src/src/treasuries/PaymentTreasury.sol/contract.PaymentTreasury.md index 753d043b..6aa15dbe 100644 --- a/docs/src/src/treasuries/PaymentTreasury.sol/contract.PaymentTreasury.md +++ b/docs/src/src/treasuries/PaymentTreasury.sol/contract.PaymentTreasury.md @@ -1,5 +1,5 @@ # PaymentTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/4076c45194ab23360a65e56402b026ef44f70a42/src/treasuries/PaymentTreasury.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/treasuries/PaymentTreasury.sol) **Inherits:** [BasePaymentTreasury](/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md) @@ -23,7 +23,7 @@ string private s_symbol; ## Functions ### constructor -*Constructor for the AllOrNothing contract.* +*Constructor for the PaymentTreasury contract.* ```solidity @@ -53,6 +53,105 @@ function name() public view returns (string memory); function symbol() public view returns (string memory); ``` +### createPayment + +Creates a new payment entry with the specified details. + + +```solidity +function createPayment( + bytes32 paymentId, + bytes32 buyerId, + bytes32 itemId, + address paymentToken, + uint256 amount, + uint256 expiration +) public override whenNotPaused whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|A unique identifier for the payment.| +|`buyerId`|`bytes32`|The id of the buyer initiating the payment.| +|`itemId`|`bytes32`|The identifier of the item being purchased.| +|`paymentToken`|`address`|The token to use for the payment.| +|`amount`|`uint256`|The amount to be paid for the item.| +|`expiration`|`uint256`|The timestamp after which the payment expires.| + + +### processCryptoPayment + +Allows a buyer to make a direct crypto payment for an item. + +*This function transfers tokens directly from the buyer's wallet and confirms the payment immediately.* + + +```solidity +function processCryptoPayment( + bytes32 paymentId, + bytes32 itemId, + address buyerAddress, + address paymentToken, + uint256 amount +) public override whenNotPaused whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the payment.| +|`itemId`|`bytes32`|The identifier of the item being purchased.| +|`buyerAddress`|`address`|The address of the buyer making the payment.| +|`paymentToken`|`address`|The token to use for the payment.| +|`amount`|`uint256`|The amount to be paid for the item.| + + +### cancelPayment + +Cancels an existing payment with the given payment ID. + + +```solidity +function cancelPayment(bytes32 paymentId) public override whenNotPaused whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the payment to cancel.| + + +### confirmPayment + +Confirms and finalizes the payment associated with the given payment ID. + + +```solidity +function confirmPayment(bytes32 paymentId) public override whenNotPaused whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the payment to confirm.| + + +### confirmPaymentBatch + +Confirms and finalizes multiple payments in a single transaction. + + +```solidity +function confirmPaymentBatch(bytes32[] calldata paymentIds) public override whenNotPaused whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentIds`|`bytes32[]`|An array of unique payment identifiers to be confirmed.| + + ### claimRefund Claims a refund for a specific payment ID. @@ -69,6 +168,21 @@ function claimRefund(bytes32 paymentId, address refundAddress) public override w |`refundAddress`|`address`|The address where the refunded amount should be sent.| +### claimRefund + +Claims a refund for a specific payment ID. + + +```solidity +function claimRefund(bytes32 paymentId) public override whenNotPaused whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the refundable payment.| + + ### disburseFees Disburses fees collected by the treasury. @@ -120,11 +234,3 @@ function _checkSuccessCondition() internal view virtual override returns (bool); error PaymentTreasuryUnAuthorized(); ``` -### PaymentTreasuryFeeAlreadyDisbursed -*Emitted when `disburseFees` after fee is disbursed already.* - - -```solidity -error PaymentTreasuryFeeAlreadyDisbursed(); -``` - diff --git a/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md b/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md index 5b28fcfd..e774d9e3 100644 --- a/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md +++ b/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md @@ -1,25 +1,55 @@ # AdminAccessChecker -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/utils/AdminAccessChecker.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/utils/AdminAccessChecker.sol) + +**Inherits:** +Context *This abstract contract provides access control mechanisms to restrict the execution of specific functions to authorized protocol administrators and platform administrators.* +*Updated to use ERC-7201 namespaced storage for upgradeable contracts* + ## State Variables -### GLOBAL_PARAMS +### ADMIN_ACCESS_CHECKER_STORAGE_LOCATION ```solidity -IGlobalParams internal GLOBAL_PARAMS; +bytes32 private constant ADMIN_ACCESS_CHECKER_STORAGE_LOCATION = + 0x7c2f08fa04c2c7c7ab255a45dbf913d4c236b91c59858917e818398e997f8800; ``` ## Functions +### _getAdminAccessCheckerStorage + + +```solidity +function _getAdminAccessCheckerStorage() private pure returns (AdminAccessCheckerStorage storage $); +``` + ### __AccessChecker_init +*Internal initializer function for AdminAccessChecker* + ```solidity function __AccessChecker_init(IGlobalParams globalParams) internal; ``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`globalParams`|`IGlobalParams`|The IGlobalParams contract instance| + + +### _getGlobalParams + +*Returns the stored GLOBAL_PARAMS for internal use* + + +```solidity +function _getGlobalParams() internal view returns (IGlobalParams); +``` ### onlyProtocolAdmin @@ -82,3 +112,15 @@ function _onlyPlatformAdmin(bytes32 platformHash) private view; error AdminAccessCheckerUnauthorized(); ``` +## Structs +### AdminAccessCheckerStorage +**Note:** +storage-location: erc7201:ccprotocol.storage.AdminAccessChecker + + +```solidity +struct AdminAccessCheckerStorage { + IGlobalParams globalParams; +} +``` + diff --git a/docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md b/docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md index 2d5866ee..fa046084 100644 --- a/docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md +++ b/docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md @@ -1,5 +1,5 @@ # BasePaymentTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/4076c45194ab23360a65e56402b026ef44f70a42/src/utils/BasePaymentTreasury.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/utils/BasePaymentTreasury.sol) **Inherits:** Initializable, [ICampaignPaymentTreasury](/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md), [CampaignAccessChecker](/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md), [PausableCancellable](/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md) @@ -20,6 +20,13 @@ uint256 internal constant PERCENT_DIVIDER = 10000; ``` +### STANDARD_DECIMALS + +```solidity +uint256 internal constant STANDARD_DECIMALS = 18; +``` + + ### PLATFORM_HASH ```solidity @@ -34,17 +41,24 @@ uint256 internal PLATFORM_FEE_PERCENT; ``` -### TOKEN +### s_paymentIdToToken + +```solidity +mapping(bytes32 => address) internal s_paymentIdToToken; +``` + + +### s_platformFeePerToken ```solidity -IERC20 internal TOKEN; +mapping(address => uint256) internal s_platformFeePerToken; ``` -### s_feesDisbursed +### s_protocolFeePerToken ```solidity -bool internal s_feesDisbursed; +mapping(address => uint256) internal s_protocolFeePerToken; ``` @@ -55,24 +69,24 @@ mapping(bytes32 => PaymentInfo) internal s_payment; ``` -### s_pendingPaymentAmount +### s_pendingPaymentPerToken ```solidity -uint256 internal s_pendingPaymentAmount; +mapping(address => uint256) internal s_pendingPaymentPerToken; ``` -### s_confirmedPaymentAmount +### s_confirmedPaymentPerToken ```solidity -uint256 internal s_confirmedPaymentAmount; +mapping(address => uint256) internal s_confirmedPaymentPerToken; ``` -### s_availableConfirmedPaymentAmount +### s_availableConfirmedPerToken ```solidity -uint256 internal s_availableConfirmedPaymentAmount; +mapping(address => uint256) internal s_availableConfirmedPerToken; ``` @@ -100,6 +114,21 @@ modifier whenCampaignNotPaused(); modifier whenCampaignNotCancelled(); ``` +### onlyBuyerOrPlatformAdmin + +Ensures that the caller is either the payment's buyer or the platform admin. + + +```solidity +modifier onlyBuyerOrPlatformAdmin(bytes32 paymentId); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the payment to validate access for.| + + ### getplatformHash Retrieves the platform identifier associated with the treasury. @@ -160,31 +189,82 @@ function getAvailableRaisedAmount() external view returns (uint256); |``|`uint256`|The current available raised amount as a uint256 value.| +### _normalizeAmount + +*Normalizes token amounts to 18 decimals for consistent comparisons.* + + +```solidity +function _normalizeAmount(address token, uint256 amount) internal view returns (uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`token`|`address`|The token address.| +|`amount`|`uint256`|The amount to normalize.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The normalized amount (scaled to 18 decimals).| + + ### createPayment Creates a new payment entry with the specified details. ```solidity -function createPayment(bytes32 paymentId, address buyerAddress, bytes32 itemId, uint256 amount, uint256 expiration) - public - virtual - override - onlyPlatformAdmin(PLATFORM_HASH) - whenCampaignNotPaused - whenCampaignNotCancelled; +function createPayment( + bytes32 paymentId, + bytes32 buyerId, + bytes32 itemId, + address paymentToken, + uint256 amount, + uint256 expiration +) public virtual override onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled; ``` **Parameters** |Name|Type|Description| |----|----|-----------| |`paymentId`|`bytes32`|A unique identifier for the payment.| -|`buyerAddress`|`address`|The address of the buyer initiating the payment.| +|`buyerId`|`bytes32`|The id of the buyer initiating the payment.| |`itemId`|`bytes32`|The identifier of the item being purchased.| +|`paymentToken`|`address`|The token to use for the payment.| |`amount`|`uint256`|The amount to be paid for the item.| |`expiration`|`uint256`|The timestamp after which the payment expires.| +### processCryptoPayment + +Allows a buyer to make a direct crypto payment for an item. + +*This function transfers tokens directly from the buyer's wallet and confirms the payment immediately.* + + +```solidity +function processCryptoPayment( + bytes32 paymentId, + bytes32 itemId, + address buyerAddress, + address paymentToken, + uint256 amount +) public virtual override whenCampaignNotPaused whenCampaignNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the payment.| +|`itemId`|`bytes32`|The identifier of the item being purchased.| +|`buyerAddress`|`address`|The address of the buyer making the payment.| +|`paymentToken`|`address`|The token to use for the payment.| +|`amount`|`uint256`|The amount to be paid for the item.| + + ### cancelPayment Cancels an existing payment with the given payment ID. @@ -250,6 +330,8 @@ function confirmPaymentBatch(bytes32[] calldata paymentIds) ### claimRefund +Claims a refund for a specific payment ID. + ```solidity function claimRefund(bytes32 paymentId, address refundAddress) @@ -260,6 +342,34 @@ function claimRefund(bytes32 paymentId, address refundAddress) whenCampaignNotPaused whenCampaignNotCancelled; ``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the refundable payment.| +|`refundAddress`|`address`|The address where the refunded amount should be sent.| + + +### claimRefund + +Claims a refund for a specific payment ID. + + +```solidity +function claimRefund(bytes32 paymentId) + public + virtual + override + onlyBuyerOrPlatformAdmin(paymentId) + whenCampaignNotPaused + whenCampaignNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the refundable payment.| + ### disburseFees @@ -309,7 +419,7 @@ function cancelTreasury(bytes32 message) public virtual onlyPlatformAdmin(PLATFO ### _revertIfCampaignPaused *Internal function to check if the campaign is paused. -If the campaign is paused, it reverts with TreasuryCampaignInfoIsPaused error.* +If the campaign is paused, it reverts with PaymentTreasuryCampaignInfoIsPaused error.* ```solidity @@ -329,7 +439,8 @@ function _revertIfCampaignCancelled() internal view; Reverts if: - The payment does not exist. - The payment has already been confirmed. -- The payment has already expired.* +- The payment has already expired. +- The payment is a crypto payment* ```solidity @@ -364,7 +475,14 @@ function _checkSuccessCondition() internal view virtual returns (bool); ```solidity event PaymentCreated( - bytes32 indexed paymentId, address indexed buyerAddress, bytes32 indexed itemId, uint256 amount, uint256 expiration + address buyerAddress, + bytes32 indexed paymentId, + bytes32 buyerId, + bytes32 indexed itemId, + address indexed paymentToken, + uint256 amount, + uint256 expiration, + bool isCryptoPayment ); ``` @@ -372,11 +490,14 @@ event PaymentCreated( |Name|Type|Description| |----|----|-----------| +|`buyerAddress`|`address`|The address of the buyer making the payment.| |`paymentId`|`bytes32`|The unique identifier of the payment.| -|`buyerAddress`|`address`|The address of the buyer who initiated the payment.| +|`buyerId`|`bytes32`|The id of the buyer.| |`itemId`|`bytes32`|The identifier of the item being purchased.| -|`amount`|`uint256`|The amount to be paid for the item.| +|`paymentToken`|`address`|The token used for the payment.| +|`amount`|`uint256`|The amount to be paid for the item (in token's native decimals).| |`expiration`|`uint256`|The timestamp after which the payment expires.| +|`isCryptoPayment`|`bool`|Boolean indicating whether the payment is made using direct crypto payment.| ### PaymentCancelled *Emitted when a payment is cancelled and removed from the treasury.* @@ -425,30 +546,33 @@ Emitted when fees are successfully disbursed. ```solidity -event FeesDisbursed(uint256 protocolShare, uint256 platformShare); +event FeesDisbursed(address indexed token, uint256 protocolShare, uint256 platformShare); ``` **Parameters** |Name|Type|Description| |----|----|-----------| +|`token`|`address`|The token in which fees were disbursed.| |`protocolShare`|`uint256`|The amount of fees sent to the protocol.| |`platformShare`|`uint256`|The amount of fees sent to the platform.| -### WithdrawalSuccessful -Emitted when a withdrawal is successful. +### WithdrawalWithFeeSuccessful +*Emitted when a withdrawal is successfully processed along with the applied fee.* ```solidity -event WithdrawalSuccessful(address indexed to, uint256 amount); +event WithdrawalWithFeeSuccessful(address indexed token, address indexed to, uint256 amount, uint256 fee); ``` **Parameters** |Name|Type|Description| |----|----|-----------| -|`to`|`address`|The recipient of the withdrawal.| -|`amount`|`uint256`|The amount withdrawn.| +|`token`|`address`|The token that was withdrawn.| +|`to`|`address`|The recipient address receiving the funds.| +|`amount`|`uint256`|The total amount withdrawn (excluding fee).| +|`fee`|`uint256`|The fee amount deducted from the withdrawal.| ### RefundClaimed *Emitted when a refund is claimed.* @@ -476,7 +600,7 @@ error PaymentTreasuryInvalidInput(); ``` ### PaymentTreasuryPaymentAlreadyExist -*Throws an error indicating that the payment id is already exist.* +*Throws an error indicating that the payment id already exists.* ```solidity @@ -500,7 +624,7 @@ error PaymentTreasuryPaymentAlreadyExpired(bytes32 paymentId); ``` ### PaymentTreasuryPaymentNotExist -*Throws an error indicating that the payment id is not exist.* +*Throws an error indicating that the payment id does not exist.* ```solidity @@ -515,6 +639,14 @@ error PaymentTreasuryPaymentNotExist(bytes32 paymentId); error PaymentTreasuryCampaignInfoIsPaused(); ``` +### PaymentTreasuryTokenNotAccepted +*Emitted when a token is not accepted for the campaign.* + + +```solidity +error PaymentTreasuryTokenNotAccepted(address token); +``` + ### PaymentTreasurySuccessConditionNotFulfilled *Throws an error indicating that the success condition was not fulfilled.* @@ -561,16 +693,69 @@ error PaymentTreasuryPaymentNotClaimable(bytes32 paymentId); error PaymentTreasuryAlreadyWithdrawn(); ``` +### PaymentTreasuryCryptoPayment +*This error is thrown when an operation is attempted on a crypto payment that is only valid for non-crypto payments.* + + +```solidity +error PaymentTreasuryCryptoPayment(bytes32 paymentId); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the payment that caused the error.| + +### PaymentTreasuryInsufficientFundsForFee +Emitted when the fee exceeds the requested withdrawal amount. + + +```solidity +error PaymentTreasuryInsufficientFundsForFee(uint256 withdrawalAmount, uint256 fee); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`withdrawalAmount`|`uint256`|The amount requested for withdrawal.| +|`fee`|`uint256`|The calculated fee, which is greater than the withdrawal amount.| + +### PaymentTreasuryInsufficientBalance +*Emitted when there are insufficient unallocated tokens for a payment confirmation.* + + +```solidity +error PaymentTreasuryInsufficientBalance(uint256 required, uint256 available); +``` + ## Structs ### PaymentInfo +*Stores information about a payment in the treasury.* + ```solidity struct PaymentInfo { address buyerAddress; + bytes32 buyerId; bytes32 itemId; uint256 amount; uint256 expiration; bool isConfirmed; + bool isCryptoPayment; } ``` +**Properties** + +|Name|Type|Description| +|----|----|-----------| +|`buyerAddress`|`address`|The address of the buyer who made the payment.| +|`buyerId`|`bytes32`|The ID of the buyer.| +|`itemId`|`bytes32`|The identifier of the item being purchased.| +|`amount`|`uint256`|The amount to be paid for the item (in token's native decimals).| +|`expiration`|`uint256`|The timestamp after which the payment expires.| +|`isConfirmed`|`bool`|Boolean indicating whether the payment has been confirmed.| +|`isCryptoPayment`|`bool`|Boolean indicating whether the payment is made using direct crypto payment.| + diff --git a/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md b/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md index 0b841fc6..fcffe7fb 100644 --- a/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md +++ b/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md @@ -1,5 +1,5 @@ # BaseTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/utils/BaseTreasury.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/utils/BaseTreasury.sol) **Inherits:** Initializable, [ICampaignTreasury](/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md), [CampaignAccessChecker](/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md), [PausableCancellable](/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md) @@ -26,38 +26,38 @@ uint256 internal constant PERCENT_DIVIDER = 10000; ``` -### PLATFORM_HASH +### STANDARD_DECIMALS ```solidity -bytes32 internal PLATFORM_HASH; +uint256 internal constant STANDARD_DECIMALS = 18; ``` -### PLATFORM_FEE_PERCENT +### PLATFORM_HASH ```solidity -uint256 internal PLATFORM_FEE_PERCENT; +bytes32 internal PLATFORM_HASH; ``` -### TOKEN +### PLATFORM_FEE_PERCENT ```solidity -IERC20 internal TOKEN; +uint256 internal PLATFORM_FEE_PERCENT; ``` -### s_pledgedAmount +### s_feesDisbursed ```solidity -uint256 internal s_pledgedAmount; +bool internal s_feesDisbursed; ``` -### s_feesDisbursed +### s_tokenRaisedAmounts ```solidity -bool internal s_feesDisbursed; +mapping(address => uint256) internal s_tokenRaisedAmounts; ``` @@ -115,6 +115,50 @@ function getplatformFeePercent() external view override returns (uint256); |``|`uint256`|The platform fee percentage as a uint256 value.| +### _normalizeAmount + +*Normalizes token amount to 18 decimals for consistent comparison.* + + +```solidity +function _normalizeAmount(address token, uint256 amount) internal view returns (uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`token`|`address`|The token address to normalize.| +|`amount`|`uint256`|The amount to normalize.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The normalized amount in 18 decimals.| + + +### _denormalizeAmount + +*Denormalizes an amount from 18 decimals to the token's actual decimals.* + + +```solidity +function _denormalizeAmount(address token, uint256 amount) internal view returns (uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`token`|`address`|The token address to denormalize for.| +|`amount`|`uint256`|The amount in 18 decimals to denormalize.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The denormalized amount in token's native decimals.| + + ### disburseFees Disburses fees collected by the treasury. @@ -194,32 +238,34 @@ function _checkSuccessCondition() internal view virtual returns (bool); ## Events ### FeesDisbursed -Emitted when fees are successfully disbursed. +Emitted when fees are successfully disbursed for a specific token. ```solidity -event FeesDisbursed(uint256 protocolShare, uint256 platformShare); +event FeesDisbursed(address indexed token, uint256 protocolShare, uint256 platformShare); ``` **Parameters** |Name|Type|Description| |----|----|-----------| +|`token`|`address`|The token address.| |`protocolShare`|`uint256`|The amount of fees sent to the protocol.| |`platformShare`|`uint256`|The amount of fees sent to the platform.| ### WithdrawalSuccessful -Emitted when a withdrawal is successful. +Emitted when a withdrawal is successful for a specific token. ```solidity -event WithdrawalSuccessful(address to, uint256 amount); +event WithdrawalSuccessful(address indexed token, address to, uint256 amount); ``` **Parameters** |Name|Type|Description| |----|----|-----------| +|`token`|`address`|The token address.| |`to`|`address`|The recipient of the withdrawal.| |`amount`|`uint256`|The amount withdrawn.| diff --git a/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md b/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md index b4bec1f2..36a1d59a 100644 --- a/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md +++ b/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md @@ -1,5 +1,8 @@ # CampaignAccessChecker -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/utils/CampaignAccessChecker.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/utils/CampaignAccessChecker.sol) + +**Inherits:** +Context *This abstract contract provides access control mechanisms to restrict the execution of specific functions to authorized protocol administrators, platform administrators, and campaign owners.* diff --git a/docs/src/src/utils/Counters.sol/library.Counters.md b/docs/src/src/utils/Counters.sol/library.Counters.md index 21571265..098bac17 100644 --- a/docs/src/src/utils/Counters.sol/library.Counters.md +++ b/docs/src/src/utils/Counters.sol/library.Counters.md @@ -1,5 +1,5 @@ # Counters -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/utils/Counters.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/utils/Counters.sol) ## Functions diff --git a/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md b/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md index 7a09c472..27856466 100644 --- a/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md +++ b/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md @@ -1,5 +1,5 @@ # FiatEnabled -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/utils/FiatEnabled.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/utils/FiatEnabled.sol) A contract that provides functionality for tracking and managing fiat transactions. This contract allows tracking the amount of fiat raised, individual fiat transactions, and the state of fiat fee disbursement. diff --git a/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md b/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md index ebea1819..b6d9c909 100644 --- a/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md +++ b/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md @@ -1,5 +1,5 @@ # ItemRegistry -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/utils/ItemRegistry.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/utils/ItemRegistry.sol) **Inherits:** [IItem](/src/interfaces/IItem.sol/interface.IItem.md), Context diff --git a/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md b/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md index c9a5c6b9..06a9e518 100644 --- a/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md +++ b/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md @@ -1,5 +1,8 @@ # PausableCancellable -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/utils/PausableCancellable.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/utils/PausableCancellable.sol) + +**Inherits:** +Context Abstract contract providing pause and cancel state management with events and modifiers diff --git a/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md b/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md index 597abd3a..b9a0d412 100644 --- a/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md +++ b/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md @@ -1,5 +1,5 @@ # TimestampChecker -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/56580a82da87af15808145e03ffc25bd15b6454b/src/utils/TimestampChecker.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/utils/TimestampChecker.sol) A contract that provides timestamp-related checks for contract functions. diff --git a/foundry.toml b/foundry.toml index 95ee243f..16049412 100644 --- a/foundry.toml +++ b/foundry.toml @@ -5,10 +5,11 @@ libs = ["lib"] via_ir = true optimizer = true optimizer_runs = 200 -solc_version = "0.8.20" +solc_version = "0.8.22" remappings = [ - "@openzeppelin/=lib/openzeppelin-contracts/" + "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/", + "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/" ] [rpc_endpoints] diff --git a/script/DeployAll.s.sol b/script/DeployAll.s.sol index f7936213..bd1fe04f 100644 --- a/script/DeployAll.s.sol +++ b/script/DeployAll.s.sol @@ -1,62 +1,116 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import {Script} from "forge-std/Script.sol"; import {console2} from "forge-std/console2.sol"; -import {DeployGlobalParams} from "./DeployGlobalParams.s.sol"; -import {DeployTestToken} from "./DeployTestToken.s.sol"; -import {DeployCampaignInfoFactory} from "./DeployCampaignInfoFactory.s.sol"; -import {DeployTreasuryFactory} from "./DeployTreasuryFactory.s.sol"; +import {TestToken} from "../test/mocks/TestToken.sol"; +import {GlobalParams} from "src/GlobalParams.sol"; +import {CampaignInfoFactory} from "src/CampaignInfoFactory.sol"; +import {CampaignInfo} from "src/CampaignInfo.sol"; +import {TreasuryFactory} from "src/TreasuryFactory.sol"; +import {IGlobalParams} from "src/interfaces/IGlobalParams.sol"; +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; contract DeployAll is Script { - function deployTestToken() internal returns (address) { - DeployTestToken script = new DeployTestToken(); - return script.deploy(); - } - - function deployGlobalParams(address testToken) internal returns (address) { - DeployGlobalParams script = new DeployGlobalParams(); - return script.deployWithToken(testToken); - } - - function deployTreasuryFactory( - address globalParams - ) internal returns (address) { - DeployTreasuryFactory script = new DeployTreasuryFactory(); - return script.deploy(globalParams); - } - - function deployCampaignFactory( - address globalParams, - address treasuryFactory - ) internal returns (address) { - DeployCampaignInfoFactory script = new DeployCampaignInfoFactory(); - return script.deploy(globalParams, treasuryFactory); - } - function run() external { bool simulate = vm.envOr("SIMULATE", false); uint256 deployerKey = vm.envUint("PRIVATE_KEY"); + address deployerAddress = vm.addr(deployerKey); if (!simulate) { vm.startBroadcast(deployerKey); } - address testToken = deployTestToken(); - address globalParams = deployGlobalParams(testToken); - address treasuryFactory = deployTreasuryFactory(globalParams); - address campaignFactory = deployCampaignFactory( - globalParams, - treasuryFactory + // Deploy TestToken + string memory tokenName = vm.envOr("TOKEN_NAME", string("TestToken")); + string memory tokenSymbol = vm.envOr("TOKEN_SYMBOL", string("TST")); + uint8 decimals = uint8(vm.envOr("TOKEN_DECIMALS", uint256(18))); + + TestToken testToken = new TestToken(tokenName, tokenSymbol, decimals); + console2.log("TestToken deployed at:", address(testToken)); + + // Deploy GlobalParams with UUPS proxy + uint256 protocolFeePercent = vm.envOr("PROTOCOL_FEE_PERCENT", uint256(100)); + + bytes32[] memory currencies = new bytes32[](1); + address[][] memory tokensPerCurrency = new address[][](1); + currencies[0] = keccak256(abi.encodePacked("USD")); + tokensPerCurrency[0] = new address[](1); + tokensPerCurrency[0][0] = address(testToken); + + // Deploy GlobalParams implementation + GlobalParams globalParamsImpl = new GlobalParams(); + console2.log("GlobalParams implementation deployed at:", address(globalParamsImpl)); + + // Prepare initialization data for GlobalParams + bytes memory globalParamsInitData = abi.encodeWithSelector( + GlobalParams.initialize.selector, + deployerAddress, + protocolFeePercent, + currencies, + tokensPerCurrency + ); + + // Deploy GlobalParams proxy + ERC1967Proxy globalParamsProxy = new ERC1967Proxy( + address(globalParamsImpl), + globalParamsInitData + ); + console2.log("GlobalParams proxy deployed at:", address(globalParamsProxy)); + + // Deploy TreasuryFactory with UUPS proxy + TreasuryFactory treasuryFactoryImpl = new TreasuryFactory(); + console2.log("TreasuryFactory implementation deployed at:", address(treasuryFactoryImpl)); + + // Prepare initialization data for TreasuryFactory + bytes memory treasuryFactoryInitData = abi.encodeWithSelector( + TreasuryFactory.initialize.selector, + IGlobalParams(address(globalParamsProxy)) + ); + + // Deploy TreasuryFactory proxy + ERC1967Proxy treasuryFactoryProxy = new ERC1967Proxy( + address(treasuryFactoryImpl), + treasuryFactoryInitData + ); + console2.log("TreasuryFactory proxy deployed at:", address(treasuryFactoryProxy)); + + // Deploy CampaignInfo implementation + CampaignInfo campaignInfoImplementation = new CampaignInfo(); + console2.log("CampaignInfo implementation deployed at:", address(campaignInfoImplementation)); + + // Deploy CampaignInfoFactory with UUPS proxy + CampaignInfoFactory campaignFactoryImpl = new CampaignInfoFactory(); + console2.log("CampaignInfoFactory implementation deployed at:", address(campaignFactoryImpl)); + + // Prepare initialization data for CampaignInfoFactory + bytes memory campaignFactoryInitData = abi.encodeWithSelector( + CampaignInfoFactory.initialize.selector, + deployerAddress, + IGlobalParams(address(globalParamsProxy)), + address(campaignInfoImplementation), + address(treasuryFactoryProxy) + ); + + // Deploy CampaignInfoFactory proxy + ERC1967Proxy campaignFactoryProxy = new ERC1967Proxy( + address(campaignFactoryImpl), + campaignFactoryInitData ); + console2.log("CampaignInfoFactory proxy deployed at:", address(campaignFactoryProxy)); if (!simulate) { vm.stopBroadcast(); } - console2.log("TOKEN_ADDRESS", testToken); - console2.log("GLOBAL_PARAMS_ADDRESS", globalParams); - console2.log("TREASURY_FACTORY_ADDRESS", treasuryFactory); - console2.log("CAMPAIGN_INFO_FACTORY_ADDRESS", campaignFactory); + // Summary + console2.log("\n--- Deployment Summary ---"); + console2.log("TOKEN_ADDRESS", address(testToken)); + console2.log("GLOBAL_PARAMS_ADDRESS", address(globalParamsProxy)); + console2.log("GLOBAL_PARAMS_IMPLEMENTATION", address(globalParamsImpl)); + console2.log("TREASURY_FACTORY_ADDRESS", address(treasuryFactoryProxy)); + console2.log("TREASURY_FACTORY_IMPLEMENTATION", address(treasuryFactoryImpl)); + console2.log("CAMPAIGN_INFO_FACTORY_ADDRESS", address(campaignFactoryProxy)); + console2.log("CAMPAIGN_INFO_FACTORY_IMPLEMENTATION", address(campaignFactoryImpl)); } } diff --git a/script/DeployAllAndSetupAllOrNothing.s.sol b/script/DeployAllAndSetupAllOrNothing.s.sol index 836c2050..ef75988c 100644 --- a/script/DeployAllAndSetupAllOrNothing.s.sol +++ b/script/DeployAllAndSetupAllOrNothing.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import {Script} from "forge-std/Script.sol"; import {console2} from "forge-std/console2.sol"; @@ -9,6 +9,8 @@ import {CampaignInfoFactory} from "src/CampaignInfoFactory.sol"; import {CampaignInfo} from "src/CampaignInfo.sol"; import {TreasuryFactory} from "src/TreasuryFactory.sol"; import {AllOrNothing} from "src/treasuries/AllOrNothing.sol"; +import {IGlobalParams} from "src/interfaces/IGlobalParams.sol"; +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; /** * @notice Script to deploy and setup all needed contracts for the protocol @@ -115,7 +117,8 @@ contract DeployAllAndSetupAllOrNothing is Script { string memory tokenSymbol = vm.envOr("TOKEN_SYMBOL", string("TST")); if (testToken == address(0)) { - testToken = address(new TestToken(tokenName, tokenSymbol)); + uint8 decimals = uint8(vm.envOr("TOKEN_DECIMALS", uint256(18))); + testToken = address(new TestToken(tokenName, tokenSymbol, decimals)); testTokenDeployed = true; console2.log("TestToken deployed at:", testToken); } else { @@ -124,13 +127,28 @@ contract DeployAllAndSetupAllOrNothing is Script { // Deploy or reuse GlobalParams if (globalParams == address(0)) { - globalParams = address( - new GlobalParams( - deployerAddress, // Initially deployer is protocol admin - testToken, - protocolFeePercent - ) + // Setup currencies and tokens for multi-token support + bytes32[] memory currencies = new bytes32[](1); + address[][] memory tokensPerCurrency = new address[][](1); + + currencies[0] = keccak256(abi.encodePacked("USD")); + tokensPerCurrency[0] = new address[](1); + tokensPerCurrency[0][0] = testToken; + + // Deploy GlobalParams with UUPS proxy + GlobalParams globalParamsImpl = new GlobalParams(); + bytes memory globalParamsInitData = abi.encodeWithSelector( + GlobalParams.initialize.selector, + deployerAddress, + protocolFeePercent, + currencies, + tokensPerCurrency ); + ERC1967Proxy globalParamsProxy = new ERC1967Proxy( + address(globalParamsImpl), + globalParamsInitData + ); + globalParams = address(globalParamsProxy); globalParamsDeployed = true; console2.log("GlobalParams deployed at:", globalParams); } else { @@ -144,7 +162,7 @@ contract DeployAllAndSetupAllOrNothing is Script { // Deploy CampaignInfo implementation if needed for new deployments if (campaignInfoFactory == address(0)) { campaignInfoImplementation = address( - new CampaignInfo(deployerAddress) + new CampaignInfo() ); console2.log( "CampaignInfo implementation deployed at:", @@ -154,9 +172,17 @@ contract DeployAllAndSetupAllOrNothing is Script { // Deploy or reuse TreasuryFactory if (treasuryFactory == address(0)) { - treasuryFactory = address( - new TreasuryFactory(GlobalParams(globalParams)) + // Deploy TreasuryFactory with UUPS proxy + TreasuryFactory treasuryFactoryImpl = new TreasuryFactory(); + bytes memory treasuryFactoryInitData = abi.encodeWithSelector( + TreasuryFactory.initialize.selector, + IGlobalParams(globalParams) + ); + ERC1967Proxy treasuryFactoryProxy = new ERC1967Proxy( + address(treasuryFactoryImpl), + treasuryFactoryInitData ); + treasuryFactory = address(treasuryFactoryProxy); treasuryFactoryDeployed = true; console2.log("TreasuryFactory deployed at:", treasuryFactory); } else { @@ -165,16 +191,20 @@ contract DeployAllAndSetupAllOrNothing is Script { // Deploy or reuse CampaignInfoFactory if (campaignInfoFactory == address(0)) { - campaignInfoFactory = address( - new CampaignInfoFactory( - GlobalParams(globalParams), - campaignInfoImplementation - ) + // Deploy CampaignInfoFactory with UUPS proxy + CampaignInfoFactory campaignFactoryImpl = new CampaignInfoFactory(); + bytes memory campaignFactoryInitData = abi.encodeWithSelector( + CampaignInfoFactory.initialize.selector, + deployerAddress, + IGlobalParams(globalParams), + campaignInfoImplementation, + treasuryFactory ); - CampaignInfoFactory(campaignInfoFactory)._initialize( - treasuryFactory, - globalParams + ERC1967Proxy campaignFactoryProxy = new ERC1967Proxy( + address(campaignFactoryImpl), + campaignFactoryInitData ); + campaignInfoFactory = address(campaignFactoryProxy); campaignInfoFactoryDeployed = true; console2.log( "CampaignInfoFactory deployed and initialized at:", diff --git a/script/DeployAllAndSetupKeepWhatsRaised.s.sol b/script/DeployAllAndSetupKeepWhatsRaised.s.sol index f18d25e5..59b5ce4b 100644 --- a/script/DeployAllAndSetupKeepWhatsRaised.s.sol +++ b/script/DeployAllAndSetupKeepWhatsRaised.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import {Script} from "forge-std/Script.sol"; import {console2} from "forge-std/console2.sol"; @@ -9,6 +9,8 @@ import {CampaignInfoFactory} from "src/CampaignInfoFactory.sol"; import {CampaignInfo} from "src/CampaignInfo.sol"; import {TreasuryFactory} from "src/TreasuryFactory.sol"; import {KeepWhatsRaised} from "src/treasuries/KeepWhatsRaised.sol"; +import {IGlobalParams} from "src/interfaces/IGlobalParams.sol"; +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; /** * @notice Script to deploy and setup all needed contracts for the keepWhatsRaised @@ -95,7 +97,8 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { string memory tokenSymbol = vm.envOr("TOKEN_SYMBOL", string("TST")); if (testToken == address(0)) { - testToken = address(new TestToken(tokenName, tokenSymbol)); + uint8 decimals = uint8(vm.envOr("TOKEN_DECIMALS", uint256(18))); + testToken = address(new TestToken(tokenName, tokenSymbol, decimals)); testTokenDeployed = true; console2.log("TestToken deployed at:", testToken); } else { @@ -104,11 +107,28 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { // Deploy or reuse GlobalParams if (globalParams == address(0)) { - globalParams = address(new GlobalParams( - deployerAddress, // Initially deployer is protocol admin - testToken, - protocolFeePercent - )); + // Setup currencies and tokens for multi-token support + bytes32[] memory currencies = new bytes32[](1); + address[][] memory tokensPerCurrency = new address[][](1); + + currencies[0] = keccak256(abi.encodePacked("USD")); + tokensPerCurrency[0] = new address[](1); + tokensPerCurrency[0][0] = testToken; + + // Deploy GlobalParams with UUPS proxy + GlobalParams globalParamsImpl = new GlobalParams(); + bytes memory globalParamsInitData = abi.encodeWithSelector( + GlobalParams.initialize.selector, + deployerAddress, + protocolFeePercent, + currencies, + tokensPerCurrency + ); + ERC1967Proxy globalParamsProxy = new ERC1967Proxy( + address(globalParamsImpl), + globalParamsInitData + ); + globalParams = address(globalParamsProxy); globalParamsDeployed = true; console2.log("GlobalParams deployed at:", globalParams); } else { @@ -121,13 +141,23 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { // Deploy CampaignInfo implementation if needed for new deployments if (campaignInfoFactory == address(0)) { - campaignInfo = address(new CampaignInfo(deployerAddress)); + campaignInfo = address(new CampaignInfo()); console2.log("CampaignInfo deployed at:", campaignInfo); } // Deploy or reuse TreasuryFactory if (treasuryFactory == address(0)) { - treasuryFactory = address(new TreasuryFactory(GlobalParams(globalParams))); + // Deploy TreasuryFactory with UUPS proxy + TreasuryFactory treasuryFactoryImpl = new TreasuryFactory(); + bytes memory treasuryFactoryInitData = abi.encodeWithSelector( + TreasuryFactory.initialize.selector, + IGlobalParams(globalParams) + ); + ERC1967Proxy treasuryFactoryProxy = new ERC1967Proxy( + address(treasuryFactoryImpl), + treasuryFactoryInitData + ); + treasuryFactory = address(treasuryFactoryProxy); treasuryFactoryDeployed = true; console2.log("TreasuryFactory deployed at:", treasuryFactory); } else { @@ -136,14 +166,20 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { // Deploy or reuse CampaignInfoFactory if (campaignInfoFactory == address(0)) { - campaignInfoFactory = address(new CampaignInfoFactory( - GlobalParams(globalParams), - campaignInfo - )); - CampaignInfoFactory(campaignInfoFactory)._initialize( - treasuryFactory, - globalParams + // Deploy CampaignInfoFactory with UUPS proxy + CampaignInfoFactory campaignFactoryImpl = new CampaignInfoFactory(); + bytes memory campaignFactoryInitData = abi.encodeWithSelector( + CampaignInfoFactory.initialize.selector, + deployerAddress, + IGlobalParams(globalParams), + campaignInfo, + treasuryFactory + ); + ERC1967Proxy campaignFactoryProxy = new ERC1967Proxy( + address(campaignFactoryImpl), + campaignFactoryInitData ); + campaignInfoFactory = address(campaignFactoryProxy); campaignInfoFactoryDeployed = true; console2.log("CampaignInfoFactory deployed and initialized at:", campaignInfoFactory); } else { diff --git a/script/DeployAllAndSetupPaymentTreasury.s.sol b/script/DeployAllAndSetupPaymentTreasury.s.sol index 205b4b74..9c364b74 100644 --- a/script/DeployAllAndSetupPaymentTreasury.s.sol +++ b/script/DeployAllAndSetupPaymentTreasury.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import {Script} from "forge-std/Script.sol"; import {console2} from "forge-std/console2.sol"; @@ -9,6 +9,8 @@ import {CampaignInfoFactory} from "src/CampaignInfoFactory.sol"; import {CampaignInfo} from "src/CampaignInfo.sol"; import {TreasuryFactory} from "src/TreasuryFactory.sol"; import {PaymentTreasury} from "src/treasuries/PaymentTreasury.sol"; +import {IGlobalParams} from "src/interfaces/IGlobalParams.sol"; +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; /** * @notice Script to deploy and setup all needed contracts for the protocol @@ -115,7 +117,8 @@ contract DeployAllAndSetupPaymentTreasury is Script { string memory tokenSymbol = vm.envOr("TOKEN_SYMBOL", string("TST")); if (testToken == address(0)) { - testToken = address(new TestToken(tokenName, tokenSymbol)); + uint8 decimals = uint8(vm.envOr("TOKEN_DECIMALS", uint256(18))); + testToken = address(new TestToken(tokenName, tokenSymbol, decimals)); testTokenDeployed = true; console2.log("TestToken deployed at:", testToken); } else { @@ -124,13 +127,28 @@ contract DeployAllAndSetupPaymentTreasury is Script { // Deploy or reuse GlobalParams if (globalParams == address(0)) { - globalParams = address( - new GlobalParams( - deployerAddress, // Initially deployer is protocol admin - testToken, - protocolFeePercent - ) + // Setup currencies and tokens for multi-token support + bytes32[] memory currencies = new bytes32[](1); + address[][] memory tokensPerCurrency = new address[][](1); + + currencies[0] = keccak256(abi.encodePacked("USD")); + tokensPerCurrency[0] = new address[](1); + tokensPerCurrency[0][0] = testToken; + + // Deploy GlobalParams with UUPS proxy + GlobalParams globalParamsImpl = new GlobalParams(); + bytes memory globalParamsInitData = abi.encodeWithSelector( + GlobalParams.initialize.selector, + deployerAddress, + protocolFeePercent, + currencies, + tokensPerCurrency ); + ERC1967Proxy globalParamsProxy = new ERC1967Proxy( + address(globalParamsImpl), + globalParamsInitData + ); + globalParams = address(globalParamsProxy); globalParamsDeployed = true; console2.log("GlobalParams deployed at:", globalParams); } else { @@ -144,7 +162,7 @@ contract DeployAllAndSetupPaymentTreasury is Script { // Deploy CampaignInfo implementation if needed for new deployments if (campaignInfoFactory == address(0)) { campaignInfoImplementation = address( - new CampaignInfo(deployerAddress) + new CampaignInfo() ); console2.log( "CampaignInfo implementation deployed at:", @@ -154,9 +172,17 @@ contract DeployAllAndSetupPaymentTreasury is Script { // Deploy or reuse TreasuryFactory if (treasuryFactory == address(0)) { - treasuryFactory = address( - new TreasuryFactory(GlobalParams(globalParams)) + // Deploy TreasuryFactory with UUPS proxy + TreasuryFactory treasuryFactoryImpl = new TreasuryFactory(); + bytes memory treasuryFactoryInitData = abi.encodeWithSelector( + TreasuryFactory.initialize.selector, + IGlobalParams(globalParams) + ); + ERC1967Proxy treasuryFactoryProxy = new ERC1967Proxy( + address(treasuryFactoryImpl), + treasuryFactoryInitData ); + treasuryFactory = address(treasuryFactoryProxy); treasuryFactoryDeployed = true; console2.log("TreasuryFactory deployed at:", treasuryFactory); } else { @@ -165,16 +191,20 @@ contract DeployAllAndSetupPaymentTreasury is Script { // Deploy or reuse CampaignInfoFactory if (campaignInfoFactory == address(0)) { - campaignInfoFactory = address( - new CampaignInfoFactory( - GlobalParams(globalParams), - campaignInfoImplementation - ) + // Deploy CampaignInfoFactory with UUPS proxy + CampaignInfoFactory campaignFactoryImpl = new CampaignInfoFactory(); + bytes memory campaignFactoryInitData = abi.encodeWithSelector( + CampaignInfoFactory.initialize.selector, + deployerAddress, + IGlobalParams(globalParams), + campaignInfoImplementation, + treasuryFactory ); - CampaignInfoFactory(campaignInfoFactory)._initialize( - treasuryFactory, - globalParams + ERC1967Proxy campaignFactoryProxy = new ERC1967Proxy( + address(campaignFactoryImpl), + campaignFactoryInitData ); + campaignInfoFactory = address(campaignFactoryProxy); campaignInfoFactoryDeployed = true; console2.log( "CampaignInfoFactory deployed and initialized at:", diff --git a/script/DeployAllOrNothingImplementation.s.sol b/script/DeployAllOrNothingImplementation.s.sol index 7c017a50..0eb025f5 100644 --- a/script/DeployAllOrNothingImplementation.s.sol +++ b/script/DeployAllOrNothingImplementation.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import {Script} from "forge-std/Script.sol"; import {console2} from "forge-std/console2.sol"; diff --git a/script/DeployCampaignInfoFactory.s.sol b/script/DeployCampaignInfoFactory.s.sol index cbf00748..6bb17a58 100644 --- a/script/DeployCampaignInfoFactory.s.sol +++ b/script/DeployCampaignInfoFactory.s.sol @@ -1,11 +1,13 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import {Script} from "forge-std/Script.sol"; import {console2} from "forge-std/console2.sol"; import {CampaignInfoFactory} from "src/CampaignInfoFactory.sol"; import {CampaignInfo} from "src/CampaignInfo.sol"; import {GlobalParams} from "src/GlobalParams.sol"; +import {IGlobalParams} from "src/interfaces/IGlobalParams.sol"; +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; import {DeployBase} from "./lib/DeployBase.s.sol"; contract DeployCampaignInfoFactory is DeployBase { @@ -15,24 +17,34 @@ contract DeployCampaignInfoFactory is DeployBase { ) public returns (address) { console2.log("Deploying CampaignInfoFactory..."); - // Properly deploy CampaignInfo with direct instantiation - CampaignInfo campaignInfoImpl = new CampaignInfo(address(this)); + address deployer = vm.addr(vm.envUint("PRIVATE_KEY")); + + // Deploy CampaignInfo implementation + CampaignInfo campaignInfoImpl = new CampaignInfo(); address campaignInfo = address(campaignInfoImpl); console2.log("CampaignInfo implementation deployed at:", campaignInfo); - // Create and initialize the factory - CampaignInfoFactory campaignInfoFactory = new CampaignInfoFactory( - GlobalParams(globalParams), - campaignInfo + // Deploy CampaignInfoFactory implementation + CampaignInfoFactory factoryImplementation = new CampaignInfoFactory(); + console2.log("CampaignInfoFactory implementation deployed at:", address(factoryImplementation)); + + // Prepare initialization data + bytes memory initData = abi.encodeWithSelector( + CampaignInfoFactory.initialize.selector, + deployer, + IGlobalParams(globalParams), + campaignInfo, + treasuryFactory ); - campaignInfoFactory._initialize(treasuryFactory, globalParams); + // Deploy proxy + ERC1967Proxy proxy = new ERC1967Proxy(address(factoryImplementation), initData); console2.log( - "CampaignInfoFactory deployed and initialized at:", - address(campaignInfoFactory) + "CampaignInfoFactory proxy deployed and initialized at:", + address(proxy) ); - return address(campaignInfoFactory); + return address(proxy); } function run() external { diff --git a/script/DeployCampaignInfoImplementation.s.sol b/script/DeployCampaignInfoImplementation.s.sol index dd4f4dc6..4fe1465b 100644 --- a/script/DeployCampaignInfoImplementation.s.sol +++ b/script/DeployCampaignInfoImplementation.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import {Script} from "forge-std/Script.sol"; import {console2} from "forge-std/console2.sol"; @@ -10,7 +10,7 @@ contract DeployCampaignInfoImplementation is Script { console2.log("Deploying CampaignInfo implementation..."); // Implementation will use the script address as admin, but this will be replaced // when the factory creates new instances - CampaignInfo campaignInfo = new CampaignInfo(address(this)); + CampaignInfo campaignInfo = new CampaignInfo(); console2.log( "CampaignInfo implementation deployed at:", address(campaignInfo) diff --git a/script/DeployGlobalParams.s.sol b/script/DeployGlobalParams.s.sol index 185d3856..a3df403f 100644 --- a/script/DeployGlobalParams.s.sol +++ b/script/DeployGlobalParams.s.sol @@ -1,13 +1,38 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import {GlobalParams} from "../src/GlobalParams.sol"; +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; import {DeployBase} from "./lib/DeployBase.s.sol"; contract DeployGlobalParams is DeployBase { function deployWithToken(address token) public returns (address) { address deployer = vm.addr(vm.envUint("PRIVATE_KEY")); - return address(new GlobalParams(deployer, token, 200)); + + // Setup currencies and tokens for multi-token support + bytes32[] memory currencies = new bytes32[](1); + address[][] memory tokensPerCurrency = new address[][](1); + + currencies[0] = keccak256(abi.encodePacked("USD")); + tokensPerCurrency[0] = new address[](1); + tokensPerCurrency[0][0] = token; + + // Deploy implementation + GlobalParams implementation = new GlobalParams(); + + // Prepare initialization data + bytes memory initData = abi.encodeWithSelector( + GlobalParams.initialize.selector, + deployer, + 200, + currencies, + tokensPerCurrency + ); + + // Deploy proxy + ERC1967Proxy proxy = new ERC1967Proxy(address(implementation), initData); + + return address(proxy); } function deploy() public returns (address) { @@ -18,7 +43,31 @@ contract DeployGlobalParams is DeployBase { address deployer = vm.addr(vm.envUint("PRIVATE_KEY")); address token = vm.envOr("TOKEN_ADDRESS", address(0)); require(token != address(0), "TestToken address must be set"); - return address(new GlobalParams(deployer, token, 200)); + + // Setup currencies and tokens for multi-token support + bytes32[] memory currencies = new bytes32[](1); + address[][] memory tokensPerCurrency = new address[][](1); + + currencies[0] = keccak256(abi.encodePacked("USD")); + tokensPerCurrency[0] = new address[](1); + tokensPerCurrency[0][0] = token; + + // Deploy implementation + GlobalParams implementation = new GlobalParams(); + + // Prepare initialization data + bytes memory initData = abi.encodeWithSelector( + GlobalParams.initialize.selector, + deployer, + 200, + currencies, + tokensPerCurrency + ); + + // Deploy proxy + ERC1967Proxy proxy = new ERC1967Proxy(address(implementation), initData); + + return address(proxy); } function run() external { diff --git a/script/DeployKeepWhatsRaised.s.sol b/script/DeployKeepWhatsRaised.s.sol index ef1cfd9b..e6c0413d 100644 --- a/script/DeployKeepWhatsRaised.s.sol +++ b/script/DeployKeepWhatsRaised.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import "forge-std/Script.sol"; import "forge-std/console.sol"; diff --git a/script/DeployTestToken.s.sol b/script/DeployTestToken.s.sol index 93d6d072..7628c808 100644 --- a/script/DeployTestToken.s.sol +++ b/script/DeployTestToken.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import {TestToken} from "../test/mocks/TestToken.sol"; import {DeployBase} from "./lib/DeployBase.s.sol"; @@ -12,7 +12,8 @@ contract DeployTestToken is DeployBase { function _deploy() internal returns (address) { string memory tokenName = vm.envOr("TOKEN_NAME", string("TestToken")); string memory tokenSymbol = vm.envOr("TOKEN_SYMBOL", string("TST")); - return address(new TestToken(tokenName, tokenSymbol)); + uint8 decimals = uint8(vm.envOr("TOKEN_DECIMALS", uint256(18))); + return address(new TestToken(tokenName, tokenSymbol, decimals)); } function run() external { diff --git a/script/DeployTreasuryFactory.s.sol b/script/DeployTreasuryFactory.s.sol index 4689147f..36625a5c 100644 --- a/script/DeployTreasuryFactory.s.sol +++ b/script/DeployTreasuryFactory.s.sol @@ -1,14 +1,29 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import {TreasuryFactory} from "../src/TreasuryFactory.sol"; import {GlobalParams} from "../src/GlobalParams.sol"; +import {IGlobalParams} from "../src/interfaces/IGlobalParams.sol"; +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; import {DeployBase} from "./lib/DeployBase.s.sol"; contract DeployTreasuryFactory is DeployBase { function deploy(address _globalParams) public returns (address) { require(_globalParams != address(0), "GlobalParams not set"); - return address(new TreasuryFactory(GlobalParams(_globalParams))); + + // Deploy implementation + TreasuryFactory implementation = new TreasuryFactory(); + + // Prepare initialization data + bytes memory initData = abi.encodeWithSelector( + TreasuryFactory.initialize.selector, + IGlobalParams(_globalParams) + ); + + // Deploy proxy + ERC1967Proxy proxy = new ERC1967Proxy(address(implementation), initData); + + return address(proxy); } function run() external { diff --git a/script/UpgradeCampaignInfoFactory.s.sol b/script/UpgradeCampaignInfoFactory.s.sol new file mode 100644 index 00000000..22b54eea --- /dev/null +++ b/script/UpgradeCampaignInfoFactory.s.sol @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.22; + +import {Script} from "forge-std/Script.sol"; +import {console2} from "forge-std/console2.sol"; +import {CampaignInfoFactory} from "../src/CampaignInfoFactory.sol"; +import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; + +/** + * @title UpgradeCampaignInfoFactory + * @notice Script to upgrade the CampaignInfoFactory implementation contract + * @dev Uses UUPS upgrade pattern + */ +contract UpgradeCampaignInfoFactory is Script { + function run() external { + uint256 deployerKey = vm.envUint("PRIVATE_KEY"); + address proxyAddress = vm.envAddress("CAMPAIGN_INFO_FACTORY_ADDRESS"); + + require(proxyAddress != address(0), "Proxy address must be set"); + + vm.startBroadcast(deployerKey); + + // Deploy new implementation + CampaignInfoFactory newImplementation = new CampaignInfoFactory(); + console2.log("New CampaignInfoFactory implementation deployed at:", address(newImplementation)); + + // Upgrade the proxy to point to the new implementation + CampaignInfoFactory proxy = CampaignInfoFactory(proxyAddress); + proxy.upgradeToAndCall(address(newImplementation), ""); + + console2.log("CampaignInfoFactory proxy upgraded successfully"); + console2.log("Proxy address:", proxyAddress); + console2.log("New implementation address:", address(newImplementation)); + + vm.stopBroadcast(); + } +} + diff --git a/script/UpgradeGlobalParams.s.sol b/script/UpgradeGlobalParams.s.sol new file mode 100644 index 00000000..69d51f4f --- /dev/null +++ b/script/UpgradeGlobalParams.s.sol @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.22; + +import {Script} from "forge-std/Script.sol"; +import {console2} from "forge-std/console2.sol"; +import {GlobalParams} from "../src/GlobalParams.sol"; +import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; + +/** + * @title UpgradeGlobalParams + * @notice Script to upgrade the GlobalParams implementation contract + * @dev Uses UUPS upgrade pattern + */ +contract UpgradeGlobalParams is Script { + function run() external { + uint256 deployerKey = vm.envUint("PRIVATE_KEY"); + address proxyAddress = vm.envAddress("GLOBAL_PARAMS_ADDRESS"); + + require(proxyAddress != address(0), "Proxy address must be set"); + + vm.startBroadcast(deployerKey); + + // Deploy new implementation + GlobalParams newImplementation = new GlobalParams(); + console2.log("New GlobalParams implementation deployed at:", address(newImplementation)); + + // Upgrade the proxy to point to the new implementation + GlobalParams proxy = GlobalParams(proxyAddress); + proxy.upgradeToAndCall(address(newImplementation), ""); + + console2.log("GlobalParams proxy upgraded successfully"); + console2.log("Proxy address:", proxyAddress); + console2.log("New implementation address:", address(newImplementation)); + + vm.stopBroadcast(); + } +} + diff --git a/script/UpgradeTreasuryFactory.s.sol b/script/UpgradeTreasuryFactory.s.sol new file mode 100644 index 00000000..f56357b1 --- /dev/null +++ b/script/UpgradeTreasuryFactory.s.sol @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.22; + +import {Script} from "forge-std/Script.sol"; +import {console2} from "forge-std/console2.sol"; +import {TreasuryFactory} from "../src/TreasuryFactory.sol"; +import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; + +/** + * @title UpgradeTreasuryFactory + * @notice Script to upgrade the TreasuryFactory implementation contract + * @dev Uses UUPS upgrade pattern + */ +contract UpgradeTreasuryFactory is Script { + function run() external { + uint256 deployerKey = vm.envUint("PRIVATE_KEY"); + address proxyAddress = vm.envAddress("TREASURY_FACTORY_ADDRESS"); + + require(proxyAddress != address(0), "Proxy address must be set"); + + vm.startBroadcast(deployerKey); + + // Deploy new implementation + TreasuryFactory newImplementation = new TreasuryFactory(); + console2.log("New TreasuryFactory implementation deployed at:", address(newImplementation)); + + // Upgrade the proxy to point to the new implementation + TreasuryFactory proxy = TreasuryFactory(proxyAddress); + proxy.upgradeToAndCall(address(newImplementation), ""); + + console2.log("TreasuryFactory proxy upgraded successfully"); + console2.log("Proxy address:", proxyAddress); + console2.log("New implementation address:", address(newImplementation)); + + vm.stopBroadcast(); + } +} + diff --git a/script/lib/DeployBase.s.sol b/script/lib/DeployBase.s.sol index e3b38fc7..efb34b6c 100644 --- a/script/lib/DeployBase.s.sol +++ b/script/lib/DeployBase.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import {Script} from "forge-std/Script.sol"; import {console2} from "forge-std/console2.sol"; diff --git a/src/CampaignInfo.sol b/src/CampaignInfo.sol index 9e50b8ba..e80fe943 100644 --- a/src/CampaignInfo.sol +++ b/src/CampaignInfo.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol"; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; @@ -35,6 +35,10 @@ contract CampaignInfo is mapping(bytes32 => bytes32) private s_platformData; bytes32[] private s_approvedPlatformHashes; + + // Multi-token support + address[] private s_acceptedTokens; // Accepted tokens for this campaign + mapping(address => bool) private s_isAcceptedToken; // O(1) token validation function getApprovedPlatformHashes() external @@ -114,7 +118,9 @@ contract CampaignInfo is */ error CampaignInfoPlatformAlreadyApproved(bytes32 platformHash); - constructor(address creator) Ownable(creator) {} + constructor() Ownable(_msgSender()) { + _disableInitializers(); + } function initialize( address creator, @@ -122,14 +128,24 @@ contract CampaignInfo is bytes32[] calldata selectedPlatformHash, bytes32[] calldata platformDataKey, bytes32[] calldata platformDataValue, - CampaignData calldata campaignData + CampaignData calldata campaignData, + address[] calldata acceptedTokens ) external initializer { __AccessChecker_init(globalParams); _transferOwnership(creator); s_campaignData = campaignData; + + // Store accepted tokens + uint256 tokenLen = acceptedTokens.length; + for (uint256 i = 0; i < tokenLen; ++i) { + address token = acceptedTokens[i]; + s_acceptedTokens.push(token); + s_isAcceptedToken[token] = true; + } + uint256 len = selectedPlatformHash.length; for (uint256 i = 0; i < len; ++i) { - s_platformFeePercent[selectedPlatformHash[i]] = GLOBAL_PARAMS + s_platformFeePercent[selectedPlatformHash[i]] = _getGlobalParams() .getPlatformFeePercent(selectedPlatformHash[i]); s_isSelectedPlatform[selectedPlatformHash[i]] = true; } @@ -141,7 +157,6 @@ contract CampaignInfo is struct Config { address treasuryFactory; - address token; uint256 protocolFeePercent; bytes32 identifierHash; } @@ -150,10 +165,9 @@ contract CampaignInfo is bytes memory args = Clones.fetchCloneArgs(address(this)); ( config.treasuryFactory, - config.token, config.protocolFeePercent, config.identifierHash - ) = abi.decode(args, (address, address, uint256, bytes32)); + ) = abi.decode(args, (address, uint256, bytes32)); } /** @@ -192,7 +206,7 @@ contract CampaignInfo is * @inheritdoc ICampaignInfo */ function getProtocolAdminAddress() public view override returns (address) { - return GLOBAL_PARAMS.getProtocolAdminAddress(); + return _getGlobalParams().getProtocolAdminAddress(); } /** @@ -216,7 +230,7 @@ contract CampaignInfo is function getPlatformAdminAddress( bytes32 platformHash ) external view override returns (address) { - return GLOBAL_PARAMS.getPlatformAdminAddress(platformHash); + return _getGlobalParams().getPlatformAdminAddress(platformHash); } /** @@ -243,17 +257,30 @@ contract CampaignInfo is /** * @inheritdoc ICampaignInfo */ - function getTokenAddress() external view override returns (address) { + function getProtocolFeePercent() external view override returns (uint256) { Config memory config = getCampaignConfig(); - return config.token; + return config.protocolFeePercent; } /** * @inheritdoc ICampaignInfo */ - function getProtocolFeePercent() external view override returns (uint256) { - Config memory config = getCampaignConfig(); - return config.protocolFeePercent; + function getCampaignCurrency() external view override returns (bytes32) { + return s_campaignData.currency; + } + + /** + * @inheritdoc ICampaignInfo + */ + function getAcceptedTokens() external view override returns (address[] memory) { + return s_acceptedTokens; + } + + /** + * @inheritdoc ICampaignInfo + */ + function isTokenAccepted(address token) external view override returns (bool) { + return s_isAcceptedToken[token]; } /** @@ -405,7 +432,7 @@ contract CampaignInfo is if (checkIfPlatformSelected(platformHash) == selection) { revert CampaignInfoInvalidInput(); } - if (!GLOBAL_PARAMS.checkIfPlatformIsListed(platformHash)) { + if (!_getGlobalParams().checkIfPlatformIsListed(platformHash)) { revert CampaignInfoInvalidPlatformUpdate(platformHash, selection); } @@ -420,7 +447,7 @@ contract CampaignInfo is if (selection) { bool isValid; for (uint256 i = 0; i < platformDataKey.length; i++) { - isValid = GLOBAL_PARAMS.checkIfPlatformDataKeyValid( + isValid = _getGlobalParams().checkIfPlatformDataKeyValid( platformDataKey[i] ); if (!isValid) { @@ -436,7 +463,7 @@ contract CampaignInfo is s_isSelectedPlatform[platformHash] = selection; if (selection) { - s_platformFeePercent[platformHash] = GLOBAL_PARAMS + s_platformFeePercent[platformHash] = _getGlobalParams() .getPlatformFeePercent(platformHash); } else { s_platformFeePercent[platformHash] = 0; @@ -462,7 +489,7 @@ contract CampaignInfo is * @dev External function to cancel the campaign. */ function _cancelCampaign(bytes32 message) external { - if (msg.sender != getProtocolAdminAddress() && msg.sender != owner()) { + if (_msgSender() != getProtocolAdminAddress() && _msgSender() != owner()) { revert CampaignInfoUnauthorized(); } _cancel(message); @@ -478,7 +505,7 @@ contract CampaignInfo is address platformTreasuryAddress ) external whenNotPaused { Config memory config = getCampaignConfig(); - if (msg.sender != config.treasuryFactory) { + if (_msgSender() != config.treasuryFactory) { revert CampaignInfoUnauthorized(); } bool selected = checkIfPlatformSelected(platformHash); diff --git a/src/CampaignInfoFactory.sol b/src/CampaignInfoFactory.sol index 716ac1b4..91c8c02c 100644 --- a/src/CampaignInfoFactory.sol +++ b/src/CampaignInfoFactory.sol @@ -1,29 +1,21 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol"; -import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; -import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol"; +import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; +import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; +import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; import {IGlobalParams} from "./interfaces/IGlobalParams.sol"; import {ICampaignInfoFactory} from "./interfaces/ICampaignInfoFactory.sol"; +import {CampaignInfoFactoryStorage} from "./storage/CampaignInfoFactoryStorage.sol"; /** * @title CampaignInfoFactory * @notice Factory contract for creating campaign information contracts. + * @dev UUPS Upgradeable contract with ERC-7201 namespaced storage */ -contract CampaignInfoFactory is Initializable, ICampaignInfoFactory, Ownable { - IGlobalParams private GLOBAL_PARAMS; - address private s_treasuryFactoryAddress; - bool private s_initialized; - address private s_implementation; - mapping(address => bool) public isValidCampaignInfo; - mapping(bytes32 => address) public identifierToCampaignInfo; - - /** - * @dev Emitted when the factory is initialized. - */ - error CampaignInfoFactoryAlreadyInitialized(); +contract CampaignInfoFactory is Initializable, ICampaignInfoFactory, OwnableUpgradeable, UUPSUpgradeable { /** * @dev Emitted when invalid input is provided. @@ -41,35 +33,54 @@ contract CampaignInfoFactory is Initializable, ICampaignInfoFactory, Ownable { ); /** - * @param globalParams The address of the global parameters contract. + * @dev Emitted when the campaign currency has no tokens. */ - constructor( - IGlobalParams globalParams, - address campaignImplementation - ) Ownable(msg.sender) { - GLOBAL_PARAMS = globalParams; - s_implementation = campaignImplementation; + error CampaignInfoInvalidTokenList(); + + /** + * @dev Constructor that disables initializers to prevent implementation contract initialization + */ + constructor() { + _disableInitializers(); } /** - * @dev Initializes the factory with treasury factory address. - * @param treasuryFactoryAddress The address of the treasury factory contract. + * @notice Initializes the CampaignInfoFactory contract. + * @param initialOwner The address that will own the factory * @param globalParams The address of the global parameters contract. + * @param campaignImplementation The address of the campaign implementation contract. + * @param treasuryFactoryAddress The address of the treasury factory contract. */ - function _initialize( - address treasuryFactoryAddress, - address globalParams - ) external onlyOwner initializer { + function initialize( + address initialOwner, + IGlobalParams globalParams, + address campaignImplementation, + address treasuryFactoryAddress + ) public initializer { if ( - treasuryFactoryAddress == address(0) || globalParams == address(0) + address(globalParams) == address(0) || + campaignImplementation == address(0) || + treasuryFactoryAddress == address(0) || + initialOwner == address(0) ) { revert CampaignInfoFactoryInvalidInput(); } - GLOBAL_PARAMS = IGlobalParams(globalParams); - s_treasuryFactoryAddress = treasuryFactoryAddress; - s_initialized = true; + + __Ownable_init(initialOwner); + __UUPSUpgradeable_init(); + + CampaignInfoFactoryStorage.Storage storage $ = CampaignInfoFactoryStorage._getCampaignInfoFactoryStorage(); + $.globalParams = globalParams; + $.implementation = campaignImplementation; + $.treasuryFactoryAddress = treasuryFactoryAddress; } + /** + * @dev Function that authorizes an upgrade to a new implementation + * @param newImplementation Address of the new implementation + */ + function _authorizeUpgrade(address newImplementation) internal override onlyOwner {} + /** * @inheritdoc ICampaignInfoFactory */ @@ -93,10 +104,12 @@ contract CampaignInfoFactory is Initializable, ICampaignInfoFactory, Ownable { if (platformDataKey.length != platformDataValue.length) { revert CampaignInfoFactoryInvalidInput(); } + + CampaignInfoFactoryStorage.Storage storage $ = CampaignInfoFactoryStorage._getCampaignInfoFactoryStorage(); bool isValid; for (uint256 i = 0; i < platformDataKey.length; i++) { - isValid = GLOBAL_PARAMS.checkIfPlatformDataKeyValid( + isValid = $.globalParams.checkIfPlatformDataKeyValid( platformDataKey[i] ); if (!isValid) { @@ -106,7 +119,7 @@ contract CampaignInfoFactory is Initializable, ICampaignInfoFactory, Ownable { revert CampaignInfoFactoryInvalidInput(); } } - address cloneExists = identifierToCampaignInfo[identifierHash]; + address cloneExists = $.identifierToCampaignInfo[identifierHash]; if (cloneExists != address(0)) { revert CampaignInfoFactoryCampaignWithSameIdentifierExists( identifierHash, @@ -117,35 +130,41 @@ contract CampaignInfoFactory is Initializable, ICampaignInfoFactory, Ownable { bytes32 platformHash; for (uint256 i = 0; i < selectedPlatformHash.length; i++) { platformHash = selectedPlatformHash[i]; - isListed = GLOBAL_PARAMS.checkIfPlatformIsListed(platformHash); + isListed = $.globalParams.checkIfPlatformIsListed(platformHash); if (!isListed) { revert CampaignInfoFactoryPlatformNotListed(platformHash); } } + // Get accepted tokens for the campaign currency + address[] memory acceptedTokens = $.globalParams.getTokensForCurrency(campaignData.currency); + if (acceptedTokens.length == 0) { + revert CampaignInfoInvalidTokenList(); + } + bytes memory args = abi.encode( - s_treasuryFactoryAddress, - GLOBAL_PARAMS.getTokenAddress(), - GLOBAL_PARAMS.getProtocolFeePercent(), + $.treasuryFactoryAddress, + $.globalParams.getProtocolFeePercent(), identifierHash ); - address clone = Clones.cloneWithImmutableArgs(s_implementation, args); + address clone = Clones.cloneWithImmutableArgs($.implementation, args); (bool success, ) = clone.call( abi.encodeWithSignature( - "initialize(address,address,bytes32[],bytes32[],bytes32[],(uint256,uint256,uint256))", + "initialize(address,address,bytes32[],bytes32[],bytes32[],(uint256,uint256,uint256,bytes32),address[])", creator, - address(GLOBAL_PARAMS), + address($.globalParams), selectedPlatformHash, platformDataKey, platformDataValue, - campaignData + campaignData, + acceptedTokens ) ); if (!success) { revert CampaignInfoFactoryCampaignInitializationFailed(); } - identifierToCampaignInfo[identifierHash] = clone; - isValidCampaignInfo[clone] = true; + $.identifierToCampaignInfo[identifierHash] = clone; + $.isValidCampaignInfo[clone] = true; emit CampaignInfoFactoryCampaignCreated(identifierHash, clone); emit CampaignInfoFactoryCampaignInitialized(); } @@ -159,6 +178,27 @@ contract CampaignInfoFactory is Initializable, ICampaignInfoFactory, Ownable { if (newImplementation == address(0)) { revert CampaignInfoFactoryInvalidInput(); } - s_implementation = newImplementation; + CampaignInfoFactoryStorage.Storage storage $ = CampaignInfoFactoryStorage._getCampaignInfoFactoryStorage(); + $.implementation = newImplementation; + } + + /** + * @notice Check if a campaign info address is valid + * @param campaignInfo The campaign info address to check + * @return bool True if valid, false otherwise + */ + function isValidCampaignInfo(address campaignInfo) external view returns (bool) { + CampaignInfoFactoryStorage.Storage storage $ = CampaignInfoFactoryStorage._getCampaignInfoFactoryStorage(); + return $.isValidCampaignInfo[campaignInfo]; + } + + /** + * @notice Get campaign info address from identifier + * @param identifierHash The identifier hash + * @return address The campaign info address + */ + function identifierToCampaignInfo(bytes32 identifierHash) external view returns (address) { + CampaignInfoFactoryStorage.Storage storage $ = CampaignInfoFactoryStorage._getCampaignInfoFactoryStorage(); + return $.identifierToCampaignInfo[identifierHash]; } } diff --git a/src/GlobalParams.sol b/src/GlobalParams.sol index 202951c4..bb0b3faf 100644 --- a/src/GlobalParams.sol +++ b/src/GlobalParams.sol @@ -1,30 +1,24 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; -import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; +import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; +import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; +import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; import {IGlobalParams} from "./interfaces/IGlobalParams.sol"; import {Counters} from "./utils/Counters.sol"; +import {GlobalParamsStorage} from "./storage/GlobalParamsStorage.sol"; /** * @title GlobalParams * @notice Manages global parameters and platform information. + * @dev UUPS Upgradeable contract with ERC-7201 namespaced storage */ -contract GlobalParams is IGlobalParams, Ownable { +contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSUpgradeable { using Counters for Counters.Counter; bytes32 private constant ZERO_BYTES = 0x0000000000000000000000000000000000000000000000000000000000000000; - address private s_protocolAdminAddress; - address private s_tokenAddress; - uint256 private s_protocolFeePercent; - mapping(bytes32 => bool) private s_platformIsListed; - mapping(bytes32 => address) private s_platformAdminAddress; - mapping(bytes32 => uint256) private s_platformFeePercent; - mapping(bytes32 => bytes32) private s_platformDataOwner; - mapping(bytes32 => bool) private s_platformData; - - Counters.Counter private s_numberOfListedPlatforms; /** * @dev Emitted when a platform is enlisted. @@ -51,10 +45,18 @@ contract GlobalParams is IGlobalParams, Ownable { event ProtocolAdminAddressUpdated(address indexed newAdminAddress); /** - * @dev Emitted when the token address is updated. - * @param newTokenAddress The new token address. + * @dev Emitted when a token is added to a currency. + * @param currency The currency identifier. + * @param token The token address added. + */ + event TokenAddedToCurrency(bytes32 indexed currency, address indexed token); + + /** + * @dev Emitted when a token is removed from a currency. + * @param currency The currency identifier. + * @param token The token address removed. */ - event TokenAddressUpdated(address indexed newTokenAddress); + event TokenRemovedFromCurrency(bytes32 indexed currency, address indexed token); /** * @dev Emitted when the protocol fee percent is updated. @@ -92,6 +94,13 @@ contract GlobalParams is IGlobalParams, Ownable { bytes32 platformDataKey ); + /** + * @dev Emitted when data is added to the registry. + * @param key The registry key. + * @param value The registry value. + */ + event DataAddedToRegistry(bytes32 indexed key, bytes32 value); + /** * @dev Throws when the input address is zero. */ @@ -141,6 +150,25 @@ contract GlobalParams is IGlobalParams, Ownable { */ error GlobalParamsUnauthorized(); + /** + * @dev Throws when currency and token arrays length mismatch. + */ + error GlobalParamsCurrencyTokenLengthMismatch(); + + + /** + * @dev Throws when a currency has no tokens registered. + * @param currency The currency identifier. + */ + error GlobalParamsCurrencyHasNoTokens(bytes32 currency); + + /** + * @dev Throws when a token is not found in a currency. + * @param currency The currency identifier. + * @param token The token address. + */ + error GlobalParamsTokenNotInCurrency(bytes32 currency, address token); + /** * @dev Reverts if the input address is zero. */ @@ -167,18 +195,88 @@ contract GlobalParams is IGlobalParams, Ownable { } /** + * @dev Constructor that disables initializers to prevent implementation contract initialization + */ + constructor() { + _disableInitializers(); + } + + /** + * @dev Initializer function (replaces constructor) * @param protocolAdminAddress The address of the protocol admin. - * @param tokenAddress The address of the token contract. * @param protocolFeePercent The protocol fee percentage. + * @param currencies The array of currency identifiers. + * @param tokensPerCurrency The array of token arrays for each currency. */ - constructor( + function initialize( address protocolAdminAddress, - address tokenAddress, - uint256 protocolFeePercent - ) Ownable(protocolAdminAddress) { - s_protocolAdminAddress = protocolAdminAddress; - s_tokenAddress = tokenAddress; - s_protocolFeePercent = protocolFeePercent; + uint256 protocolFeePercent, + bytes32[] memory currencies, + address[][] memory tokensPerCurrency + ) public initializer { + __Ownable_init(protocolAdminAddress); + __UUPSUpgradeable_init(); + + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + $.protocolAdminAddress = protocolAdminAddress; + $.protocolFeePercent = protocolFeePercent; + + uint256 currencyLength = currencies.length; + + if(currencyLength != tokensPerCurrency.length) { + revert GlobalParamsCurrencyTokenLengthMismatch(); + } + + for (uint256 i = 0; i < currencyLength; ) { + for (uint256 j = 0; j < tokensPerCurrency[i].length; ) { + address token = tokensPerCurrency[i][j]; + if (token == address(0)) { + revert GlobalParamsInvalidInput(); + } + $.currencyToTokens[currencies[i]].push(token); + unchecked { + ++j; + } + } + unchecked { + ++i; + } + } + } + + /** + * @dev Function that authorizes an upgrade to a new implementation + * @param newImplementation Address of the new implementation + */ + function _authorizeUpgrade(address newImplementation) internal override onlyOwner {} + + /** + * @notice Adds a key-value pair to the data registry. + * @param key The registry key. + * @param value The registry value. + */ + function addToRegistry( + bytes32 key, + bytes32 value + ) external onlyOwner { + if (key == ZERO_BYTES) { + revert GlobalParamsInvalidInput(); + } + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + $.dataRegistry[key] = value; + emit DataAddedToRegistry(key, value); + } + + /** + * @notice Retrieves a value from the data registry. + * @param key The registry key. + * @return value The registry value. + */ + function getFromRegistry( + bytes32 key + ) external view returns (bytes32 value) { + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + value = $.dataRegistry[key]; } /** @@ -193,7 +291,8 @@ contract GlobalParams is IGlobalParams, Ownable { platformIsListed(platformHash) returns (address account) { - account = s_platformAdminAddress[platformHash]; + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + account = $.platformAdminAddress[platformHash]; if (account == address(0)) { revert GlobalParamsPlatformAdminNotSet(platformHash); } @@ -208,7 +307,8 @@ contract GlobalParams is IGlobalParams, Ownable { override returns (uint256) { - return s_numberOfListedPlatforms.current(); + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + return $.numberOfListedPlatforms.current(); } /** @@ -220,21 +320,16 @@ contract GlobalParams is IGlobalParams, Ownable { override returns (address) { - return s_protocolAdminAddress; - } - - /** - * @inheritdoc IGlobalParams - */ - function getTokenAddress() external view override returns (address) { - return s_tokenAddress; + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + return $.protocolAdminAddress; } /** * @inheritdoc IGlobalParams */ function getProtocolFeePercent() external view override returns (uint256) { - return s_protocolFeePercent; + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + return $.protocolFeePercent; } /** @@ -249,7 +344,8 @@ contract GlobalParams is IGlobalParams, Ownable { platformIsListed(platformHash) returns (uint256 platformFeePercent) { - platformFeePercent = s_platformFeePercent[platformHash]; + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + platformFeePercent = $.platformFeePercent[platformHash]; } /** @@ -258,7 +354,8 @@ contract GlobalParams is IGlobalParams, Ownable { function getPlatformDataOwner( bytes32 platformDataKey ) external view override returns (bytes32 platformHash) { - platformHash = s_platformDataOwner[platformDataKey]; + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + platformHash = $.platformDataOwner[platformDataKey]; } /** @@ -267,7 +364,8 @@ contract GlobalParams is IGlobalParams, Ownable { function checkIfPlatformIsListed( bytes32 platformHash ) public view override returns (bool) { - return s_platformIsListed[platformHash]; + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + return $.platformIsListed[platformHash]; } /** @@ -276,7 +374,8 @@ contract GlobalParams is IGlobalParams, Ownable { function checkIfPlatformDataKeyValid( bytes32 platformDataKey ) external view override returns (bool isValid) { - isValid = s_platformData[platformDataKey]; + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + isValid = $.platformData[platformDataKey]; } /** @@ -294,13 +393,14 @@ contract GlobalParams is IGlobalParams, Ownable { if (platformHash == ZERO_BYTES) { revert GlobalParamsInvalidInput(); } - if (s_platformIsListed[platformHash]) { + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + if ($.platformIsListed[platformHash]) { revert GlobalParamsPlatformAlreadyListed(platformHash); } else { - s_platformIsListed[platformHash] = true; - s_platformAdminAddress[platformHash] = platformAdminAddress; - s_platformFeePercent[platformHash] = platformFeePercent; - s_numberOfListedPlatforms.increment(); + $.platformIsListed[platformHash] = true; + $.platformAdminAddress[platformHash] = platformAdminAddress; + $.platformFeePercent[platformHash] = platformFeePercent; + $.numberOfListedPlatforms.increment(); emit PlatformEnlisted( platformHash, platformAdminAddress, @@ -316,10 +416,11 @@ contract GlobalParams is IGlobalParams, Ownable { function delistPlatform( bytes32 platformHash ) external onlyOwner platformIsListed(platformHash) { - s_platformIsListed[platformHash] = false; - s_platformAdminAddress[platformHash] = address(0); - s_platformFeePercent[platformHash] = 0; - s_numberOfListedPlatforms.decrement(); + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + $.platformIsListed[platformHash] = false; + $.platformAdminAddress[platformHash] = address(0); + $.platformFeePercent[platformHash] = 0; + $.numberOfListedPlatforms.decrement(); emit PlatformDelisted(platformHash); } @@ -335,11 +436,12 @@ contract GlobalParams is IGlobalParams, Ownable { if (platformDataKey == ZERO_BYTES) { revert GlobalParamsInvalidInput(); } - if (s_platformData[platformDataKey]) { + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + if ($.platformData[platformDataKey]) { revert GlobalParamsPlatformDataAlreadySet(); } - s_platformData[platformDataKey] = true; - s_platformDataOwner[platformDataKey] = platformHash; + $.platformData[platformDataKey] = true; + $.platformDataOwner[platformDataKey] = platformHash; emit PlatformDataAdded(platformHash, platformDataKey); } @@ -355,11 +457,12 @@ contract GlobalParams is IGlobalParams, Ownable { if (platformDataKey == ZERO_BYTES) { revert GlobalParamsInvalidInput(); } - if (!s_platformData[platformDataKey]) { + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + if (!$.platformData[platformDataKey]) { revert GlobalParamsPlatformDataNotSet(); } - s_platformData[platformDataKey] = false; - s_platformDataOwner[platformDataKey] = ZERO_BYTES; + $.platformData[platformDataKey] = false; + $.platformDataOwner[platformDataKey] = ZERO_BYTES; emit PlatformDataRemoved(platformHash, platformDataKey); } @@ -369,27 +472,19 @@ contract GlobalParams is IGlobalParams, Ownable { function updateProtocolAdminAddress( address protocolAdminAddress ) external override onlyOwner notAddressZero(protocolAdminAddress) { - s_protocolAdminAddress = protocolAdminAddress; + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + $.protocolAdminAddress = protocolAdminAddress; emit ProtocolAdminAddressUpdated(protocolAdminAddress); } - /** - * @inheritdoc IGlobalParams - */ - function updateTokenAddress( - address tokenAddress - ) external override onlyOwner notAddressZero(tokenAddress) { - s_tokenAddress = tokenAddress; - emit TokenAddressUpdated(tokenAddress); - } - /** * @inheritdoc IGlobalParams */ function updateProtocolFeePercent( uint256 protocolFeePercent ) external override onlyOwner { - s_protocolFeePercent = protocolFeePercent; + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + $.protocolFeePercent = protocolFeePercent; emit ProtocolFeePercentUpdated(protocolFeePercent); } @@ -406,10 +501,64 @@ contract GlobalParams is IGlobalParams, Ownable { platformIsListed(platformHash) notAddressZero(platformAdminAddress) { - s_platformAdminAddress[platformHash] = platformAdminAddress; + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + $.platformAdminAddress[platformHash] = platformAdminAddress; emit PlatformAdminAddressUpdated(platformHash, platformAdminAddress); } + /** + * @inheritdoc IGlobalParams + */ + function addTokenToCurrency( + bytes32 currency, + address token + ) external override onlyOwner notAddressZero(token) { + if (currency == ZERO_BYTES) { + revert GlobalParamsInvalidInput(); + } + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + $.currencyToTokens[currency].push(token); + emit TokenAddedToCurrency(currency, token); + } + + /** + * @inheritdoc IGlobalParams + */ + function removeTokenFromCurrency( + bytes32 currency, + address token + ) external override onlyOwner notAddressZero(token) { + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + address[] storage tokens = $.currencyToTokens[currency]; + uint256 length = tokens.length; + bool found = false; + + for (uint256 i = 0; i < length; ) { + if (tokens[i] == token) { + tokens[i] = tokens[length - 1]; + tokens.pop(); + found = true; + break; + } + unchecked { ++i; } + } + + if (!found) { + revert GlobalParamsTokenNotInCurrency(currency, token); + } + emit TokenRemovedFromCurrency(currency, token); + } + + /** + * @inheritdoc IGlobalParams + */ + function getTokensForCurrency( + bytes32 currency + ) external view override returns (address[] memory) { + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + return $.currencyToTokens[currency]; + } + /** * @dev Reverts if the input address is zero. */ @@ -425,7 +574,8 @@ contract GlobalParams is IGlobalParams, Ownable { * @param platformHash The unique identifier of the platform. */ function _onlyPlatformAdmin(bytes32 platformHash) private view { - if (msg.sender != s_platformAdminAddress[platformHash]) { + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + if (_msgSender() != $.platformAdminAddress[platformHash]) { revert GlobalParamsUnauthorized(); } } diff --git a/src/TreasuryFactory.sol b/src/TreasuryFactory.sol index 44f05280..8f5a0f96 100644 --- a/src/TreasuryFactory.sol +++ b/src/TreasuryFactory.sol @@ -1,14 +1,20 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol"; +import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; +import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; import {ITreasuryFactory} from "./interfaces/ITreasuryFactory.sol"; import {IGlobalParams, AdminAccessChecker} from "./utils/AdminAccessChecker.sol"; +import {TreasuryFactoryStorage} from "./storage/TreasuryFactoryStorage.sol"; -contract TreasuryFactory is ITreasuryFactory, AdminAccessChecker { - mapping(bytes32 => mapping(uint256 => address)) private implementationMap; - mapping(address => bool) private approvedImplementations; +/** + * @title TreasuryFactory + * @notice Factory contract for creating treasury contracts + * @dev UUPS Upgradeable contract with ERC-7201 namespaced storage + */ +contract TreasuryFactory is Initializable, ITreasuryFactory, AdminAccessChecker, UUPSUpgradeable { error TreasuryFactoryUnauthorized(); error TreasuryFactoryInvalidKey(); @@ -19,14 +25,28 @@ contract TreasuryFactory is ITreasuryFactory, AdminAccessChecker { error TreasuryFactoryTreasuryInitializationFailed(); error TreasuryFactorySettingPlatformInfoFailed(); + /** + * @dev Constructor that disables initializers to prevent implementation contract initialization + */ + constructor() { + _disableInitializers(); + } + /** * @notice Initializes the TreasuryFactory contract. - * @dev This constructor sets the address of the GlobalParams contract as the admin. + * @param globalParams The address of the GlobalParams contract */ - constructor(IGlobalParams globalParams) { + function initialize(IGlobalParams globalParams) public initializer { __AccessChecker_init(globalParams); + __UUPSUpgradeable_init(); } + /** + * @dev Function that authorizes an upgrade to a new implementation + * @param newImplementation Address of the new implementation + */ + function _authorizeUpgrade(address newImplementation) internal override onlyProtocolAdmin {} + /** * @inheritdoc ITreasuryFactory */ @@ -38,7 +58,8 @@ contract TreasuryFactory is ITreasuryFactory, AdminAccessChecker { if (implementation == address(0)) { revert TreasuryFactoryInvalidAddress(); } - implementationMap[platformHash][implementationId] = implementation; + TreasuryFactoryStorage.Storage storage $ = TreasuryFactoryStorage._getTreasuryFactoryStorage(); + $.implementationMap[platformHash][implementationId] = implementation; } /** @@ -48,13 +69,12 @@ contract TreasuryFactory is ITreasuryFactory, AdminAccessChecker { bytes32 platformHash, uint256 implementationId ) external override onlyProtocolAdmin { - address implementation = implementationMap[platformHash][ - implementationId - ]; + TreasuryFactoryStorage.Storage storage $ = TreasuryFactoryStorage._getTreasuryFactoryStorage(); + address implementation = $.implementationMap[platformHash][implementationId]; if (implementation == address(0)) { revert TreasuryFactoryImplementationNotSet(); } - approvedImplementations[implementation] = true; + $.approvedImplementations[implementation] = true; } /** @@ -63,7 +83,8 @@ contract TreasuryFactory is ITreasuryFactory, AdminAccessChecker { function disapproveTreasuryImplementation( address implementation ) external override onlyProtocolAdmin { - approvedImplementations[implementation] = false; + TreasuryFactoryStorage.Storage storage $ = TreasuryFactoryStorage._getTreasuryFactoryStorage(); + $.approvedImplementations[implementation] = false; } /** @@ -73,7 +94,8 @@ contract TreasuryFactory is ITreasuryFactory, AdminAccessChecker { bytes32 platformHash, uint256 implementationId ) external override onlyPlatformAdmin(platformHash) { - delete implementationMap[platformHash][implementationId]; + TreasuryFactoryStorage.Storage storage $ = TreasuryFactoryStorage._getTreasuryFactoryStorage(); + delete $.implementationMap[platformHash][implementationId]; } /** @@ -91,10 +113,9 @@ contract TreasuryFactory is ITreasuryFactory, AdminAccessChecker { onlyPlatformAdmin(platformHash) returns (address clone) { - address implementation = implementationMap[platformHash][ - implementationId - ]; - if (!approvedImplementations[implementation]) { + TreasuryFactoryStorage.Storage storage $ = TreasuryFactoryStorage._getTreasuryFactoryStorage(); + address implementation = $.implementationMap[platformHash][implementationId]; + if (!$.approvedImplementations[implementation]) { revert TreasuryFactoryImplementationNotSetOrApproved(); } diff --git a/src/interfaces/ICampaignData.sol b/src/interfaces/ICampaignData.sol index abf5e0ac..bb8a5095 100644 --- a/src/interfaces/ICampaignData.sol +++ b/src/interfaces/ICampaignData.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; /** * @title ICampaignData @@ -7,11 +7,12 @@ pragma solidity ^0.8.20; */ interface ICampaignData { /** - * @dev Struct to represent campaign data, including launch time, deadline, and goal amount. + * @dev Struct to represent campaign data, including launch time, deadline, goal amount, and currency. */ struct CampaignData { uint256 launchTime; // Timestamp when the campaign is launched. uint256 deadline; // Timestamp or block number when the campaign ends. uint256 goalAmount; // Funding goal amount that the campaign aims to achieve. + bytes32 currency; // Currency identifier for the campaign (e.g., bytes32("USD")). } } diff --git a/src/interfaces/ICampaignInfo.sol b/src/interfaces/ICampaignInfo.sol index 6dda02c9..203d8172 100644 --- a/src/interfaces/ICampaignInfo.sol +++ b/src/interfaces/ICampaignInfo.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; /** * @title ICampaignInfo @@ -60,18 +60,31 @@ interface ICampaignInfo { */ function getGoalAmount() external view returns (uint256); - /** - * @notice Retrieves the address of the token used in the campaign. - * @return The address of the campaign's token. - */ - function getTokenAddress() external view returns (address); - /** * @notice Retrieves the protocol fee percentage for the campaign. * @return The protocol fee percentage applied to the campaign. */ function getProtocolFeePercent() external view returns (uint256); + /** + * @notice Retrieves the campaign's currency identifier. + * @return The bytes32 currency identifier for the campaign. + */ + function getCampaignCurrency() external view returns (bytes32); + + /** + * @notice Retrieves the cached accepted tokens for the campaign. + * @return An array of token addresses accepted for the campaign. + */ + function getAcceptedTokens() external view returns (address[] memory); + + /** + * @notice Checks if a token is accepted for the campaign. + * @param token The token address to check. + * @return True if the token is accepted; otherwise, false. + */ + function isTokenAccepted(address token) external view returns (bool); + /** * @notice Retrieves the platform fee percentage for a specific platform. * @param platformHash The bytes32 identifier of the platform. diff --git a/src/interfaces/ICampaignInfoFactory.sol b/src/interfaces/ICampaignInfoFactory.sol index cc7f137c..7f1af5a7 100644 --- a/src/interfaces/ICampaignInfoFactory.sol +++ b/src/interfaces/ICampaignInfoFactory.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import {ICampaignData} from "./ICampaignData.sol"; @@ -35,7 +35,7 @@ interface ICampaignInfoFactory is ICampaignData { * @param selectedPlatformHash An array of platform identifiers selected for the campaign. * @param platformDataKey An array of platform-specific data keys. * @param platformDataValue An array of platform-specific data values. - * @param campaignData The struct containing campaign launch details. + * @param campaignData The struct containing campaign launch details (including currency). */ function createCampaign( address creator, diff --git a/src/interfaces/ICampaignPaymentTreasury.sol b/src/interfaces/ICampaignPaymentTreasury.sol index db7631d8..b9601fbb 100644 --- a/src/interfaces/ICampaignPaymentTreasury.sol +++ b/src/interfaces/ICampaignPaymentTreasury.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; /** * @title ICampaignPaymentTreasury @@ -12,6 +12,7 @@ interface ICampaignPaymentTreasury { * @param paymentId A unique identifier for the payment. * @param buyerId The id of the buyer initiating the payment. * @param itemId The identifier of the item being purchased. + * @param paymentToken The token to use for the payment. * @param amount The amount to be paid for the item. * @param expiration The timestamp after which the payment expires. */ @@ -19,6 +20,7 @@ interface ICampaignPaymentTreasury { bytes32 paymentId, bytes32 buyerId, bytes32 itemId, + address paymentToken, uint256 amount, uint256 expiration ) external; @@ -29,12 +31,14 @@ interface ICampaignPaymentTreasury { * @param paymentId The unique identifier of the payment. * @param itemId The identifier of the item being purchased. * @param buyerAddress The address of the buyer making the payment. + * @param paymentToken The token to use for the payment. * @param amount The amount to be paid for the item. */ function processCryptoPayment( bytes32 paymentId, bytes32 itemId, address buyerAddress, + address paymentToken, uint256 amount ) external; diff --git a/src/interfaces/ICampaignTreasury.sol b/src/interfaces/ICampaignTreasury.sol index 5bac65ee..1f2f85c9 100644 --- a/src/interfaces/ICampaignTreasury.sol +++ b/src/interfaces/ICampaignTreasury.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; /** * @title ICampaignTreasury diff --git a/src/interfaces/IGlobalParams.sol b/src/interfaces/IGlobalParams.sol index 4bc1f7dc..f44bea73 100644 --- a/src/interfaces/IGlobalParams.sol +++ b/src/interfaces/IGlobalParams.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; /** * @title IGlobalParams @@ -36,12 +36,6 @@ interface IGlobalParams { */ function getProtocolAdminAddress() external view returns (address); - /** - * @notice Retrieves the address of the protocol's native token. - * @return The address of the native token. - */ - function getTokenAddress() external view returns (address); - /** * @notice Retrieves the protocol fee percentage. * @return The protocol fee percentage as a uint256 value. @@ -81,12 +75,6 @@ interface IGlobalParams { */ function updateProtocolAdminAddress(address _protocolAdminAddress) external; - /** - * @notice Updates the address of the protocol's native token. - * @param _tokenAddress The new address of the native token. - */ - function updateTokenAddress(address _tokenAddress) external; - /** * @notice Updates the protocol fee percentage. * @param _protocolFeePercent The new protocol fee percentage as a uint256 value. @@ -102,4 +90,27 @@ interface IGlobalParams { bytes32 _platformHash, address _platformAdminAddress ) external; + + /** + * @notice Adds a token to a currency. + * @param currency The currency identifier. + * @param token The token address to add. + */ + function addTokenToCurrency(bytes32 currency, address token) external; + + /** + * @notice Removes a token from a currency. + * @param currency The currency identifier. + * @param token The token address to remove. + */ + function removeTokenFromCurrency(bytes32 currency, address token) external; + + /** + * @notice Retrieves all tokens accepted for a specific currency. + * @param currency The currency identifier. + * @return An array of token addresses accepted for the currency. + */ + function getTokensForCurrency( + bytes32 currency + ) external view returns (address[] memory); } diff --git a/src/interfaces/IItem.sol b/src/interfaces/IItem.sol index 95a1aad8..09dd6dc7 100644 --- a/src/interfaces/IItem.sol +++ b/src/interfaces/IItem.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; /** * @title IItem diff --git a/src/interfaces/IReward.sol b/src/interfaces/IReward.sol index 92a3212f..0c570869 100644 --- a/src/interfaces/IReward.sol +++ b/src/interfaces/IReward.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; /** * @title IReward * @notice An interface for managing rewards in a campaign. diff --git a/src/interfaces/ITreasuryFactory.sol b/src/interfaces/ITreasuryFactory.sol index ca3f4b74..55b89b2a 100644 --- a/src/interfaces/ITreasuryFactory.sol +++ b/src/interfaces/ITreasuryFactory.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; /** * @title ITreasuryFactory diff --git a/src/storage/AdminAccessCheckerStorage.sol b/src/storage/AdminAccessCheckerStorage.sol new file mode 100644 index 00000000..ba3352e6 --- /dev/null +++ b/src/storage/AdminAccessCheckerStorage.sol @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.22; + +import {IGlobalParams} from "../interfaces/IGlobalParams.sol"; + +/** + * @title AdminAccessCheckerStorage + * @notice Storage contract for AdminAccessChecker using ERC-7201 namespaced storage + * @dev This contract contains the storage layout and accessor functions for AdminAccessChecker + */ +library AdminAccessCheckerStorage { + /// @custom:storage-location erc7201:ccprotocol.storage.AdminAccessChecker + struct Storage { + IGlobalParams globalParams; + } + + // keccak256(abi.encode(uint256(keccak256("ccprotocol.storage.AdminAccessChecker")) - 1)) & ~bytes32(uint256(0xff)) + bytes32 private constant ADMIN_ACCESS_CHECKER_STORAGE_LOCATION = + 0x7c2f08fa04c2c7c7ab255a45dbf913d4c236b91c59858917e818398e997f8800; + + function _getAdminAccessCheckerStorage() internal pure returns (Storage storage $) { + assembly { + $.slot := ADMIN_ACCESS_CHECKER_STORAGE_LOCATION + } + } +} diff --git a/src/storage/CampaignInfoFactoryStorage.sol b/src/storage/CampaignInfoFactoryStorage.sol new file mode 100644 index 00000000..3edb2e5e --- /dev/null +++ b/src/storage/CampaignInfoFactoryStorage.sol @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.22; + +import {IGlobalParams} from "../interfaces/IGlobalParams.sol"; + +/** + * @title CampaignInfoFactoryStorage + * @notice Storage contract for CampaignInfoFactory using ERC-7201 namespaced storage + * @dev This contract contains the storage layout and accessor functions for CampaignInfoFactory + */ +library CampaignInfoFactoryStorage { + /// @custom:storage-location erc7201:ccprotocol.storage.CampaignInfoFactory + struct Storage { + IGlobalParams globalParams; + address treasuryFactoryAddress; + address implementation; + mapping(address => bool) isValidCampaignInfo; + mapping(bytes32 => address) identifierToCampaignInfo; + } + + // keccak256(abi.encode(uint256(keccak256("ccprotocol.storage.CampaignInfoFactory")) - 1)) & ~bytes32(uint256(0xff)) + bytes32 private constant CAMPAIGN_INFO_FACTORY_STORAGE_LOCATION = + 0x2857858a392b093e1f8b3f368c2276ce911f27cef445605a2932ebe945968d00; + + function _getCampaignInfoFactoryStorage() internal pure returns (Storage storage $) { + assembly { + $.slot := CAMPAIGN_INFO_FACTORY_STORAGE_LOCATION + } + } +} diff --git a/src/storage/GlobalParamsStorage.sol b/src/storage/GlobalParamsStorage.sol new file mode 100644 index 00000000..401eff25 --- /dev/null +++ b/src/storage/GlobalParamsStorage.sol @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.22; + +import {Counters} from "../utils/Counters.sol"; + +/** + * @title GlobalParamsStorage + * @notice Storage contract for GlobalParams using ERC-7201 namespaced storage + * @dev This contract contains the storage layout and accessor functions for GlobalParams + */ +library GlobalParamsStorage { + using Counters for Counters.Counter; + + /// @custom:storage-location erc7201:ccprotocol.storage.GlobalParams + struct Storage { + address protocolAdminAddress; + uint256 protocolFeePercent; + mapping(bytes32 => bool) platformIsListed; + mapping(bytes32 => address) platformAdminAddress; + mapping(bytes32 => uint256) platformFeePercent; + mapping(bytes32 => bytes32) platformDataOwner; + mapping(bytes32 => bool) platformData; + mapping(bytes32 => bytes32) dataRegistry; + mapping(bytes32 => address[]) currencyToTokens; + Counters.Counter numberOfListedPlatforms; + } + + // keccak256(abi.encode(uint256(keccak256("ccprotocol.storage.GlobalParams")) - 1)) & ~bytes32(uint256(0xff)) + bytes32 private constant GLOBAL_PARAMS_STORAGE_LOCATION = + 0x83d0145f7c1378f10048390769ec94f999b3ba6d94904b8fd7251512962b1c00; + + function _getGlobalParamsStorage() internal pure returns (Storage storage $) { + assembly { + $.slot := GLOBAL_PARAMS_STORAGE_LOCATION + } + } +} diff --git a/src/storage/TreasuryFactoryStorage.sol b/src/storage/TreasuryFactoryStorage.sol new file mode 100644 index 00000000..fe40a181 --- /dev/null +++ b/src/storage/TreasuryFactoryStorage.sol @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.22; + +/** + * @title TreasuryFactoryStorage + * @notice Storage contract for TreasuryFactory using ERC-7201 namespaced storage + * @dev This contract contains the storage layout and accessor functions for TreasuryFactory + */ +library TreasuryFactoryStorage { + /// @custom:storage-location erc7201:ccprotocol.storage.TreasuryFactory + struct Storage { + mapping(bytes32 => mapping(uint256 => address)) implementationMap; + mapping(address => bool) approvedImplementations; + } + + // keccak256(abi.encode(uint256(keccak256("ccprotocol.storage.TreasuryFactory")) - 1)) & ~bytes32(uint256(0xff)) + bytes32 private constant TREASURY_FACTORY_STORAGE_LOCATION = + 0x96b7de8c171ef460648aea35787d043e89feb6b6de2623a1e6f17a91b9c9e900; + + function _getTreasuryFactoryStorage() internal pure returns (Storage storage $) { + assembly { + $.slot := TREASURY_FACTORY_STORAGE_LOCATION + } + } +} diff --git a/src/treasuries/AllOrNothing.sol b/src/treasuries/AllOrNothing.sol index 10b52d28..43e37324 100644 --- a/src/treasuries/AllOrNothing.sol +++ b/src/treasuries/AllOrNothing.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol"; @@ -30,6 +30,8 @@ contract AllOrNothing is mapping(uint256 => uint256) private s_tokenToPledgedAmount; // Mapping to store reward details by name mapping(bytes32 => Reward) private s_reward; + // Mapping to store the token used for each NFT + mapping(uint256 => address) private s_tokenIdToPledgeToken; // Counters for token IDs and rewards Counters.Counter private s_tokenIdCounter; @@ -41,6 +43,7 @@ contract AllOrNothing is /** * @dev Emitted when a backer makes a pledge. * @param backer The address of the backer making the pledge. + * @param pledgeToken The token used for the pledge. * @param reward The name of the reward. * @param pledgeAmount The amount pledged. * @param tokenId The ID of the token representing the pledge. @@ -48,7 +51,8 @@ contract AllOrNothing is */ event Receipt( address indexed backer, - bytes32 indexed reward, + address indexed pledgeToken, + bytes32 reward, uint256 pledgeAmount, uint256 shippingFee, uint256 tokenId, @@ -110,6 +114,11 @@ contract AllOrNothing is */ error AllOrNothingRewardExists(); + /** + * @dev Emitted when a token is not accepted for the campaign. + */ + error AllOrNothingTokenNotAccepted(address token); + /** * @dev Emitted when claiming an unclaimable refund. * @param tokenId The ID of the token representing the pledge. @@ -158,7 +167,18 @@ contract AllOrNothing is * @inheritdoc ICampaignTreasury */ function getRaisedAmount() external view override returns (uint256) { - return s_pledgedAmount; + address[] memory acceptedTokens = INFO.getAcceptedTokens(); + uint256 totalNormalized = 0; + + for (uint256 i = 0; i < acceptedTokens.length; i++) { + address token = acceptedTokens[i]; + uint256 amount = s_tokenRaisedAmounts[token]; + if (amount > 0) { + totalNormalized += _normalizeAmount(token, amount); + } + } + + return totalNormalized; } /** @@ -240,10 +260,13 @@ contract AllOrNothing is * @dev The first element of the `reward` array must be a reward tier and the other elements can be either reward tiers or non-reward tiers. * The non-reward tiers cannot be pledged for without a reward. * @param backer The address of the backer making the pledge. + * @param pledgeToken The token address to use for the pledge. + * @param shippingFee The shipping fee amount. * @param reward An array of reward names. */ function pledgeForAReward( address backer, + address pledgeToken, uint256 shippingFee, bytes32[] calldata reward ) @@ -276,16 +299,18 @@ contract AllOrNothing is } pledgeAmount += tempReward.rewardValue; } - _pledge(backer, reward[0], pledgeAmount, shippingFee, tokenId, reward); + _pledge(backer, pledgeToken, reward[0], pledgeAmount, shippingFee, tokenId, reward); } /** * @notice Allows a backer to pledge without selecting a reward. * @param backer The address of the backer making the pledge. + * @param pledgeToken The token address to use for the pledge. * @param pledgeAmount The amount of the pledge. */ function pledgeWithoutAReward( address backer, + address pledgeToken, uint256 pledgeAmount ) external @@ -298,7 +323,7 @@ contract AllOrNothing is uint256 tokenId = s_tokenIdCounter.current(); bytes32[] memory emptyByteArray = new bytes32[](0); - _pledge(backer, ZERO_BYTES, pledgeAmount, 0, tokenId, emptyByteArray); + _pledge(backer, pledgeToken, ZERO_BYTES, pledgeAmount, 0, tokenId, emptyByteArray); } /** @@ -318,15 +343,20 @@ contract AllOrNothing is } uint256 amountToRefund = s_tokenToTotalCollectedAmount[tokenId]; uint256 pledgedAmount = s_tokenToPledgedAmount[tokenId]; + address pledgeToken = s_tokenIdToPledgeToken[tokenId]; + if (amountToRefund == 0) { revert AllOrNothingNotClaimable(tokenId); } + s_tokenToTotalCollectedAmount[tokenId] = 0; s_tokenToPledgedAmount[tokenId] = 0; - s_pledgedAmount -= pledgedAmount; + s_tokenRaisedAmounts[pledgeToken] -= pledgedAmount; + delete s_tokenIdToPledgeToken[tokenId]; + burn(tokenId); - TOKEN.safeTransfer(msg.sender, amountToRefund); - emit RefundClaimed(tokenId, amountToRefund, msg.sender); + IERC20(pledgeToken).safeTransfer(_msgSender(), amountToRefund); + emit RefundClaimed(tokenId, amountToRefund, _msgSender()); } /** @@ -358,8 +388,8 @@ contract AllOrNothing is */ function cancelTreasury(bytes32 message) public override { if ( - msg.sender != INFO.getPlatformAdminAddress(PLATFORM_HASH) && - msg.sender != INFO.owner() + _msgSender() != INFO.getPlatformAdminAddress(PLATFORM_HASH) && + _msgSender() != INFO.owner() ) { revert AllOrNothingUnAuthorized(); } @@ -381,21 +411,47 @@ contract AllOrNothing is function _pledge( address backer, + address pledgeToken, bytes32 reward, uint256 pledgeAmount, uint256 shippingFee, uint256 tokenId, bytes32[] memory rewards ) private { - uint256 totalAmount = pledgeAmount + shippingFee; - TOKEN.safeTransferFrom(backer, address(this), totalAmount); + // Validate token is accepted + if (!INFO.isTokenAccepted(pledgeToken)) { + revert AllOrNothingTokenNotAccepted(pledgeToken); + } + + // If this is for a reward, pledgeAmount and shippingFee are in 18 decimals + // If not for a reward, amounts are already in token decimals + uint256 pledgeAmountInTokenDecimals; + uint256 shippingFeeInTokenDecimals; + + if (reward != ZERO_BYTES) { + // Reward pledge: denormalize from 18 decimals to token decimals + pledgeAmountInTokenDecimals = _denormalizeAmount(pledgeToken, pledgeAmount); + shippingFeeInTokenDecimals = _denormalizeAmount(pledgeToken, shippingFee); + } else { + // Non-reward pledge: already in token decimals + pledgeAmountInTokenDecimals = pledgeAmount; + shippingFeeInTokenDecimals = shippingFee; + } + + uint256 totalAmount = pledgeAmountInTokenDecimals + shippingFeeInTokenDecimals; + + IERC20(pledgeToken).safeTransferFrom(backer, address(this), totalAmount); + s_tokenIdCounter.increment(); - s_tokenToPledgedAmount[tokenId] = pledgeAmount; + s_tokenToPledgedAmount[tokenId] = pledgeAmountInTokenDecimals; s_tokenToTotalCollectedAmount[tokenId] = totalAmount; - s_pledgedAmount += pledgeAmount; + s_tokenIdToPledgeToken[tokenId] = pledgeToken; + s_tokenRaisedAmounts[pledgeToken] += pledgeAmountInTokenDecimals; + _safeMint(backer, tokenId, abi.encodePacked(backer, reward, rewards)); emit Receipt( backer, + pledgeToken, reward, pledgeAmount, shippingFee, diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index f7c64500..6f8fc9a8 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -1,7 +1,8 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; +import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import {ERC721Burnable} from "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol"; @@ -40,6 +41,13 @@ contract KeepWhatsRaised is mapping(bytes32 => uint256) public s_paymentGatewayFees; /// Mapping that stores fee values indexed by their corresponding fee keys. mapping(bytes32 => uint256) private s_feeValues; + + // Multi-token support + mapping(uint256 => address) private s_tokenIdToPledgeToken; // Token used for each NFT + mapping(address => uint256) private s_protocolFeePerToken; // Protocol fees per token + mapping(address => uint256) private s_platformFeePerToken; // Platform fees per token + mapping(address => uint256) private s_tipPerToken; // Tips per token + mapping(address => uint256) private s_availablePerToken; // Available amount per token // Counters for token IDs and rewards Counters.Counter private s_tokenIdCounter; @@ -97,10 +105,6 @@ contract KeepWhatsRaised is string private s_name; string private s_symbol; - uint256 private s_tip; - uint256 private s_platformFee; - uint256 private s_protocolFee; - uint256 private s_availablePledgedAmount; uint256 private s_cancellationTime; bool private s_isWithdrawalApproved; bool private s_tipClaimed; @@ -112,6 +116,7 @@ contract KeepWhatsRaised is /** * @dev Emitted when a backer makes a pledge. * @param backer The address of the backer making the pledge. + * @param pledgeToken The token used for the pledge. * @param reward The name of the reward. * @param pledgeAmount The amount pledged. * @param tip An optional tip can be added during the process. @@ -120,7 +125,8 @@ contract KeepWhatsRaised is */ event Receipt( address indexed backer, - bytes32 indexed reward, + address indexed pledgeToken, + bytes32 reward, uint256 pledgeAmount, uint256 tip, uint256 tokenId, @@ -216,6 +222,11 @@ contract KeepWhatsRaised is */ error KeepWhatsRaisedInvalidInput(); + /** + * @dev Emitted when a token is not accepted for the campaign. + */ + error KeepWhatsRaisedTokenNotAccepted(address token); + /** * @dev Emitted when a `Reward` already exists for given input. */ @@ -308,12 +319,12 @@ contract KeepWhatsRaised is } /// @notice Restricts access to only the platform admin or the campaign owner. - /// @dev Checks if `msg.sender` is either the platform admin (via `INFO.getPlatformAdminAddress`) + /// @dev Checks if `_msgSender()` is either the platform admin (via `INFO.getPlatformAdminAddress`) /// or the campaign owner (via `INFO.owner()`). Reverts with `KeepWhatsRaisedUnAuthorized` if not authorized. modifier onlyPlatformAdminOrCampaignOwner() { if ( - msg.sender != INFO.getPlatformAdminAddress(PLATFORM_HASH) && - msg.sender != INFO.owner() + _msgSender() != INFO.getPlatformAdminAddress(PLATFORM_HASH) && + _msgSender() != INFO.owner() ) { revert KeepWhatsRaisedUnAuthorized(); } @@ -369,7 +380,18 @@ contract KeepWhatsRaised is * @inheritdoc ICampaignTreasury */ function getRaisedAmount() external view override returns (uint256) { - return s_pledgedAmount; + address[] memory acceptedTokens = INFO.getAcceptedTokens(); + uint256 totalNormalized = 0; + + for (uint256 i = 0; i < acceptedTokens.length; i++) { + address token = acceptedTokens[i]; + uint256 amount = s_tokenRaisedAmounts[token]; + if (amount > 0) { + totalNormalized += _normalizeAmount(token, amount); + } + } + + return totalNormalized; } /** @@ -377,7 +399,18 @@ contract KeepWhatsRaised is * @return The current available raised amount as a uint256 value. */ function getAvailableRaisedAmount() external view returns (uint256) { - return s_availablePledgedAmount; + address[] memory acceptedTokens = INFO.getAcceptedTokens(); + uint256 totalNormalized = 0; + + for (uint256 i = 0; i < acceptedTokens.length; i++) { + address token = acceptedTokens[i]; + uint256 amount = s_availablePerToken[token]; + if (amount > 0) { + totalNormalized += _normalizeAmount(token, amount); + } + } + + return totalNormalized; } /** @@ -652,6 +685,7 @@ contract KeepWhatsRaised is function setFeeAndPledge( bytes32 pledgeId, address backer, + address pledgeToken, uint256 pledgeAmount, uint256 tip, uint256 fee, @@ -669,9 +703,9 @@ contract KeepWhatsRaised is setPaymentGatewayFee(pledgeId, fee); if(isPledgeForAReward){ - _pledgeForAReward(pledgeId, backer, tip, reward, msg.sender); // Pass admin as token source + _pledgeForAReward(pledgeId, backer, pledgeToken, tip, reward, _msgSender()); // Pass admin as token source }else { - _pledgeWithoutAReward(pledgeId, backer, pledgeAmount, tip, msg.sender); // Pass admin as token source + _pledgeWithoutAReward(pledgeId, backer, pledgeToken, pledgeAmount, tip, _msgSender()); // Pass admin as token source } } @@ -681,12 +715,14 @@ contract KeepWhatsRaised is * The non-reward tiers cannot be pledged for without a reward. * @param pledgeId The unique identifier of the pledge. * @param backer The address of the backer making the pledge. + * @param pledgeToken The token to use for the pledge. * @param tip An optional tip can be added during the process. * @param reward An array of reward names. */ function pledgeForAReward( bytes32 pledgeId, address backer, + address pledgeToken, uint256 tip, bytes32[] calldata reward ) @@ -697,7 +733,7 @@ contract KeepWhatsRaised is whenCampaignNotCancelled whenNotCancelled { - _pledgeForAReward(pledgeId, backer, tip, reward, backer); // Pass backer as token source for direct calls + _pledgeForAReward(pledgeId, backer, pledgeToken, tip, reward, backer); // Pass backer as token source for direct calls } /** @@ -708,6 +744,7 @@ contract KeepWhatsRaised is * setFeeAndPledge (with admin as token source). * @param pledgeId The unique identifier of the pledge. * @param backer The address of the backer making the pledge (receives the NFT). + * @param pledgeToken The token to use for the pledge. * @param tip An optional tip can be added during the process. * @param reward An array of reward names. * @param tokenSource The address from which tokens will be transferred (either backer for direct calls or admin for setFeeAndPledge calls). @@ -715,6 +752,7 @@ contract KeepWhatsRaised is function _pledgeForAReward( bytes32 pledgeId, address backer, + address pledgeToken, uint256 tip, bytes32[] calldata reward, address tokenSource @@ -726,7 +764,7 @@ contract KeepWhatsRaised is whenCampaignNotCancelled whenNotCancelled { - bytes32 internalPledgeId = keccak256(abi.encodePacked(pledgeId, msg.sender)); + bytes32 internalPledgeId = keccak256(abi.encodePacked(pledgeId, _msgSender())); if(s_processedPledges[internalPledgeId]){ revert KeepWhatsRaisedPledgeAlreadyProcessed(internalPledgeId); @@ -755,19 +793,21 @@ contract KeepWhatsRaised is } pledgeAmount += tempReward.rewardValue; } - _pledge(pledgeId, backer, reward[0], pledgeAmount, tip, tokenId, reward, tokenSource); + _pledge(pledgeId, backer, pledgeToken, reward[0], pledgeAmount, tip, tokenId, reward, tokenSource); } /** * @notice Allows a backer to pledge without selecting a reward. * @param pledgeId The unique identifier of the pledge. * @param backer The address of the backer making the pledge. + * @param pledgeToken The token to use for the pledge. * @param pledgeAmount The amount of the pledge. * @param tip An optional tip can be added during the process. */ function pledgeWithoutAReward( bytes32 pledgeId, address backer, + address pledgeToken, uint256 pledgeAmount, uint256 tip ) @@ -778,7 +818,7 @@ contract KeepWhatsRaised is whenCampaignNotCancelled whenNotCancelled { - _pledgeWithoutAReward(pledgeId, backer, pledgeAmount, tip, backer); // Pass backer as token source for direct calls + _pledgeWithoutAReward(pledgeId, backer, pledgeToken, pledgeAmount, tip, backer); // Pass backer as token source for direct calls } /** @@ -787,6 +827,7 @@ contract KeepWhatsRaised is * setFeeAndPledge (with admin as token source). * @param pledgeId The unique identifier of the pledge. * @param backer The address of the backer making the pledge (receives the NFT). + * @param pledgeToken The token to use for the pledge. * @param pledgeAmount The amount of the pledge. * @param tip An optional tip can be added during the process. * @param tokenSource The address from which tokens will be transferred (either backer for direct calls or admin for setFeeAndPledge calls). @@ -794,6 +835,7 @@ contract KeepWhatsRaised is function _pledgeWithoutAReward( bytes32 pledgeId, address backer, + address pledgeToken, uint256 pledgeAmount, uint256 tip, address tokenSource @@ -805,7 +847,7 @@ contract KeepWhatsRaised is whenCampaignNotCancelled whenNotCancelled { - bytes32 internalPledgeId = keccak256(abi.encodePacked(pledgeId, msg.sender)); + bytes32 internalPledgeId = keccak256(abi.encodePacked(pledgeId, _msgSender())); if(s_processedPledges[internalPledgeId]){ revert KeepWhatsRaisedPledgeAlreadyProcessed(internalPledgeId); @@ -815,7 +857,7 @@ contract KeepWhatsRaised is uint256 tokenId = s_tokenIdCounter.current(); bytes32[] memory emptyByteArray = new bytes32[](0); - _pledge(pledgeId, backer, ZERO_BYTES, pledgeAmount, tip, tokenId, emptyByteArray, tokenSource); + _pledge(pledgeId, backer, pledgeToken, ZERO_BYTES, pledgeAmount, tip, tokenId, emptyByteArray, tokenSource); } /** @@ -828,11 +870,13 @@ contract KeepWhatsRaised is /** * @dev Allows the campaign owner or platform admin to withdraw funds, applying required fees and taxes. * + * @param token The token to withdraw. * @param amount The withdrawal amount (ignored for final withdrawals). * * Requirements: * - Caller must be authorized. * - Withdrawals must be enabled, not paused, and within the allowed time. + * - Token must be accepted for the campaign. * - For partial withdrawals: * - `amount` > 0 and `amount + fees` ≤ available balance. * - For final withdrawals: @@ -840,7 +884,7 @@ contract KeepWhatsRaised is * * Effects: * - Deducts fees (flat, cumulative, and Colombian tax if applicable). - * - Updates available balance. + * - Updates available balance per token. * - Transfers net funds to the recipient. * * Reverts: @@ -850,6 +894,7 @@ contract KeepWhatsRaised is * - `WithdrawalWithFeeSuccessful`. */ function withdraw( + address token, uint256 amount ) public @@ -859,10 +904,17 @@ contract KeepWhatsRaised is whenNotCancelled withdrawalEnabled { - uint256 flatFee = getFeeValue(s_feeKeys.flatFeeKey); - uint256 cumulativeFee = getFeeValue(s_feeKeys.cumulativeFlatFeeKey); + if (!INFO.isTokenAccepted(token)) { + revert KeepWhatsRaisedTokenNotAccepted(token); + } + + // Fee config values are in 18 decimals, denormalize for comparison/calculation + uint256 flatFee = _denormalizeAmount(token, getFeeValue(s_feeKeys.flatFeeKey)); + uint256 cumulativeFee = _denormalizeAmount(token, getFeeValue(s_feeKeys.cumulativeFlatFeeKey)); + uint256 minimumWithdrawalForFeeExemption = _denormalizeAmount(token, s_config.minimumWithdrawalForFeeExemption); + uint256 currentTime = block.timestamp; - uint256 withdrawalAmount = s_availablePledgedAmount; + uint256 withdrawalAmount = s_availablePerToken[token]; uint256 totalFee = 0; address recipient = INFO.owner(); bool isFinalWithdrawal = (currentTime > getDeadline()); @@ -872,8 +924,8 @@ contract KeepWhatsRaised is if(withdrawalAmount == 0){ revert KeepWhatsRaisedAlreadyWithdrawn(); } - if(withdrawalAmount < s_config.minimumWithdrawalForFeeExemption){ - s_platformFee += flatFee; + if(withdrawalAmount < minimumWithdrawalForFeeExemption){ + s_platformFeePerToken[token] += flatFee; totalFee += flatFee; } @@ -882,15 +934,15 @@ contract KeepWhatsRaised is if(withdrawalAmount == 0){ revert KeepWhatsRaisedInvalidInput(); } - if(withdrawalAmount > s_availablePledgedAmount){ - revert KeepWhatsRaisedInsufficientFundsForWithdrawalAndFee(s_availablePledgedAmount, withdrawalAmount, totalFee); + if(withdrawalAmount > s_availablePerToken[token]){ + revert KeepWhatsRaisedInsufficientFundsForWithdrawalAndFee(s_availablePerToken[token], withdrawalAmount, totalFee); } - if(withdrawalAmount < s_config.minimumWithdrawalForFeeExemption){ - s_platformFee += cumulativeFee; + if(withdrawalAmount < minimumWithdrawalForFeeExemption){ + s_platformFeePerToken[token] += cumulativeFee; totalFee += cumulativeFee; }else { - s_platformFee += flatFee; + s_platformFeePerToken[token] += flatFee; totalFee += flatFee; } } @@ -905,7 +957,7 @@ contract KeepWhatsRaised is uint256 denominator = 10040; uint256 columbianCreatorTax = numerator / (denominator * PERCENT_DIVIDER); - s_platformFee += columbianCreatorTax; + s_platformFeePerToken[token] += columbianCreatorTax; totalFee += columbianCreatorTax; } @@ -914,15 +966,15 @@ contract KeepWhatsRaised is revert KeepWhatsRaisedInsufficientFundsForFee(withdrawalAmount, totalFee); } - s_availablePledgedAmount = 0; - TOKEN.safeTransfer(recipient, withdrawalAmount - totalFee); + s_availablePerToken[token] = 0; + IERC20(token).safeTransfer(recipient, withdrawalAmount - totalFee); } else { - if(s_availablePledgedAmount < (withdrawalAmount + totalFee)) { - revert KeepWhatsRaisedInsufficientFundsForWithdrawalAndFee(s_availablePledgedAmount, withdrawalAmount, totalFee); + if(s_availablePerToken[token] < (withdrawalAmount + totalFee)) { + revert KeepWhatsRaisedInsufficientFundsForWithdrawalAndFee(s_availablePerToken[token], withdrawalAmount, totalFee); } - s_availablePledgedAmount -= (withdrawalAmount + totalFee); - TOKEN.safeTransfer(recipient, withdrawalAmount); + s_availablePerToken[token] -= (withdrawalAmount + totalFee); + IERC20(token).safeTransfer(recipient, withdrawalAmount); } emit WithdrawalWithFeeSuccessful(recipient, isFinalWithdrawal ? withdrawalAmount - totalFee : withdrawalAmount, totalFee); @@ -949,22 +1001,23 @@ contract KeepWhatsRaised is revert KeepWhatsRaisedNotClaimable(tokenId); } + address pledgeToken = s_tokenIdToPledgeToken[tokenId]; uint256 amountToRefund = s_tokenToPledgedAmount[tokenId]; - uint256 availablePledgedAmount = s_availablePledgedAmount; uint256 paymentFee = s_tokenToPaymentFee[tokenId]; uint256 netRefundAmount = amountToRefund - paymentFee; - if (netRefundAmount == 0 || availablePledgedAmount < netRefundAmount) { + if (netRefundAmount == 0 || s_availablePerToken[pledgeToken] < netRefundAmount) { revert KeepWhatsRaisedNotClaimable(tokenId); } + s_tokenToPledgedAmount[tokenId] = 0; - s_pledgedAmount -= amountToRefund; - s_availablePledgedAmount -= netRefundAmount; + s_tokenRaisedAmounts[pledgeToken] -= amountToRefund; + s_availablePerToken[pledgeToken] -= netRefundAmount; s_tokenToPaymentFee[tokenId] = 0; burn(tokenId); - TOKEN.safeTransfer(msg.sender, netRefundAmount); - emit RefundClaimed(tokenId, netRefundAmount, msg.sender); + IERC20(pledgeToken).safeTransfer(_msgSender(), netRefundAmount); + emit RefundClaimed(tokenId, netRefundAmount, _msgSender()); } /** @@ -979,18 +1032,30 @@ contract KeepWhatsRaised is whenNotPaused whenNotCancelled { - uint256 protocolShare = s_protocolFee; - uint256 platformShare = s_platformFee; - (s_protocolFee, s_platformFee) = (0, 0); - - TOKEN.safeTransfer(INFO.getProtocolAdminAddress(), protocolShare); - - TOKEN.safeTransfer( - INFO.getPlatformAdminAddress(PLATFORM_HASH), - platformShare - ); + address[] memory acceptedTokens = INFO.getAcceptedTokens(); + address protocolAdmin = INFO.getProtocolAdminAddress(); + address platformAdmin = INFO.getPlatformAdminAddress(PLATFORM_HASH); - emit FeesDisbursed(protocolShare, platformShare); + for (uint256 i = 0; i < acceptedTokens.length; i++) { + address token = acceptedTokens[i]; + uint256 protocolShare = s_protocolFeePerToken[token]; + uint256 platformShare = s_platformFeePerToken[token]; + + if (protocolShare > 0 || platformShare > 0) { + s_protocolFeePerToken[token] = 0; + s_platformFeePerToken[token] = 0; + + if (protocolShare > 0) { + IERC20(token).safeTransfer(protocolAdmin, protocolShare); + } + + if (platformShare > 0) { + IERC20(token).safeTransfer(platformAdmin, platformShare); + } + + emit FeesDisbursed(token, protocolShare, platformShare); + } + } } /** @@ -1015,16 +1080,19 @@ contract KeepWhatsRaised is } address platformAdmin = INFO.getPlatformAdminAddress(PLATFORM_HASH); - uint256 tip = s_tip; - s_tip = 0; + address[] memory acceptedTokens = INFO.getAcceptedTokens(); s_tipClaimed = true; - TOKEN.safeTransfer( - platformAdmin, - tip - ); - - emit TipClaimed(tip, platformAdmin); + for (uint256 i = 0; i < acceptedTokens.length; i++) { + address token = acceptedTokens[i]; + uint256 tip = s_tipPerToken[token]; + + if (tip > 0) { + s_tipPerToken[token] = 0; + IERC20(token).safeTransfer(platformAdmin, tip); + emit TipClaimed(tip, platformAdmin); + } + } } /** @@ -1053,16 +1121,19 @@ contract KeepWhatsRaised is } address platformAdmin = INFO.getPlatformAdminAddress(PLATFORM_HASH); - uint256 amountToClaim = s_availablePledgedAmount; - s_availablePledgedAmount = 0; + address[] memory acceptedTokens = INFO.getAcceptedTokens(); s_fundClaimed = true; - TOKEN.safeTransfer( - platformAdmin, - amountToClaim - ); - - emit FundClaimed(amountToClaim, platformAdmin); + for (uint256 i = 0; i < acceptedTokens.length; i++) { + address token = acceptedTokens[i]; + uint256 amountToClaim = s_availablePerToken[token]; + + if (amountToClaim > 0) { + s_availablePerToken[token] = 0; + IERC20(token).safeTransfer(platformAdmin, amountToClaim); + emit FundClaimed(amountToClaim, platformAdmin); + } + } } /** @@ -1090,6 +1161,7 @@ contract KeepWhatsRaised is function _pledge( bytes32 pledgeId, address backer, + address pledgeToken, bytes32 reward, uint256 pledgeAmount, uint256 tip, @@ -1097,24 +1169,44 @@ contract KeepWhatsRaised is bytes32[] memory rewards, address tokenSource ) private { - uint256 totalAmount = pledgeAmount + tip; + // Validate token is accepted + if (!INFO.isTokenAccepted(pledgeToken)) { + revert KeepWhatsRaisedTokenNotAccepted(pledgeToken); + } + + // If this is for a reward, pledgeAmount is in 18 decimals and needs to be denormalized + // If not for a reward (pledgeWithoutAReward), pledgeAmount is already in token decimals + // Tip is always in the pledgeToken's decimals (same token used for payment) + uint256 pledgeAmountInTokenDecimals; + if (reward != ZERO_BYTES) { + // Reward pledge: denormalize from 18 decimals to token decimals + pledgeAmountInTokenDecimals = _denormalizeAmount(pledgeToken, pledgeAmount); + } else { + // Non-reward pledge: already in token decimals + pledgeAmountInTokenDecimals = pledgeAmount; + } + + // Tip is already in token's decimals, no denormalization needed + uint256 totalAmount = pledgeAmountInTokenDecimals + tip; // Transfer tokens from tokenSource (either admin or backer) - TOKEN.safeTransferFrom(tokenSource, address(this), totalAmount); + IERC20(pledgeToken).safeTransferFrom(tokenSource, address(this), totalAmount); s_tokenIdCounter.increment(); - s_tokenToPledgedAmount[tokenId] = pledgeAmount; + s_tokenToPledgedAmount[tokenId] = pledgeAmountInTokenDecimals; s_tokenToTippedAmount[tokenId] = tip; - s_pledgedAmount += pledgeAmount; - s_tip += tip; + s_tokenIdToPledgeToken[tokenId] = pledgeToken; + s_tipPerToken[pledgeToken] += tip; + s_tokenRaisedAmounts[pledgeToken] += pledgeAmountInTokenDecimals; - //Fee Calculation - pledgeAmount = _calculateNetAvailable(pledgeId, tokenId, pledgeAmount); - s_availablePledgedAmount += pledgeAmount; + //Fee Calculation (uses token decimals) + uint256 netAvailable = _calculateNetAvailable(pledgeId, pledgeToken, tokenId, pledgeAmountInTokenDecimals); + s_availablePerToken[pledgeToken] += netAvailable; _safeMint(backer, tokenId, abi.encodePacked(backer, reward)); emit Receipt( backer, + pledgeToken, reward, pledgeAmount, tip, @@ -1131,36 +1223,38 @@ contract KeepWhatsRaised is * - Applies all configured gross percentage-based fees * - Applies payment gateway fee for the given pledge * - Applies protocol fee based on protocol configuration - * - Accumulates total platform and protocol fees + * - Accumulates total platform and protocol fees per token * - Records the total deducted fee for the token * * @param pledgeId The unique identifier of the pledge + * @param pledgeToken The token used for the pledge * @param tokenId The token ID representing the pledge * @param pledgeAmount The original pledged amount before deductions * * @return The net available amount after all fees are deducted */ - function _calculateNetAvailable(bytes32 pledgeId, uint256 tokenId, uint256 pledgeAmount) internal returns (uint256) { + function _calculateNetAvailable(bytes32 pledgeId, address pledgeToken, uint256 tokenId, uint256 pledgeAmount) internal returns (uint256) { uint256 totalFee = 0; - // Gross Percentage Fee Calculation + // Gross Percentage Fee Calculation (correct as-is) uint256 len = s_feeKeys.grossPercentageFeeKeys.length; for (uint256 i = 0; i < len; i++) { uint256 fee = (pledgeAmount * getFeeValue(s_feeKeys.grossPercentageFeeKeys[i])) / PERCENT_DIVIDER; - s_platformFee += fee; + s_platformFeePerToken[pledgeToken] += fee; totalFee += fee; } - //Payment Gateway Fee Calculation - uint256 paymentGatewayFee = getPaymentGatewayFee(pledgeId); - s_platformFee += paymentGatewayFee; + // Payment Gateway Fee Calculation - MUST DENORMALIZE + uint256 paymentGatewayFeeNormalized = getPaymentGatewayFee(pledgeId); + uint256 paymentGatewayFee = _denormalizeAmount(pledgeToken, paymentGatewayFeeNormalized); + s_platformFeePerToken[pledgeToken] += paymentGatewayFee; totalFee += paymentGatewayFee; - //Protocol Fee Calculation + // Protocol Fee Calculation (correct as-is) uint256 protocolFee = (pledgeAmount * INFO.getProtocolFeePercent()) / PERCENT_DIVIDER; - s_protocolFee += protocolFee; + s_protocolFeePerToken[pledgeToken] += protocolFee; totalFee += protocolFee; s_tokenToPaymentFee[tokenId] = totalFee; diff --git a/src/treasuries/PaymentTreasury.sol b/src/treasuries/PaymentTreasury.sol index 3c9d146c..b9211016 100644 --- a/src/treasuries/PaymentTreasury.sol +++ b/src/treasuries/PaymentTreasury.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; @@ -20,12 +20,7 @@ contract PaymentTreasury is error PaymentTreasuryUnAuthorized(); /** - * @dev Emitted when `disburseFees` after fee is disbursed already. - */ - error PaymentTreasuryFeeAlreadyDisbursed(); - - /** - * @dev Constructor for the AllOrNothing contract. + * @dev Constructor for the PaymentTreasury contract. */ constructor() {} @@ -55,10 +50,11 @@ contract PaymentTreasury is bytes32 paymentId, bytes32 buyerId, bytes32 itemId, + address paymentToken, uint256 amount, uint256 expiration ) public override whenNotPaused whenNotCancelled { - super.createPayment(paymentId, buyerId, itemId, amount, expiration); + super.createPayment(paymentId, buyerId, itemId, paymentToken, amount, expiration); } /** @@ -68,9 +64,10 @@ contract PaymentTreasury is bytes32 paymentId, bytes32 itemId, address buyerAddress, + address paymentToken, uint256 amount ) public override whenNotPaused whenNotCancelled { - super.processCryptoPayment(paymentId, itemId, buyerAddress, amount); + super.processCryptoPayment(paymentId, itemId, buyerAddress, paymentToken, amount); } /** @@ -144,8 +141,8 @@ contract PaymentTreasury is */ function cancelTreasury(bytes32 message) public override { if ( - msg.sender != INFO.getPlatformAdminAddress(PLATFORM_HASH) && - msg.sender != INFO.owner() + _msgSender() != INFO.getPlatformAdminAddress(PLATFORM_HASH) && + _msgSender() != INFO.owner() ) { revert PaymentTreasuryUnAuthorized(); } diff --git a/src/utils/AdminAccessChecker.sol b/src/utils/AdminAccessChecker.sol index 7c025282..ac0a5050 100644 --- a/src/utils/AdminAccessChecker.sol +++ b/src/utils/AdminAccessChecker.sol @@ -1,24 +1,38 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; +import {Context} from "@openzeppelin/contracts/utils/Context.sol"; import {IGlobalParams} from "../interfaces/IGlobalParams.sol"; +import {AdminAccessCheckerStorage} from "../storage/AdminAccessCheckerStorage.sol"; /** * @title AdminAccessChecker * @dev This abstract contract provides access control mechanisms to restrict the execution of specific functions * to authorized protocol administrators and platform administrators. + * @dev Updated to use ERC-7201 namespaced storage for upgradeable contracts */ -abstract contract AdminAccessChecker { - // Immutable reference to the IGlobalParams contract, which manages global parameters and admin addresses. - IGlobalParams internal GLOBAL_PARAMS; +abstract contract AdminAccessChecker is Context { /** * @dev Throws when the caller is not authorized. */ error AdminAccessCheckerUnauthorized(); + /** + * @dev Internal initializer function for AdminAccessChecker + * @param globalParams The IGlobalParams contract instance + */ function __AccessChecker_init(IGlobalParams globalParams) internal { - GLOBAL_PARAMS = globalParams; + AdminAccessCheckerStorage.Storage storage $ = AdminAccessCheckerStorage._getAdminAccessCheckerStorage(); + $.globalParams = globalParams; + } + + /** + * @dev Returns the stored GLOBAL_PARAMS for internal use + */ + function _getGlobalParams() internal view returns (IGlobalParams) { + AdminAccessCheckerStorage.Storage storage $ = AdminAccessCheckerStorage._getAdminAccessCheckerStorage(); + return $.globalParams; } /** @@ -45,7 +59,8 @@ abstract contract AdminAccessChecker { * If the sender is not the protocol admin, it reverts with AdminAccessCheckerUnauthorized error. */ function _onlyProtocolAdmin() private view { - if (msg.sender != GLOBAL_PARAMS.getProtocolAdminAddress()) { + AdminAccessCheckerStorage.Storage storage $ = AdminAccessCheckerStorage._getAdminAccessCheckerStorage(); + if (_msgSender() != $.globalParams.getProtocolAdminAddress()) { revert AdminAccessCheckerUnauthorized(); } } @@ -56,7 +71,8 @@ abstract contract AdminAccessChecker { * @param platformHash The unique identifier of the platform. */ function _onlyPlatformAdmin(bytes32 platformHash) private view { - if (msg.sender != GLOBAL_PARAMS.getPlatformAdminAddress(platformHash)) { + AdminAccessCheckerStorage.Storage storage $ = AdminAccessCheckerStorage._getAdminAccessCheckerStorage(); + if (_msgSender() != $.globalParams.getPlatformAdminAddress(platformHash)) { revert AdminAccessCheckerUnauthorized(); } } diff --git a/src/utils/BasePaymentTreasury.sol b/src/utils/BasePaymentTreasury.sol index e7a8e5d3..bf51ea48 100644 --- a/src/utils/BasePaymentTreasury.sol +++ b/src/utils/BasePaymentTreasury.sol @@ -1,7 +1,8 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; +import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol"; import {ICampaignPaymentTreasury} from "../interfaces/ICampaignPaymentTreasury.sol"; @@ -19,18 +20,22 @@ abstract contract BasePaymentTreasury is bytes32 internal constant ZERO_BYTES = 0x0000000000000000000000000000000000000000000000000000000000000000; uint256 internal constant PERCENT_DIVIDER = 10000; + uint256 internal constant STANDARD_DECIMALS = 18; bytes32 internal PLATFORM_HASH; uint256 internal PLATFORM_FEE_PERCENT; - IERC20 internal TOKEN; - uint256 internal s_platformFee; - uint256 internal s_protocolFee; + + // Multi-token support + mapping(bytes32 => address) internal s_paymentIdToToken; // Track token used for each payment + mapping(address => uint256) internal s_platformFeePerToken; // Platform fees per token + mapping(address => uint256) internal s_protocolFeePerToken; // Protocol fees per token + /** * @dev Stores information about a payment in the treasury. * @param buyerAddress The address of the buyer who made the payment. * @param buyerId The ID of the buyer. * @param itemId The identifier of the item being purchased. - * @param amount The amount to be paid for the item. + * @param amount The amount to be paid for the item (in token's native decimals). * @param expiration The timestamp after which the payment expires. * @param isConfirmed Boolean indicating whether the payment has been confirmed. * @param isCryptoPayment Boolean indicating whether the payment is made using direct crypto payment. @@ -46,9 +51,11 @@ abstract contract BasePaymentTreasury is } mapping (bytes32 => PaymentInfo) internal s_payment; - uint256 internal s_pendingPaymentAmount; - uint256 internal s_confirmedPaymentAmount; - uint256 internal s_availableConfirmedPaymentAmount; + + // Multi-token balances (all in token's native decimals) + mapping(address => uint256) internal s_pendingPaymentPerToken; // Pending payment amounts per token + mapping(address => uint256) internal s_confirmedPaymentPerToken; // Confirmed payment amounts per token + mapping(address => uint256) internal s_availableConfirmedPerToken; // Available confirmed amounts per token /** * @dev Emitted when a new payment is created. @@ -56,7 +63,8 @@ abstract contract BasePaymentTreasury is * @param paymentId The unique identifier of the payment. * @param buyerId The id of the buyer. * @param itemId The identifier of the item being purchased. - * @param amount The amount to be paid for the item. + * @param paymentToken The token used for the payment. + * @param amount The amount to be paid for the item (in token's native decimals). * @param expiration The timestamp after which the payment expires. * @param isCryptoPayment Boolean indicating whether the payment is made using direct crypto payment. */ @@ -65,6 +73,7 @@ abstract contract BasePaymentTreasury is bytes32 indexed paymentId, bytes32 buyerId, bytes32 indexed itemId, + address indexed paymentToken, uint256 amount, uint256 expiration, bool isCryptoPayment @@ -96,18 +105,20 @@ abstract contract BasePaymentTreasury is /** * @notice Emitted when fees are successfully disbursed. + * @param token The token in which fees were disbursed. * @param protocolShare The amount of fees sent to the protocol. * @param platformShare The amount of fees sent to the platform. */ - event FeesDisbursed(uint256 protocolShare, uint256 platformShare); + event FeesDisbursed(address indexed token, uint256 protocolShare, uint256 platformShare); /** * @dev Emitted when a withdrawal is successfully processed along with the applied fee. + * @param token The token that was withdrawn. * @param to The recipient address receiving the funds. * @param amount The total amount withdrawn (excluding fee). * @param fee The fee amount deducted from the withdrawal. */ - event WithdrawalWithFeeSuccessful(address indexed to, uint256 amount, uint256 fee); + event WithdrawalWithFeeSuccessful(address indexed token, address indexed to, uint256 amount, uint256 fee); /** * @dev Emitted when a refund is claimed. @@ -123,7 +134,7 @@ abstract contract BasePaymentTreasury is error PaymentTreasuryInvalidInput(); /** - * @dev Throws an error indicating that the payment id is already exist. + * @dev Throws an error indicating that the payment id already exists. */ error PaymentTreasuryPaymentAlreadyExist(bytes32 paymentId); @@ -138,7 +149,7 @@ abstract contract BasePaymentTreasury is error PaymentTreasuryPaymentAlreadyExpired(bytes32 paymentId); /** - * @dev Throws an error indicating that the payment id is not exist. + * @dev Throws an error indicating that the payment id does not exist. */ error PaymentTreasuryPaymentNotExist(bytes32 paymentId); @@ -147,6 +158,11 @@ abstract contract BasePaymentTreasury is */ error PaymentTreasuryCampaignInfoIsPaused(); + /** + * @dev Emitted when a token is not accepted for the campaign. + */ + error PaymentTreasuryTokenNotAccepted(address token); + /** * @dev Throws an error indicating that the success condition was not fulfilled. */ @@ -187,6 +203,9 @@ abstract contract BasePaymentTreasury is */ error PaymentTreasuryInsufficientFundsForFee(uint256 withdrawalAmount, uint256 fee); + /** + * @dev Emitted when there are insufficient unallocated tokens for a payment confirmation. + */ error PaymentTreasuryInsufficientBalance(uint256 required, uint256 available); function __BaseContract_init( @@ -195,7 +214,6 @@ abstract contract BasePaymentTreasury is ) internal { __CampaignAccessChecker_init(infoAddress); PLATFORM_HASH = platformHash; - TOKEN = IERC20(INFO.getTokenAddress()); PLATFORM_FEE_PERCENT = INFO.getPlatformFeePercent(platformHash); } @@ -221,8 +239,8 @@ abstract contract BasePaymentTreasury is address buyerAddress = payment.buyerAddress; if ( - msg.sender != buyerAddress && - msg.sender != INFO.getPlatformAdminAddress(PLATFORM_HASH) + _msgSender() != buyerAddress && + _msgSender() != INFO.getPlatformAdminAddress(PLATFORM_HASH) ) { revert PaymentTreasuryPaymentNotClaimable(paymentId); } @@ -247,14 +265,57 @@ abstract contract BasePaymentTreasury is * @inheritdoc ICampaignPaymentTreasury */ function getRaisedAmount() public view override virtual returns (uint256) { - return s_confirmedPaymentAmount; + address[] memory acceptedTokens = INFO.getAcceptedTokens(); + uint256 totalNormalized = 0; + + for (uint256 i = 0; i < acceptedTokens.length; i++) { + address token = acceptedTokens[i]; + uint256 amount = s_confirmedPaymentPerToken[token]; + if (amount > 0) { + totalNormalized += _normalizeAmount(token, amount); + } + } + + return totalNormalized; } /** * @inheritdoc ICampaignPaymentTreasury */ function getAvailableRaisedAmount() external view returns (uint256) { - return s_availableConfirmedPaymentAmount; + address[] memory acceptedTokens = INFO.getAcceptedTokens(); + uint256 totalNormalized = 0; + + for (uint256 i = 0; i < acceptedTokens.length; i++) { + address token = acceptedTokens[i]; + uint256 amount = s_availableConfirmedPerToken[token]; + if (amount > 0) { + totalNormalized += _normalizeAmount(token, amount); + } + } + + return totalNormalized; + } + + /** + * @dev Normalizes token amounts to 18 decimals for consistent comparisons. + * @param token The token address. + * @param amount The amount to normalize. + * @return The normalized amount (scaled to 18 decimals). + */ + function _normalizeAmount( + address token, + uint256 amount + ) internal view returns (uint256) { + uint8 decimals = IERC20Metadata(token).decimals(); + + if (decimals == STANDARD_DECIMALS) { + return amount; + } else if (decimals < STANDARD_DECIMALS) { + return amount * (10 ** (STANDARD_DECIMALS - decimals)); + } else { + return amount / (10 ** (decimals - STANDARD_DECIMALS)); + } } /** @@ -264,6 +325,7 @@ abstract contract BasePaymentTreasury is bytes32 paymentId, bytes32 buyerId, bytes32 itemId, + address paymentToken, uint256 amount, uint256 expiration ) public override virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { @@ -272,11 +334,17 @@ abstract contract BasePaymentTreasury is amount == 0 || expiration <= block.timestamp || paymentId == ZERO_BYTES || - itemId == ZERO_BYTES + itemId == ZERO_BYTES || + paymentToken == address(0) ){ revert PaymentTreasuryInvalidInput(); } + // Validate token is accepted + if (!INFO.isTokenAccepted(paymentToken)) { + revert PaymentTreasuryTokenNotAccepted(paymentToken); + } + if(s_payment[paymentId].buyerId != ZERO_BYTES || s_payment[paymentId].buyerAddress != address(0)){ revert PaymentTreasuryPaymentAlreadyExist(paymentId); } @@ -285,24 +353,25 @@ abstract contract BasePaymentTreasury is buyerId: buyerId, buyerAddress: address(0), itemId: itemId, - amount: amount, + amount: amount, // Amount in token's native decimals expiration: expiration, isConfirmed: false, isCryptoPayment: false }); - s_pendingPaymentAmount += amount; + s_paymentIdToToken[paymentId] = paymentToken; + s_pendingPaymentPerToken[paymentToken] += amount; emit PaymentCreated( address(0), paymentId, buyerId, itemId, + paymentToken, amount, expiration, false ); - } /** @@ -312,41 +381,50 @@ abstract contract BasePaymentTreasury is bytes32 paymentId, bytes32 itemId, address buyerAddress, + address paymentToken, uint256 amount ) public override virtual whenCampaignNotPaused whenCampaignNotCancelled { if(buyerAddress == address(0) || amount == 0 || paymentId == ZERO_BYTES || - itemId == ZERO_BYTES + itemId == ZERO_BYTES || + paymentToken == address(0) ){ revert PaymentTreasuryInvalidInput(); } + // Validate token is accepted + if (!INFO.isTokenAccepted(paymentToken)) { + revert PaymentTreasuryTokenNotAccepted(paymentToken); + } + if(s_payment[paymentId].buyerAddress != address(0) || s_payment[paymentId].buyerId != ZERO_BYTES){ revert PaymentTreasuryPaymentAlreadyExist(paymentId); } - TOKEN.safeTransferFrom(buyerAddress, address(this), amount); + IERC20(paymentToken).safeTransferFrom(buyerAddress, address(this), amount); s_payment[paymentId] = PaymentInfo({ buyerId: ZERO_BYTES, buyerAddress: buyerAddress, itemId: itemId, - amount: amount, + amount: amount, // Amount in token's native decimals expiration: 0, isConfirmed: true, isCryptoPayment: true }); - s_confirmedPaymentAmount += amount; - s_availableConfirmedPaymentAmount += amount; + s_paymentIdToToken[paymentId] = paymentToken; + s_confirmedPaymentPerToken[paymentToken] += amount; + s_availableConfirmedPerToken[paymentToken] += amount; emit PaymentCreated( buyerAddress, paymentId, ZERO_BYTES, itemId, + paymentToken, amount, 0, true @@ -362,14 +440,15 @@ abstract contract BasePaymentTreasury is _validatePaymentForAction(paymentId); + address paymentToken = s_paymentIdToToken[paymentId]; uint256 amount = s_payment[paymentId].amount; delete s_payment[paymentId]; + delete s_paymentIdToToken[paymentId]; - s_pendingPaymentAmount -= amount; + s_pendingPaymentPerToken[paymentToken] -= amount; emit PaymentCancelled(paymentId); - } /** @@ -380,11 +459,14 @@ abstract contract BasePaymentTreasury is ) public override virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { _validatePaymentForAction(paymentId); + address paymentToken = s_paymentIdToToken[paymentId]; uint256 paymentAmount = s_payment[paymentId].amount; // Check that we have enough unallocated tokens for this payment - uint256 actualBalance = TOKEN.balanceOf(address(this)); - uint256 currentlyCommitted = s_availableConfirmedPaymentAmount + s_protocolFee + s_platformFee; + uint256 actualBalance = IERC20(paymentToken).balanceOf(address(this)); + uint256 currentlyCommitted = s_availableConfirmedPerToken[paymentToken] + + s_protocolFeePerToken[paymentToken] + + s_platformFeePerToken[paymentToken]; if (currentlyCommitted + paymentAmount > actualBalance) { revert PaymentTreasuryInsufficientBalance( @@ -395,9 +477,9 @@ abstract contract BasePaymentTreasury is s_payment[paymentId].isConfirmed = true; - s_pendingPaymentAmount -= paymentAmount; - s_confirmedPaymentAmount += paymentAmount; - s_availableConfirmedPaymentAmount += paymentAmount; + s_pendingPaymentPerToken[paymentToken] -= paymentAmount; + s_confirmedPaymentPerToken[paymentToken] += paymentAmount; + s_availableConfirmedPerToken[paymentToken] += paymentAmount; emit PaymentConfirmed(paymentId); } @@ -408,17 +490,23 @@ abstract contract BasePaymentTreasury is function confirmPaymentBatch( bytes32[] calldata paymentIds ) public override virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { - uint256 actualBalance = TOKEN.balanceOf(address(this)); + bytes32 currentPaymentId; + address currentToken; for(uint256 i = 0; i < paymentIds.length;){ currentPaymentId = paymentIds[i]; + _validatePaymentForAction(currentPaymentId); + currentToken = s_paymentIdToToken[currentPaymentId]; uint256 amount = s_payment[currentPaymentId].amount; + uint256 actualBalance = IERC20(currentToken).balanceOf(address(this)); // Check if this confirmation would exceed balance - uint256 currentlyCommitted = s_availableConfirmedPaymentAmount + s_protocolFee + s_platformFee; + uint256 currentlyCommitted = s_availableConfirmedPerToken[currentToken] + + s_protocolFeePerToken[currentToken] + + s_platformFeePerToken[currentToken]; if (currentlyCommitted + amount > actualBalance) { revert PaymentTreasuryInsufficientBalance( @@ -428,9 +516,9 @@ abstract contract BasePaymentTreasury is } s_payment[currentPaymentId].isConfirmed = true; - s_pendingPaymentAmount -= amount; - s_confirmedPaymentAmount += amount; - s_availableConfirmedPaymentAmount += amount; + s_pendingPaymentPerToken[currentToken] -= amount; + s_confirmedPaymentPerToken[currentToken] += amount; + s_availableConfirmedPerToken[currentToken] += amount; unchecked { ++i; @@ -452,8 +540,9 @@ abstract contract BasePaymentTreasury is revert PaymentTreasuryInvalidInput(); } PaymentInfo memory payment = s_payment[paymentId]; + address paymentToken = s_paymentIdToToken[paymentId]; uint256 amountToRefund = payment.amount; - uint256 availablePaymentAmount = s_availableConfirmedPaymentAmount; + uint256 availablePaymentAmount = s_availableConfirmedPerToken[paymentToken]; if (payment.buyerId == ZERO_BYTES) { revert PaymentTreasuryPaymentNotExist(paymentId); @@ -466,11 +555,12 @@ abstract contract BasePaymentTreasury is } delete s_payment[paymentId]; + delete s_paymentIdToToken[paymentId]; - s_confirmedPaymentAmount -= amountToRefund; - s_availableConfirmedPaymentAmount -= amountToRefund; + s_confirmedPaymentPerToken[paymentToken] -= amountToRefund; + s_availableConfirmedPerToken[paymentToken] -= amountToRefund; - TOKEN.safeTransfer(refundAddress, amountToRefund); + IERC20(paymentToken).safeTransfer(refundAddress, amountToRefund); emit RefundClaimed(paymentId, amountToRefund, refundAddress); } @@ -482,9 +572,10 @@ abstract contract BasePaymentTreasury is ) public override virtual onlyBuyerOrPlatformAdmin(paymentId) whenCampaignNotPaused whenCampaignNotCancelled { PaymentInfo memory payment = s_payment[paymentId]; + address paymentToken = s_paymentIdToToken[paymentId]; address buyerAddress = payment.buyerAddress; uint256 amountToRefund = payment.amount; - uint256 availablePaymentAmount = s_availableConfirmedPaymentAmount; + uint256 availablePaymentAmount = s_availableConfirmedPerToken[paymentToken]; if (buyerAddress == address(0)) { revert PaymentTreasuryPaymentNotExist(paymentId); @@ -494,11 +585,12 @@ abstract contract BasePaymentTreasury is } delete s_payment[paymentId]; + delete s_paymentIdToToken[paymentId]; - s_confirmedPaymentAmount -= amountToRefund; - s_availableConfirmedPaymentAmount -= amountToRefund; + s_confirmedPaymentPerToken[paymentToken] -= amountToRefund; + s_availableConfirmedPerToken[paymentToken] -= amountToRefund; - TOKEN.safeTransfer(buyerAddress, amountToRefund); + IERC20(paymentToken).safeTransfer(buyerAddress, amountToRefund); emit RefundClaimed(paymentId, amountToRefund, buyerAddress); } @@ -512,18 +604,30 @@ abstract contract BasePaymentTreasury is whenCampaignNotPaused whenCampaignNotCancelled { - uint256 protocolShare = s_protocolFee; - uint256 platformShare = s_platformFee; - (s_protocolFee, s_platformFee) = (0, 0); + address[] memory acceptedTokens = INFO.getAcceptedTokens(); + address protocolAdmin = INFO.getProtocolAdminAddress(); + address platformAdmin = INFO.getPlatformAdminAddress(PLATFORM_HASH); - TOKEN.safeTransfer(INFO.getProtocolAdminAddress(), protocolShare); - - TOKEN.safeTransfer( - INFO.getPlatformAdminAddress(PLATFORM_HASH), - platformShare - ); - - emit FeesDisbursed(protocolShare, platformShare); + for (uint256 i = 0; i < acceptedTokens.length; i++) { + address token = acceptedTokens[i]; + uint256 protocolShare = s_protocolFeePerToken[token]; + uint256 platformShare = s_platformFeePerToken[token]; + + if (protocolShare > 0 || platformShare > 0) { + s_protocolFeePerToken[token] = 0; + s_platformFeePerToken[token] = 0; + + if (protocolShare > 0) { + IERC20(token).safeTransfer(protocolAdmin, protocolShare); + } + + if (platformShare > 0) { + IERC20(token).safeTransfer(platformAdmin, platformShare); + } + + emit FeesDisbursed(token, protocolShare, platformShare); + } + } } /** @@ -541,31 +645,45 @@ abstract contract BasePaymentTreasury is } address recipient = INFO.owner(); - uint256 balance = s_availableConfirmedPaymentAmount; - if (balance == 0) { - revert PaymentTreasuryAlreadyWithdrawn(); - } + address[] memory acceptedTokens = INFO.getAcceptedTokens(); + uint256 protocolFeePercent = INFO.getProtocolFeePercent(); + uint256 platformFeePercent = INFO.getPlatformFeePercent(PLATFORM_HASH); + + bool hasWithdrawn = false; + + for (uint256 i = 0; i < acceptedTokens.length; i++) { + address token = acceptedTokens[i]; + uint256 balance = s_availableConfirmedPerToken[token]; + + if (balance > 0) { + hasWithdrawn = true; + + // Calculate fees + uint256 protocolShare = (balance * protocolFeePercent) / PERCENT_DIVIDER; + uint256 platformShare = (balance * platformFeePercent) / PERCENT_DIVIDER; + + s_protocolFeePerToken[token] += protocolShare; + s_platformFeePerToken[token] += platformShare; - // Calculate fees - uint256 protocolShare = (balance * INFO.getProtocolFeePercent()) / PERCENT_DIVIDER; - uint256 platformShare = (balance * INFO.getPlatformFeePercent(PLATFORM_HASH)) / PERCENT_DIVIDER; + uint256 totalFee = protocolShare + platformShare; - s_protocolFee += protocolShare; - s_platformFee += platformShare; + if(balance < totalFee) { + revert PaymentTreasuryInsufficientFundsForFee(balance, totalFee); + } + uint256 withdrawalAmount = balance - totalFee; + + // Reset balance + s_availableConfirmedPerToken[token] = 0; - uint256 totalFee = protocolShare + platformShare; + IERC20(token).safeTransfer(recipient, withdrawalAmount); - if(balance < totalFee) { - revert PaymentTreasuryInsufficientFundsForFee(balance, totalFee); + emit WithdrawalWithFeeSuccessful(token, recipient, withdrawalAmount, totalFee); + } } - uint256 withdrawalAmount = balance - totalFee; - // Reset balance - s_availableConfirmedPaymentAmount = 0; - - TOKEN.safeTransfer(recipient, withdrawalAmount); - - emit WithdrawalWithFeeSuccessful(recipient, withdrawalAmount, totalFee); + if (!hasWithdrawn) { + revert PaymentTreasuryAlreadyWithdrawn(); + } } /** @@ -597,7 +715,7 @@ abstract contract BasePaymentTreasury is /** * @dev Internal function to check if the campaign is paused. - * If the campaign is paused, it reverts with TreasuryCampaignInfoIsPaused error. + * If the campaign is paused, it reverts with PaymentTreasuryCampaignInfoIsPaused error. */ function _revertIfCampaignPaused() internal view { if (INFO.paused()) { @@ -645,5 +763,4 @@ abstract contract BasePaymentTreasury is * @return Whether the success condition is met. */ function _checkSuccessCondition() internal view virtual returns (bool); - } \ No newline at end of file diff --git a/src/utils/BaseTreasury.sol b/src/utils/BaseTreasury.sol index f41f1572..74516cb8 100644 --- a/src/utils/BaseTreasury.sol +++ b/src/utils/BaseTreasury.sol @@ -1,7 +1,8 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; +import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol"; import {ICampaignTreasury} from "../interfaces/ICampaignTreasury.sol"; @@ -25,27 +26,31 @@ abstract contract BaseTreasury is bytes32 internal constant ZERO_BYTES = 0x0000000000000000000000000000000000000000000000000000000000000000; uint256 internal constant PERCENT_DIVIDER = 10000; + uint256 internal constant STANDARD_DECIMALS = 18; bytes32 internal PLATFORM_HASH; uint256 internal PLATFORM_FEE_PERCENT; - IERC20 internal TOKEN; - uint256 internal s_pledgedAmount; bool internal s_feesDisbursed; + + // Multi-token support + mapping(address => uint256) internal s_tokenRaisedAmounts; // Amount raised per token /** - * @notice Emitted when fees are successfully disbursed. + * @notice Emitted when fees are successfully disbursed for a specific token. + * @param token The token address. * @param protocolShare The amount of fees sent to the protocol. * @param platformShare The amount of fees sent to the platform. */ - event FeesDisbursed(uint256 protocolShare, uint256 platformShare); + event FeesDisbursed(address indexed token, uint256 protocolShare, uint256 platformShare); /** - * @notice Emitted when a withdrawal is successful. + * @notice Emitted when a withdrawal is successful for a specific token. + * @param token The token address. * @param to The recipient of the withdrawal. * @param amount The amount withdrawn. */ - event WithdrawalSuccessful(address to, uint256 amount); + event WithdrawalSuccessful(address indexed token, address to, uint256 amount); /** * @notice Emitted when the success condition is not fulfilled during fee disbursement. @@ -78,7 +83,6 @@ abstract contract BaseTreasury is ) internal { __CampaignAccessChecker_init(infoAddress); PLATFORM_HASH = platformHash; - TOKEN = IERC20(INFO.getTokenAddress()); PLATFORM_FEE_PERCENT = INFO.getPlatformFeePercent(platformHash); } @@ -109,6 +113,52 @@ abstract contract BaseTreasury is return PLATFORM_FEE_PERCENT; } + /** + * @dev Normalizes token amount to 18 decimals for consistent comparison. + * @param token The token address to normalize. + * @param amount The amount to normalize. + * @return The normalized amount in 18 decimals. + */ + function _normalizeAmount( + address token, + uint256 amount + ) internal view returns (uint256) { + uint8 decimals = IERC20Metadata(token).decimals(); + + if (decimals == STANDARD_DECIMALS) { + return amount; + } else if (decimals < STANDARD_DECIMALS) { + // Scale up for tokens with fewer decimals + return amount * (10 ** (STANDARD_DECIMALS - decimals)); + } else { + // Scale down for tokens with more decimals (rare but possible) + return amount / (10 ** (decimals - STANDARD_DECIMALS)); + } + } + + /** + * @dev Denormalizes an amount from 18 decimals to the token's actual decimals. + * @param token The token address to denormalize for. + * @param amount The amount in 18 decimals to denormalize. + * @return The denormalized amount in token's native decimals. + */ + function _denormalizeAmount( + address token, + uint256 amount + ) internal view returns (uint256) { + uint8 decimals = IERC20Metadata(token).decimals(); + + if (decimals == STANDARD_DECIMALS) { + return amount; + } else if (decimals < STANDARD_DECIMALS) { + // Scale down for tokens with fewer decimals (e.g., USDC 6 decimals) + return amount / (10 ** (STANDARD_DECIMALS - decimals)); + } else { + // Scale up for tokens with more decimals (rare but possible) + return amount * (10 ** (decimals - STANDARD_DECIMALS)); + } + } + /** * @inheritdoc ICampaignTreasury */ @@ -122,20 +172,34 @@ abstract contract BaseTreasury is if (!_checkSuccessCondition()) { revert TreasurySuccessConditionNotFulfilled(); } - uint256 balance = s_pledgedAmount; - uint256 protocolShare = (balance * INFO.getProtocolFeePercent()) / - PERCENT_DIVIDER; - uint256 platformShare = (balance * - INFO.getPlatformFeePercent(PLATFORM_HASH)) / PERCENT_DIVIDER; - TOKEN.safeTransfer(INFO.getProtocolAdminAddress(), protocolShare); - - TOKEN.safeTransfer( - INFO.getPlatformAdminAddress(PLATFORM_HASH), - platformShare - ); - + + address[] memory acceptedTokens = INFO.getAcceptedTokens(); + + // Disburse fees for each token + for (uint256 i = 0; i < acceptedTokens.length; i++) { + address token = acceptedTokens[i]; + uint256 balance = s_tokenRaisedAmounts[token]; + + if (balance > 0) { + uint256 protocolShare = (balance * INFO.getProtocolFeePercent()) / PERCENT_DIVIDER; + uint256 platformShare = (balance * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; + + if (protocolShare > 0) { + IERC20(token).safeTransfer(INFO.getProtocolAdminAddress(), protocolShare); + } + + if (platformShare > 0) { + IERC20(token).safeTransfer( + INFO.getPlatformAdminAddress(PLATFORM_HASH), + platformShare + ); + } + + emit FeesDisbursed(token, protocolShare, platformShare); + } + } + s_feesDisbursed = true; - emit FeesDisbursed(protocolShare, platformShare); } /** @@ -151,11 +215,20 @@ abstract contract BaseTreasury is if (!s_feesDisbursed) { revert TreasuryFeeNotDisbursed(); } - uint256 balance = TOKEN.balanceOf(address(this)); + + address[] memory acceptedTokens = INFO.getAcceptedTokens(); address recipient = INFO.owner(); - TOKEN.safeTransfer(recipient, balance); - - emit WithdrawalSuccessful(recipient, balance); + + // Withdraw remaining balance for each token + for (uint256 i = 0; i < acceptedTokens.length; i++) { + address token = acceptedTokens[i]; + uint256 balance = IERC20(token).balanceOf(address(this)); + + if (balance > 0) { + IERC20(token).safeTransfer(recipient, balance); + emit WithdrawalSuccessful(token, recipient, balance); + } + } } /** diff --git a/src/utils/CampaignAccessChecker.sol b/src/utils/CampaignAccessChecker.sol index 060cca68..7f8cc25f 100644 --- a/src/utils/CampaignAccessChecker.sol +++ b/src/utils/CampaignAccessChecker.sol @@ -1,6 +1,7 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; +import {Context} from "@openzeppelin/contracts/utils/Context.sol"; import {ICampaignInfo} from "../interfaces/ICampaignInfo.sol"; import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol"; @@ -9,7 +10,7 @@ import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.s * @dev This abstract contract provides access control mechanisms to restrict the execution of specific functions * to authorized protocol administrators, platform administrators, and campaign owners. */ -abstract contract CampaignAccessChecker { +abstract contract CampaignAccessChecker is Context { // Immutable reference to the ICampaignInfo contract, which provides campaign-related information and admin addresses. ICampaignInfo internal INFO; @@ -59,7 +60,7 @@ abstract contract CampaignAccessChecker { * If the sender is not the protocol admin, it reverts with AccessCheckerUnauthorized error. */ function _onlyProtocolAdmin() private view { - if (msg.sender != INFO.getProtocolAdminAddress()) { + if (_msgSender() != INFO.getProtocolAdminAddress()) { revert AccessCheckerUnauthorized(); } } @@ -70,7 +71,7 @@ abstract contract CampaignAccessChecker { * @param platformHash The unique identifier of the platform. */ function _onlyPlatformAdmin(bytes32 platformHash) private view { - if (msg.sender != INFO.getPlatformAdminAddress(platformHash)) { + if (_msgSender() != INFO.getPlatformAdminAddress(platformHash)) { revert AccessCheckerUnauthorized(); } } @@ -80,7 +81,7 @@ abstract contract CampaignAccessChecker { * If the sender is not the owner, it reverts with AccessCheckerUnauthorized error. */ function _onlyCampaignOwner() private view { - if (INFO.owner() != msg.sender) { + if (INFO.owner() != _msgSender()) { revert AccessCheckerUnauthorized(); } } diff --git a/src/utils/Counters.sol b/src/utils/Counters.sol index cacf1388..549f2f36 100644 --- a/src/utils/Counters.sol +++ b/src/utils/Counters.sol @@ -7,7 +7,7 @@ // The updates in this version are to ensure compatibility with Solidity v0.8.20 and to be consistent in style of other contracts used in this repository. -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; library Counters { /** diff --git a/src/utils/FiatEnabled.sol b/src/utils/FiatEnabled.sol index 85d98f62..fef6fb0c 100644 --- a/src/utils/FiatEnabled.sol +++ b/src/utils/FiatEnabled.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; /** * @title FiatEnabled diff --git a/src/utils/ItemRegistry.sol b/src/utils/ItemRegistry.sol index 0e6f4282..e8ee582c 100644 --- a/src/utils/ItemRegistry.sol +++ b/src/utils/ItemRegistry.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import {Context} from "@openzeppelin/contracts/utils/Context.sol"; diff --git a/src/utils/PausableCancellable.sol b/src/utils/PausableCancellable.sol index db0994d0..ee79d7e5 100644 --- a/src/utils/PausableCancellable.sol +++ b/src/utils/PausableCancellable.sol @@ -1,9 +1,11 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; + +import {Context} from "@openzeppelin/contracts/utils/Context.sol"; /// @title PausableCancellable /// @notice Abstract contract providing pause and cancel state management with events and modifiers -abstract contract PausableCancellable { +abstract contract PausableCancellable is Context { bool private _paused; bool private _cancelled; @@ -102,7 +104,7 @@ abstract contract PausableCancellable { bytes32 reason ) internal virtual whenNotPaused whenNotCancelled { _paused = true; - emit Paused(msg.sender, reason); + emit Paused(_msgSender(), reason); } /** @@ -112,7 +114,7 @@ abstract contract PausableCancellable { */ function _unpause(bytes32 reason) internal virtual whenPaused { _paused = false; - emit Unpaused(msg.sender, reason); + emit Unpaused(_msgSender(), reason); } /** @@ -129,6 +131,6 @@ abstract contract PausableCancellable { ); } _cancelled = true; - emit Cancelled(msg.sender, reason); + emit Cancelled(_msgSender(), reason); } } diff --git a/src/utils/TimestampChecker.sol b/src/utils/TimestampChecker.sol index 7ae687f7..3a697448 100644 --- a/src/utils/TimestampChecker.sol +++ b/src/utils/TimestampChecker.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; /** * @title TimestampChecker diff --git a/test/foundry/Base.t.sol b/test/foundry/Base.t.sol index d7373a06..4ab89305 100644 --- a/test/foundry/Base.t.sol +++ b/test/foundry/Base.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import "forge-std/Test.sol"; import {Users} from "./utils/Types.sol"; @@ -11,14 +11,22 @@ import {CampaignInfo} from "src/CampaignInfo.sol"; import {TreasuryFactory} from "src/TreasuryFactory.sol"; import {AllOrNothing} from "src/treasuries/AllOrNothing.sol"; import {KeepWhatsRaised} from "src/treasuries/KeepWhatsRaised.sol"; +import {IGlobalParams} from "src/interfaces/IGlobalParams.sol"; +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; /// @notice Base test contract with common logic needed by all tests. abstract contract Base_Test is Test, Defaults { //Variables Users internal users; - //Test Contracts + //Test Contracts - Multiple tokens for multi-token testing + TestToken internal usdtToken; // 6 decimals - Tether + TestToken internal usdcToken; // 6 decimals - USD Coin + TestToken internal cUSDToken; // 18 decimals - Celo Dollar + + // Legacy support - points to cUSDToken for backward compatibility TestToken internal testToken; + GlobalParams internal globalParams; CampaignInfoFactory internal campaignInfoFactory; TreasuryFactory internal treasuryFactory; @@ -41,38 +49,99 @@ abstract contract Base_Test is Test, Defaults { vm.startPrank(users.contractOwner); - // Deploy the base test contracts. - testToken = new TestToken(tokenName, tokenSymbol); - globalParams = new GlobalParams( + // Deploy multiple test tokens with different decimals + usdtToken = new TestToken("Tether USD", "USDT", 6); + usdcToken = new TestToken("USD Coin", "USDC", 6); + cUSDToken = new TestToken("Celo Dollar", "cUSD", 18); + + // Backward compatibility + testToken = cUSDToken; + + // Setup currencies and tokens for multi-token support + bytes32[] memory currencies = new bytes32[](1); + currencies[0] = bytes32("USD"); + + address[][] memory tokensPerCurrency = new address[][](1); + tokensPerCurrency[0] = new address[](3); + tokensPerCurrency[0][0] = address(usdtToken); + tokensPerCurrency[0][1] = address(usdcToken); + tokensPerCurrency[0][2] = address(cUSDToken); + + // Deploy GlobalParams with UUPS proxy + GlobalParams globalParamsImpl = new GlobalParams(); + bytes memory globalParamsInitData = abi.encodeWithSelector( + GlobalParams.initialize.selector, users.protocolAdminAddress, - address(testToken), - PROTOCOL_FEE_PERCENT + PROTOCOL_FEE_PERCENT, + currencies, + tokensPerCurrency ); + ERC1967Proxy globalParamsProxy = new ERC1967Proxy( + address(globalParamsImpl), + globalParamsInitData + ); + globalParams = GlobalParams(address(globalParamsProxy)); - campaignInfo = new CampaignInfo(address(this)); + // Deploy CampaignInfo implementation + campaignInfo = new CampaignInfo(); console.log("CampaignInfo address: ", address(campaignInfo)); - campaignInfoFactory = new CampaignInfoFactory( - globalParams, - address(campaignInfo) + + // Deploy TreasuryFactory with UUPS proxy + TreasuryFactory treasuryFactoryImpl = new TreasuryFactory(); + bytes memory treasuryFactoryInitData = abi.encodeWithSelector( + TreasuryFactory.initialize.selector, + IGlobalParams(address(globalParams)) + ); + ERC1967Proxy treasuryFactoryProxy = new ERC1967Proxy( + address(treasuryFactoryImpl), + treasuryFactoryInitData ); - treasuryFactory = new TreasuryFactory(globalParams); + treasuryFactory = TreasuryFactory(address(treasuryFactoryProxy)); - //Initialize campaignInfoFactory - campaignInfoFactory._initialize( - address(treasuryFactory), - address(globalParams) + // Deploy CampaignInfoFactory with UUPS proxy + CampaignInfoFactory campaignFactoryImpl = new CampaignInfoFactory(); + bytes memory campaignFactoryInitData = abi.encodeWithSelector( + CampaignInfoFactory.initialize.selector, + users.contractOwner, + IGlobalParams(address(globalParams)), + address(campaignInfo), + address(treasuryFactory) ); + ERC1967Proxy campaignFactoryProxy = new ERC1967Proxy( + address(campaignFactoryImpl), + campaignFactoryInitData + ); + campaignInfoFactory = CampaignInfoFactory(address(campaignFactoryProxy)); allOrNothingImplementation = new AllOrNothing(); keepWhatsRaisedImplementation = new KeepWhatsRaised(); - //Mint token to the backer - testToken.mint(users.backer1Address, TOKEN_MINT_AMOUNT); - testToken.mint(users.backer2Address, TOKEN_MINT_AMOUNT); + + //Mint tokens to backers - all three token types + usdtToken.mint(users.backer1Address, TOKEN_MINT_AMOUNT / 1e12); // Adjust for 6 decimals + usdtToken.mint(users.backer2Address, TOKEN_MINT_AMOUNT / 1e12); + + usdcToken.mint(users.backer1Address, TOKEN_MINT_AMOUNT / 1e12); + usdcToken.mint(users.backer2Address, TOKEN_MINT_AMOUNT / 1e12); + + cUSDToken.mint(users.backer1Address, TOKEN_MINT_AMOUNT); + cUSDToken.mint(users.backer2Address, TOKEN_MINT_AMOUNT); + + // Also mint to platform admins for setFeeAndPledge tests + usdtToken.mint(users.platform1AdminAddress, TOKEN_MINT_AMOUNT / 1e12); + usdcToken.mint(users.platform1AdminAddress, TOKEN_MINT_AMOUNT / 1e12); + cUSDToken.mint(users.platform1AdminAddress, TOKEN_MINT_AMOUNT); + + usdtToken.mint(users.platform2AdminAddress, TOKEN_MINT_AMOUNT / 1e12); + usdcToken.mint(users.platform2AdminAddress, TOKEN_MINT_AMOUNT / 1e12); + cUSDToken.mint(users.platform2AdminAddress, TOKEN_MINT_AMOUNT); vm.stopPrank(); // Label the base test contracts. - vm.label({account: address(testToken), newLabel: "TestToken"}); + vm.label({account: address(usdtToken), newLabel: "USDT"}); + vm.label({account: address(usdcToken), newLabel: "USDC"}); + vm.label({account: address(cUSDToken), newLabel: "cUSD"}); + vm.label({account: address(testToken), newLabel: "TestToken(cUSD)"}); vm.label({ account: address(globalParams), newLabel: "Global Parameter" @@ -96,4 +165,12 @@ abstract contract Base_Test is Test, Defaults { vm.deal({account: user, newBalance: 100 ether}); return user; } + + /// @dev Helper to get token amount adjusted for decimals + function getTokenAmount(address token, uint256 baseAmount) internal view returns (uint256) { + if (token == address(usdtToken) || token == address(usdcToken)) { + return baseAmount / 1e12; // Convert 18 decimal amount to 6 decimal + } + return baseAmount; // 18 decimals (cUSD) + } } \ No newline at end of file diff --git a/test/foundry/integration/AllOrNothing/AllOrNothing.t.sol b/test/foundry/integration/AllOrNothing/AllOrNothing.t.sol index 0cc2dce3..5e9e9964 100644 --- a/test/foundry/integration/AllOrNothing/AllOrNothing.t.sol +++ b/test/foundry/integration/AllOrNothing/AllOrNothing.t.sol @@ -182,22 +182,24 @@ abstract contract AllOrNothing_Integration_Shared_Test is AllOrNothing(allOrNothingAddress).pledgeForAReward( caller, + address(token), shippingFee, reward ); logs = vm.getRecordedLogs(); - bytes memory data = decodeEventFromLogs( + (bytes32[] memory topics, bytes memory data) = decodeTopicsAndData( logs, - "Receipt(address,bytes32,uint256,uint256,uint256,bytes32[])", + "Receipt(address,address,bytes32,uint256,uint256,uint256,bytes32[])", allOrNothingAddress ); - // (, tokenId, rewards) = abi.decode(data, (uint256, uint256, bytes32[])); - (, , tokenId, rewards) = abi.decode( + // Indexed params: backer (topics[1]), pledgeToken (topics[2]) + // Data params: reward, pledgeAmount, shippingFee, tokenId, rewards + (, , , tokenId, rewards) = abi.decode( data, - (uint256, uint256, uint256, bytes32[]) + (bytes32, uint256, uint256, uint256, bytes32[]) ); vm.stopPrank(); @@ -221,21 +223,24 @@ abstract contract AllOrNothing_Integration_Shared_Test is AllOrNothing(allOrNothingAddress).pledgeWithoutAReward( caller, + address(token), pledgeAmount ); logs = vm.getRecordedLogs(); // Decode receipt event if available - bytes memory data = decodeEventFromLogs( + (bytes32[] memory topics, bytes memory data) = decodeTopicsAndData( logs, - "Receipt(address,bytes32,uint256,uint256,uint256,bytes32[])", + "Receipt(address,address,bytes32,uint256,uint256,uint256,bytes32[])", allOrNothingAddress ); - (, , tokenId, ) = abi.decode( + // Indexed params: backer (topics[1]), pledgeToken (topics[2]) + // Data params: reward, pledgeAmount, shippingFee, tokenId, rewards + (, , , tokenId, ) = abi.decode( data, - (uint256, uint256, uint256, bytes32[]) + (bytes32, uint256, uint256, uint256, bytes32[]) ); vm.stopPrank(); } @@ -300,12 +305,13 @@ abstract contract AllOrNothing_Integration_Shared_Test is logs = vm.getRecordedLogs(); - bytes memory data = decodeEventFromLogs( + (bytes32[] memory topics, bytes memory data) = decodeTopicsAndData( logs, - "FeesDisbursed(uint256,uint256)", + "FeesDisbursed(address,uint256,uint256)", allOrNothingAddress ); + // topics[1] is the indexed token (protocolShare, platformShare) = abi.decode(data, (uint256, uint256)); } @@ -327,12 +333,13 @@ abstract contract AllOrNothing_Integration_Shared_Test is logs = vm.getRecordedLogs(); // Decode the data from the logs - bytes memory data = decodeEventFromLogs( + (bytes32[] memory topics, bytes memory data) = decodeTopicsAndData( logs, - "WithdrawalSuccessful(address,uint256)", + "WithdrawalSuccessful(address,address,uint256)", allOrNothingAddress ); + // topics[1] is the indexed token // Decode the amount and the address of the receiver (to, amount) = abi.decode(data, (address, uint256)); diff --git a/test/foundry/integration/AllOrNothing/AllOrNothingFunction.t.sol b/test/foundry/integration/AllOrNothing/AllOrNothingFunction.t.sol index 26101269..7089b5e4 100644 --- a/test/foundry/integration/AllOrNothing/AllOrNothingFunction.t.sol +++ b/test/foundry/integration/AllOrNothing/AllOrNothingFunction.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import "./AllOrNothing.t.sol"; import "forge-std/console.sol"; @@ -9,6 +9,7 @@ import {Defaults} from "../../utils/Defaults.sol"; import {Constants} from "../../utils/Constants.sol"; import {Users} from "../../utils/Types.sol"; import {IReward} from "src/interfaces/IReward.sol"; +import {TestToken} from "../../../mocks/TestToken.sol"; contract AllOrNothingFunction_Integration_Shared_Test is AllOrNothing_Integration_Shared_Test @@ -218,4 +219,316 @@ contract AllOrNothingFunction_Integration_Shared_Test is ); assertEq(amount, expectedAmount, "Incorrect withdrawal amount"); } + + /*////////////////////////////////////////////////////////////// + MULTI-TOKEN FUNCTIONALITY TESTS + //////////////////////////////////////////////////////////////*/ + + function test_pledgeWithMultipleTokens() external { + addRewards( + users.creator1Address, + address(allOrNothing), + REWARD_NAMES, + REWARDS + ); + + // Pledge with USDC (6 decimals) + uint256 usdcPledgeAmount = getTokenAmount(address(usdcToken), PLEDGE_AMOUNT); + uint256 usdcShippingFee = getTokenAmount(address(usdcToken), SHIPPING_FEE); + + vm.startPrank(users.backer1Address); + usdcToken.approve(address(allOrNothing), usdcPledgeAmount + usdcShippingFee); + vm.warp(LAUNCH_TIME); + + bytes32[] memory reward1 = new bytes32[](1); + reward1[0] = REWARD_NAME_1_HASH; + allOrNothing.pledgeForAReward( + users.backer1Address, + address(usdcToken), + usdcShippingFee, + reward1 + ); + vm.stopPrank(); + + // Pledge with cUSD (18 decimals) - no conversion needed + vm.startPrank(users.backer2Address); + cUSDToken.approve(address(allOrNothing), PLEDGE_AMOUNT); + allOrNothing.pledgeWithoutAReward( + users.backer2Address, + address(cUSDToken), + PLEDGE_AMOUNT + ); + vm.stopPrank(); + + // Verify balances + assertEq(usdcToken.balanceOf(address(allOrNothing)), usdcPledgeAmount + usdcShippingFee); + assertEq(cUSDToken.balanceOf(address(allOrNothing)), PLEDGE_AMOUNT); + + // Verify normalized raised amount + uint256 totalRaised = allOrNothing.getRaisedAmount(); + assertEq(totalRaised, PLEDGE_AMOUNT * 2, "Total raised should be sum of normalized amounts"); + } + + function test_getRaisedAmountNormalizesCorrectly() external { + addRewards( + users.creator1Address, + address(allOrNothing), + REWARD_NAMES, + REWARDS + ); + + // Pledge same base amount in different tokens + uint256 baseAmount = 1000e18; + + // USDC pledge (6 decimals) + uint256 usdcAmount = baseAmount / 1e12; + vm.startPrank(users.backer1Address); + usdcToken.approve(address(allOrNothing), usdcAmount); + vm.warp(LAUNCH_TIME); + allOrNothing.pledgeWithoutAReward( + users.backer1Address, + address(usdcToken), + usdcAmount + ); + vm.stopPrank(); + + uint256 raisedAfterUSDC = allOrNothing.getRaisedAmount(); + assertEq(raisedAfterUSDC, baseAmount, "USDC amount should be normalized to 18 decimals"); + + // cUSD pledge (18 decimals) + vm.startPrank(users.backer2Address); + cUSDToken.approve(address(allOrNothing), baseAmount); + allOrNothing.pledgeWithoutAReward( + users.backer2Address, + address(cUSDToken), + baseAmount + ); + vm.stopPrank(); + + uint256 raisedAfterCUSD = allOrNothing.getRaisedAmount(); + assertEq(raisedAfterCUSD, baseAmount * 2, "Total should be sum of normalized amounts"); + } + + function test_disburseFeesWithMultipleTokens() external { + addRewards( + users.creator1Address, + address(allOrNothing), + REWARD_NAMES, + REWARDS + ); + + // Pledge with USDC + uint256 usdcAmount = getTokenAmount(address(usdcToken), PLEDGE_AMOUNT); + vm.startPrank(users.backer1Address); + usdcToken.approve(address(allOrNothing), usdcAmount); + vm.warp(LAUNCH_TIME); + allOrNothing.pledgeWithoutAReward( + users.backer1Address, + address(usdcToken), + usdcAmount + ); + vm.stopPrank(); + + // Pledge with cUSD to meet goal + vm.startPrank(users.backer2Address); + cUSDToken.approve(address(allOrNothing), GOAL_AMOUNT); + allOrNothing.pledgeWithoutAReward( + users.backer2Address, + address(cUSDToken), + GOAL_AMOUNT + ); + vm.stopPrank(); + + uint256 protocolBalanceUSDCBefore = usdcToken.balanceOf(users.protocolAdminAddress); + uint256 platformBalanceUSDCBefore = usdcToken.balanceOf(users.platform1AdminAddress); + uint256 protocolBalanceCUSDBefore = cUSDToken.balanceOf(users.protocolAdminAddress); + uint256 platformBalanceCUSDBefore = cUSDToken.balanceOf(users.platform1AdminAddress); + + // Disburse fees + vm.warp(DEADLINE + 1 days); + allOrNothing.disburseFees(); + + // Verify USDC fees + uint256 expectedUSDCProtocolFee = (usdcAmount * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 expectedUSDCPlatformFee = (usdcAmount * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; + + assertEq( + usdcToken.balanceOf(users.protocolAdminAddress) - protocolBalanceUSDCBefore, + expectedUSDCProtocolFee, + "Incorrect USDC protocol fee" + ); + assertEq( + usdcToken.balanceOf(users.platform1AdminAddress) - platformBalanceUSDCBefore, + expectedUSDCPlatformFee, + "Incorrect USDC platform fee" + ); + + // Verify cUSD fees + uint256 expectedCUSDProtocolFee = (GOAL_AMOUNT * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 expectedCUSDPlatformFee = (GOAL_AMOUNT * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; + + assertEq( + cUSDToken.balanceOf(users.protocolAdminAddress) - protocolBalanceCUSDBefore, + expectedCUSDProtocolFee, + "Incorrect cUSD protocol fee" + ); + assertEq( + cUSDToken.balanceOf(users.platform1AdminAddress) - platformBalanceCUSDBefore, + expectedCUSDPlatformFee, + "Incorrect cUSD platform fee" + ); + } + + function test_withdrawWithMultipleTokens() external { + addRewards( + users.creator1Address, + address(allOrNothing), + REWARD_NAMES, + REWARDS + ); + + // Pledge with multiple tokens + uint256 usdcAmount = getTokenAmount(address(usdcToken), PLEDGE_AMOUNT); + uint256 usdtAmount = getTokenAmount(address(usdtToken), PLEDGE_AMOUNT); + + vm.startPrank(users.backer1Address); + usdcToken.approve(address(allOrNothing), usdcAmount); + vm.warp(LAUNCH_TIME); + allOrNothing.pledgeWithoutAReward( + users.backer1Address, + address(usdcToken), + usdcAmount + ); + vm.stopPrank(); + + vm.startPrank(users.backer2Address); + usdtToken.approve(address(allOrNothing), usdtAmount); + allOrNothing.pledgeWithoutAReward( + users.backer2Address, + address(usdtToken), + usdtAmount + ); + vm.stopPrank(); + + // Need cUSD pledge to meet goal + vm.startPrank(users.backer1Address); + cUSDToken.approve(address(allOrNothing), GOAL_AMOUNT); + allOrNothing.pledgeWithoutAReward( + users.backer1Address, + address(cUSDToken), + GOAL_AMOUNT + ); + vm.stopPrank(); + + // Disburse fees and withdraw + vm.warp(DEADLINE + 1 days); + allOrNothing.disburseFees(); + + uint256 creatorUSDCBefore = usdcToken.balanceOf(users.creator1Address); + uint256 creatorUSDTBefore = usdtToken.balanceOf(users.creator1Address); + uint256 creatorCUSDBefore = cUSDToken.balanceOf(users.creator1Address); + + allOrNothing.withdraw(); + + // Verify all tokens were withdrawn + assertTrue(usdcToken.balanceOf(users.creator1Address) > creatorUSDCBefore, "Creator should receive USDC"); + assertTrue(usdtToken.balanceOf(users.creator1Address) > creatorUSDTBefore, "Creator should receive USDT"); + assertTrue(cUSDToken.balanceOf(users.creator1Address) > creatorCUSDBefore, "Creator should receive cUSD"); + + // Verify treasury is empty + assertEq(usdcToken.balanceOf(address(allOrNothing)), 0, "USDC should be fully withdrawn"); + assertEq(usdtToken.balanceOf(address(allOrNothing)), 0, "USDT should be fully withdrawn"); + assertEq(cUSDToken.balanceOf(address(allOrNothing)), 0, "cUSD should be fully withdrawn"); + } + + function test_refundWithCorrectToken() external { + addRewards( + users.creator1Address, + address(allOrNothing), + REWARD_NAMES, + REWARDS + ); + + // Backer1 pledges with USDC + uint256 usdcAmount = getTokenAmount(address(usdcToken), PLEDGE_AMOUNT); + vm.startPrank(users.backer1Address); + usdcToken.approve(address(allOrNothing), usdcAmount); + vm.warp(LAUNCH_TIME); + allOrNothing.pledgeWithoutAReward( + users.backer1Address, + address(usdcToken), + usdcAmount + ); + uint256 usdcTokenId = 0; + vm.stopPrank(); + + // Backer2 pledges with cUSD + vm.startPrank(users.backer2Address); + cUSDToken.approve(address(allOrNothing), PLEDGE_AMOUNT); + allOrNothing.pledgeWithoutAReward( + users.backer2Address, + address(cUSDToken), + PLEDGE_AMOUNT + ); + uint256 cUSDTokenId = 1; + vm.stopPrank(); + + uint256 backer1USDCBefore = usdcToken.balanceOf(users.backer1Address); + uint256 backer2CUSDBefore = cUSDToken.balanceOf(users.backer2Address); + + // Claim refunds + vm.warp(LAUNCH_TIME + 1 days); + + vm.prank(users.backer1Address); + allOrNothing.claimRefund(usdcTokenId); + + vm.prank(users.backer2Address); + allOrNothing.claimRefund(cUSDTokenId); + + // Verify refunds in correct tokens + assertEq( + usdcToken.balanceOf(users.backer1Address) - backer1USDCBefore, + usdcAmount, + "Should refund in USDC" + ); + assertEq( + cUSDToken.balanceOf(users.backer2Address) - backer2CUSDBefore, + PLEDGE_AMOUNT, + "Should refund in cUSD" + ); + + // Verify no cross-token refunds + assertEq(cUSDToken.balanceOf(users.backer1Address), TOKEN_MINT_AMOUNT, "Should not receive cUSD"); + assertEq(usdcToken.balanceOf(users.backer2Address), TOKEN_MINT_AMOUNT / 1e12, "Should not receive USDC"); + } + + function test_revertWhenPledgingWithUnacceptedToken() external { + // Create a token not in the accepted list + TestToken unacceptedToken = new TestToken("Unaccepted", "UNA", 18); + unacceptedToken.mint(users.backer1Address, PLEDGE_AMOUNT); + + addRewards( + users.creator1Address, + address(allOrNothing), + REWARD_NAMES, + REWARDS + ); + + vm.startPrank(users.backer1Address); + unacceptedToken.approve(address(allOrNothing), PLEDGE_AMOUNT); + vm.warp(LAUNCH_TIME); + + vm.expectRevert( + abi.encodeWithSelector( + AllOrNothing.AllOrNothingTokenNotAccepted.selector, + address(unacceptedToken) + ) + ); + allOrNothing.pledgeWithoutAReward( + users.backer1Address, + address(unacceptedToken), + PLEDGE_AMOUNT + ); + vm.stopPrank(); + } } diff --git a/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaised.t.sol b/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaised.t.sol index 7fcc957a..33b7a37d 100644 --- a/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaised.t.sol +++ b/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaised.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import "forge-std/Vm.sol"; import "forge-std/console.sol"; @@ -272,15 +272,17 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder testToken.approve(treasury, pledgeAmount + tip); } - KeepWhatsRaised(treasury).setFeeAndPledge(pledgeId, backer, pledgeAmount, tip, fee, reward, isPledgeForAReward); + KeepWhatsRaised(treasury).setFeeAndPledge(pledgeId, backer, address(testToken), pledgeAmount, tip, fee, reward, isPledgeForAReward); logs = vm.getRecordedLogs(); - bytes memory data = decodeEventFromLogs( - logs, "Receipt(address,bytes32,uint256,uint256,uint256,bytes32[])", treasury + (bytes32[] memory topics, bytes memory data) = decodeTopicsAndData( + logs, "Receipt(address,address,bytes32,uint256,uint256,uint256,bytes32[])", treasury ); - (,, tokenId, rewards) = abi.decode(data, (uint256, uint256, uint256, bytes32[])); + // Indexed params: backer (topics[1]), pledgeToken (topics[2]) + // Data params: reward, pledgeAmount, tip, tokenId, rewards + (,, , tokenId, rewards) = abi.decode(data, (bytes32, uint256, uint256, uint256, bytes32[])); vm.stopPrank(); } @@ -307,15 +309,17 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder bytes32[] memory reward = new bytes32[](1); reward[0] = rewardName; - KeepWhatsRaised(keepWhatsRaisedAddress).pledgeForAReward(pledgeId, caller, tip, reward); + KeepWhatsRaised(keepWhatsRaisedAddress).pledgeForAReward(pledgeId, caller, token, tip, reward); logs = vm.getRecordedLogs(); - bytes memory data = decodeEventFromLogs( - logs, "Receipt(address,bytes32,uint256,uint256,uint256,bytes32[])", keepWhatsRaisedAddress + (bytes32[] memory topics, bytes memory data) = decodeTopicsAndData( + logs, "Receipt(address,address,bytes32,uint256,uint256,uint256,bytes32[])", keepWhatsRaisedAddress ); - (,, tokenId, rewards) = abi.decode(data, (uint256, uint256, uint256, bytes32[])); + // Indexed params: backer (topics[1]), pledgeToken (topics[2]) + // Data params: reward, pledgeAmount, tip, tokenId, rewards + (,, , tokenId, rewards) = abi.decode(data, (bytes32, uint256, uint256, uint256, bytes32[])); vm.stopPrank(); } @@ -338,15 +342,17 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder testToken.approve(keepWhatsRaisedAddress, pledgeAmount + tip); vm.warp(launchTime); - KeepWhatsRaised(keepWhatsRaisedAddress).pledgeWithoutAReward(pledgeId, caller, pledgeAmount, tip); + KeepWhatsRaised(keepWhatsRaisedAddress).pledgeWithoutAReward(pledgeId, caller, token, pledgeAmount, tip); logs = vm.getRecordedLogs(); - bytes memory data = decodeEventFromLogs( - logs, "Receipt(address,bytes32,uint256,uint256,uint256,bytes32[])", keepWhatsRaisedAddress + (bytes32[] memory topics, bytes memory data) = decodeTopicsAndData( + logs, "Receipt(address,address,bytes32,uint256,uint256,uint256,bytes32[])", keepWhatsRaisedAddress ); - (,, tokenId,) = abi.decode(data, (uint256, uint256, uint256, bytes32[])); + // Indexed params: backer (topics[1]), pledgeToken (topics[2]) + // Data params: reward, pledgeAmount, tip, tokenId, rewards + (,, , tokenId,) = abi.decode(data, (bytes32, uint256, uint256, uint256, bytes32[])); vm.stopPrank(); } @@ -361,7 +367,7 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder vm.startPrank(caller); vm.recordLogs(); - KeepWhatsRaised(keepWhatsRaisedAddress).withdraw(amount); + KeepWhatsRaised(keepWhatsRaisedAddress).withdraw(address(testToken), amount); logs = vm.getRecordedLogs(); @@ -463,8 +469,9 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder logs = vm.getRecordedLogs(); - bytes memory data = decodeEventFromLogs(logs, "FeesDisbursed(uint256,uint256)", keepWhatsRaisedAddress); + (bytes32[] memory topics, bytes memory data) = decodeTopicsAndData(logs, "FeesDisbursed(address,uint256,uint256)", keepWhatsRaisedAddress); + // topics[1] is the indexed token (protocolShare, platformShare) = abi.decode(data, (uint256, uint256)); } diff --git a/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaisedFunction.t.sol b/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaisedFunction.t.sol index 67a8f5aa..cd7fe0c6 100644 --- a/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaisedFunction.t.sol +++ b/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaisedFunction.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import "./KeepWhatsRaised.t.sol"; import "forge-std/Vm.sol"; @@ -271,7 +271,7 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte vm.warp(DEADLINE - 1 days); vm.prank(users.platform2AdminAddress); - keepWhatsRaised.withdraw(PLEDGE_AMOUNT); + keepWhatsRaised.withdraw(address(testToken), PLEDGE_AMOUNT); uint256 protocolAdminBalanceBefore = testToken.balanceOf(users.protocolAdminAddress); uint256 platformAdminBalanceBefore = testToken.balanceOf(users.platform2AdminAddress); @@ -519,7 +519,7 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte vm.startPrank(users.backer2Address); testToken.approve(address(keepWhatsRaised), PLEDGE_AMOUNT); vm.expectRevert(); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID_2, users.backer2Address, PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID_2, users.backer2Address, address(testToken), PLEDGE_AMOUNT, 0); vm.stopPrank(); } @@ -549,7 +549,7 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte vm.startPrank(users.backer2Address); testToken.approve(address(keepWhatsRaised), PLEDGE_AMOUNT); vm.expectRevert(); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID_2, users.backer2Address, PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID_2, users.backer2Address, address(testToken), PLEDGE_AMOUNT, 0); vm.stopPrank(); } diff --git a/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol b/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol index 418c6911..55636f00 100644 --- a/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol +++ b/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import {Base_Test} from "../../Base.t.sol"; import "forge-std/Vm.sol"; @@ -8,6 +8,7 @@ import {PaymentTreasury} from "src/treasuries/PaymentTreasury.sol"; import {CampaignInfo} from "src/CampaignInfo.sol"; import {ICampaignPaymentTreasury} from "src/interfaces/ICampaignPaymentTreasury.sol"; import {LogDecoder} from "../../utils/LogDecoder.sol"; +import {TestToken} from "../../../mocks/TestToken.sol"; /// @notice Common testing logic needed by all PaymentTreasury integration tests. abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Test { @@ -142,11 +143,12 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te bytes32 paymentId, bytes32 buyerId, bytes32 itemId, + address paymentToken, uint256 amount, uint256 expiration ) internal { vm.prank(caller); - paymentTreasury.createPayment(paymentId, buyerId, itemId, amount, expiration); + paymentTreasury.createPayment(paymentId, buyerId, itemId, paymentToken, amount, expiration); } /** @@ -157,10 +159,11 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te bytes32 paymentId, bytes32 itemId, address buyerAddress, + address paymentToken, uint256 amount ) internal { vm.prank(caller); - paymentTreasury.processCryptoPayment(paymentId, itemId, buyerAddress, amount); + paymentTreasury.processCryptoPayment(paymentId, itemId, buyerAddress, paymentToken, amount); } /** @@ -246,8 +249,10 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te Vm.Log[] memory logs = vm.getRecordedLogs(); - bytes memory data = decodeEventFromLogs(logs, "FeesDisbursed(uint256,uint256)", treasury); + (bytes32[] memory topics, bytes memory data) = decodeTopicsAndData(logs, "FeesDisbursed(address,uint256,uint256)", treasury); + // topics[1] is the indexed token + // Data contains protocolShare and platformShare (protocolShare, platformShare) = abi.decode(data, (uint256, uint256)); } @@ -265,9 +270,12 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te Vm.Log[] memory logs = vm.getRecordedLogs(); (bytes32[] memory topics, bytes memory data) = - decodeTopicsAndData(logs, "WithdrawalWithFeeSuccessful(address,uint256,uint256)", treasury); + decodeTopicsAndData(logs, "WithdrawalWithFeeSuccessful(address,address,uint256,uint256)", treasury); - to = address(uint160(uint256(topics[1]))); + // topics[0] is the event signature hash + // topics[1] is the indexed token + // topics[2] is the indexed to address + to = address(uint160(uint256(topics[2]))); (amount, fee) = abi.decode(data, (uint256, uint256)); } @@ -312,9 +320,9 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te vm.prank(buyerAddress); testToken.approve(treasuryAddress, amount); - // Create payment + // Create payment with token specified uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; - createPayment(users.platform1AdminAddress, paymentId, buyerId, itemId, amount, expiration); + createPayment(users.platform1AdminAddress, paymentId, buyerId, itemId, address(testToken), amount, expiration); // Transfer tokens from buyer to treasury vm.prank(buyerAddress); @@ -338,7 +346,7 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te testToken.approve(treasuryAddress, amount); // Process crypto payment - processCryptoPayment(buyerAddress, paymentId, itemId, buyerAddress, amount); + processCryptoPayment(buyerAddress, paymentId, itemId, buyerAddress, address(testToken), amount); } /** @@ -348,4 +356,52 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); _createAndFundPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, PAYMENT_AMOUNT_2, users.backer2Address); } + + /** + * @notice Helper to create and fund a payment from buyer with specific token + */ + function _createAndFundPaymentWithToken( + bytes32 paymentId, + bytes32 buyerId, + bytes32 itemId, + uint256 amount, + address buyerAddress, + address token + ) internal { + // Fund buyer + deal(token, buyerAddress, amount); + + // Buyer approves treasury + vm.prank(buyerAddress); + TestToken(token).approve(treasuryAddress, amount); + + // Create payment with token specified + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + createPayment(users.platform1AdminAddress, paymentId, buyerId, itemId, token, amount, expiration); + + // Transfer tokens from buyer to treasury + vm.prank(buyerAddress); + TestToken(token).transfer(treasuryAddress, amount); + } + + /** + * @notice Helper to create and process a crypto payment with specific token + */ + function _createAndProcessCryptoPaymentWithToken( + bytes32 paymentId, + bytes32 itemId, + uint256 amount, + address buyerAddress, + address token + ) internal { + // Fund buyer + deal(token, buyerAddress, amount); + + // Buyer approves treasury + vm.prank(buyerAddress); + TestToken(token).approve(treasuryAddress, amount); + + // Process crypto payment + processCryptoPayment(buyerAddress, paymentId, itemId, buyerAddress, token, amount); + } } \ No newline at end of file diff --git a/test/foundry/integration/PaymentTreasury/PaymentTreasuryBatchLimitTest.t.sol b/test/foundry/integration/PaymentTreasury/PaymentTreasuryBatchLimitTest.t.sol index 8b2d3f5b..7e90e55b 100644 --- a/test/foundry/integration/PaymentTreasury/PaymentTreasuryBatchLimitTest.t.sol +++ b/test/foundry/integration/PaymentTreasury/PaymentTreasuryBatchLimitTest.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import "./PaymentTreasury.t.sol"; import "forge-std/Vm.sol"; @@ -33,7 +33,7 @@ contract PaymentTreasuryBatchLimit_Test is PaymentTreasury_Integration_Shared_Te bytes32 buyerId = keccak256(abi.encodePacked("buyer", i)); bytes32 itemId = keccak256(abi.encodePacked("item", i)); - paymentTreasury.createPayment(paymentId, buyerId, itemId, paymentAmount, expiration); + paymentTreasury.createPayment(paymentId, buyerId, itemId, address(testToken), paymentAmount, expiration); paymentIds[i] = paymentId; } diff --git a/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol b/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol index cef0e151..7944559e 100644 --- a/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol +++ b/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import "./PaymentTreasury.t.sol"; import "forge-std/console.sol"; @@ -7,6 +7,7 @@ import "forge-std/Vm.sol"; import "forge-std/Test.sol"; import {CampaignInfo} from "src/CampaignInfo.sol"; import {PaymentTreasury} from "src/treasuries/PaymentTreasury.sol"; +import {TestToken} from "../../../mocks/TestToken.sol"; /** * @title PaymentTreasuryFunction_Integration_Test @@ -29,7 +30,7 @@ contract PaymentTreasuryFunction_Integration_Test is ); assertEq(testToken.balanceOf(treasuryAddress), PAYMENT_AMOUNT_1); - confirmPayment(users.platform1AdminAddress, PAYMENT_ID_1); + confirmPayment(users.platform1AdminAddress, PAYMENT_ID_1); // Removed token parameter assertEq( paymentTreasury.getRaisedAmount(), @@ -54,7 +55,7 @@ contract PaymentTreasuryFunction_Integration_Test is bytes32[] memory paymentIds = new bytes32[](2); paymentIds[0] = PAYMENT_ID_1; paymentIds[1] = PAYMENT_ID_2; - confirmPaymentBatch(users.platform1AdminAddress, paymentIds); + confirmPaymentBatch(users.platform1AdminAddress, paymentIds); // Removed token array assertEq( paymentTreasury.getRaisedAmount(), @@ -110,7 +111,7 @@ contract PaymentTreasuryFunction_Integration_Test is vm.prank(users.backer1Address); testToken.approve(treasuryAddress, amount); - processCryptoPayment(users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, amount); + processCryptoPayment(users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), amount); assertEq(paymentTreasury.getRaisedAmount(), amount, "Raised amount should match crypto payment"); assertEq(paymentTreasury.getAvailableRaisedAmount(), amount, "Available amount should match crypto payment"); @@ -209,4 +210,506 @@ contract PaymentTreasuryFunction_Integration_Test is assertEq(testToken.balanceOf(treasuryAddress), 0, "Treasury should have zero balance after disbursing fees"); } + + /*////////////////////////////////////////////////////////////// + MULTI-TOKEN FUNCTIONALITY TESTS + //////////////////////////////////////////////////////////////*/ + + function test_confirmPaymentWithMultipleTokens() public { + // Create payments with different tokens + uint256 usdtAmount = getTokenAmount(address(usdtToken), PAYMENT_AMOUNT_1); + uint256 usdcAmount = getTokenAmount(address(usdcToken), PAYMENT_AMOUNT_2); + + _createAndFundPaymentWithToken( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + usdtAmount, + users.backer1Address, + address(usdtToken) + ); + + _createAndFundPaymentWithToken( + PAYMENT_ID_2, + BUYER_ID_2, + ITEM_ID_2, + usdcAmount, + users.backer2Address, + address(usdcToken) + ); + + // Confirm without specifying token (already set during creation) + confirmPayment(users.platform1AdminAddress, PAYMENT_ID_1); + confirmPayment(users.platform1AdminAddress, PAYMENT_ID_2); + + // Verify normalized raised amount + uint256 expectedNormalized = PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2; + assertEq( + paymentTreasury.getRaisedAmount(), + expectedNormalized, + "Raised amount should be normalized sum" + ); + } + + function test_getRaisedAmountNormalizesCorrectly() public { + // Create payments with same base amount in different tokens + uint256 baseAmount = 1000e18; + uint256 usdtAmount = baseAmount / 1e12; // 6 decimals + uint256 cUSDAmount = baseAmount; // 18 decimals + + _createAndFundPaymentWithToken( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + usdtAmount, + users.backer1Address, + address(usdtToken) + ); + + confirmPayment(users.platform1AdminAddress, PAYMENT_ID_1); + + uint256 raisedAfterUSDT = paymentTreasury.getRaisedAmount(); + assertEq(raisedAfterUSDT, baseAmount, "USDT should normalize to base amount"); + + _createAndFundPaymentWithToken( + PAYMENT_ID_2, + BUYER_ID_2, + ITEM_ID_2, + cUSDAmount, + users.backer2Address, + address(cUSDToken) + ); + + confirmPayment(users.platform1AdminAddress, PAYMENT_ID_2); + + uint256 raisedAfterCUSD = paymentTreasury.getRaisedAmount(); + assertEq(raisedAfterCUSD, baseAmount * 2, "Total should be sum of normalized amounts"); + } + + function test_batchConfirmWithMultipleTokens() public { + // Create payments with different tokens + uint256 usdtAmount = getTokenAmount(address(usdtToken), 500e18); + uint256 usdcAmount = getTokenAmount(address(usdcToken), 700e18); + uint256 cUSDAmount = 900e18; + + _createAndFundPaymentWithToken( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + usdtAmount, + users.backer1Address, + address(usdtToken) + ); + + _createAndFundPaymentWithToken( + PAYMENT_ID_2, + BUYER_ID_2, + ITEM_ID_2, + usdcAmount, + users.backer2Address, + address(usdcToken) + ); + + _createAndFundPaymentWithToken( + PAYMENT_ID_3, + BUYER_ID_1, + ITEM_ID_1, + cUSDAmount, + users.backer1Address, + address(cUSDToken) + ); + + bytes32[] memory paymentIds = new bytes32[](3); + paymentIds[0] = PAYMENT_ID_1; + paymentIds[1] = PAYMENT_ID_2; + paymentIds[2] = PAYMENT_ID_3; + + // Batch confirm without token array (tokens already set during creation) + confirmPaymentBatch(users.platform1AdminAddress, paymentIds); + + uint256 expectedTotal = 500e18 + 700e18 + 900e18; + assertEq(paymentTreasury.getRaisedAmount(), expectedTotal, "Should sum all normalized amounts"); + } + + function test_processCryptoPaymentWithMultipleTokens() public { + uint256 usdtAmount = getTokenAmount(address(usdtToken), 800e18); + uint256 cUSDAmount = 1200e18; + + // Process USDT payment + _createAndProcessCryptoPaymentWithToken( + PAYMENT_ID_1, + ITEM_ID_1, + usdtAmount, + users.backer1Address, + address(usdtToken) + ); + + // Process cUSD payment + _createAndProcessCryptoPaymentWithToken( + PAYMENT_ID_2, + ITEM_ID_2, + cUSDAmount, + users.backer2Address, + address(cUSDToken) + ); + + uint256 expectedTotal = 800e18 + 1200e18; + assertEq(paymentTreasury.getRaisedAmount(), expectedTotal, "Should track both crypto payments"); + assertEq(usdtToken.balanceOf(treasuryAddress), usdtAmount, "Should hold USDT"); + assertEq(cUSDToken.balanceOf(treasuryAddress), cUSDAmount, "Should hold cUSD"); + } + + function test_refundReturnsCorrectToken() public { + uint256 usdtAmount = getTokenAmount(address(usdtToken), PAYMENT_AMOUNT_1); + uint256 cUSDAmount = PAYMENT_AMOUNT_2; + + // Create and confirm USDT payment + _createAndFundPaymentWithToken( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + usdtAmount, + users.backer1Address, + address(usdtToken) + ); + confirmPayment(users.platform1AdminAddress, PAYMENT_ID_1); // No token parameter + + // Create and confirm cUSD payment + _createAndFundPaymentWithToken( + PAYMENT_ID_2, + BUYER_ID_2, + ITEM_ID_2, + cUSDAmount, + users.backer2Address, + address(cUSDToken) + ); + confirmPayment(users.platform1AdminAddress, PAYMENT_ID_2); // No token parameter + + uint256 backer1USDTBefore = usdtToken.balanceOf(users.backer1Address); + uint256 backer2CUSDBefore = cUSDToken.balanceOf(users.backer2Address); + + // Claim refunds + uint256 refund1 = claimRefund(users.platform1AdminAddress, PAYMENT_ID_1, users.backer1Address); + uint256 refund2 = claimRefund(users.platform1AdminAddress, PAYMENT_ID_2, users.backer2Address); + + // Verify correct tokens refunded + assertEq(refund1, usdtAmount, "Should refund USDT amount"); + assertEq(refund2, cUSDAmount, "Should refund cUSD amount"); + assertEq( + usdtToken.balanceOf(users.backer1Address) - backer1USDTBefore, + usdtAmount, + "Should receive USDT" + ); + assertEq( + cUSDToken.balanceOf(users.backer2Address) - backer2CUSDBefore, + cUSDAmount, + "Should receive cUSD" + ); + + // Verify no cross-token contamination + assertEq(cUSDToken.balanceOf(users.backer1Address), TOKEN_MINT_AMOUNT, "Backer1 shouldn't have cUSD changes"); + assertEq(usdtToken.balanceOf(users.backer2Address), TOKEN_MINT_AMOUNT / 1e12, "Backer2 shouldn't have USDT changes"); + } + + function test_cryptoPaymentRefundWithMultipleTokens() public { + uint256 usdcAmount = getTokenAmount(address(usdcToken), 1500e18); + uint256 cUSDAmount = 2000e18; + + // Process crypto payments + _createAndProcessCryptoPaymentWithToken( + PAYMENT_ID_1, + ITEM_ID_1, + usdcAmount, + users.backer1Address, + address(usdcToken) + ); + + _createAndProcessCryptoPaymentWithToken( + PAYMENT_ID_2, + ITEM_ID_2, + cUSDAmount, + users.backer2Address, + address(cUSDToken) + ); + + uint256 backer1USDCBefore = usdcToken.balanceOf(users.backer1Address); + uint256 backer2CUSDBefore = cUSDToken.balanceOf(users.backer2Address); + + // Buyers claim their own refunds + uint256 refund1 = claimRefund(users.backer1Address, PAYMENT_ID_1); + uint256 refund2 = claimRefund(users.backer2Address, PAYMENT_ID_2); + + assertEq(refund1, usdcAmount, "Should refund USDC amount"); + assertEq(refund2, cUSDAmount, "Should refund cUSD amount"); + assertEq(usdcToken.balanceOf(users.backer1Address) - backer1USDCBefore, usdcAmount); + assertEq(cUSDToken.balanceOf(users.backer2Address) - backer2CUSDBefore, cUSDAmount); + } + + function test_withdrawWithMultipleTokens() public { + uint256 usdtAmount = getTokenAmount(address(usdtToken), 1000e18); + uint256 usdcAmount = getTokenAmount(address(usdcToken), 1500e18); + uint256 cUSDAmount = 2000e18; + + // Create and confirm payments with different tokens + _createAndFundPaymentWithToken( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + usdtAmount, + users.backer1Address, + address(usdtToken) + ); + confirmPayment(users.platform1AdminAddress, PAYMENT_ID_1); + + _createAndFundPaymentWithToken( + PAYMENT_ID_2, + BUYER_ID_2, + ITEM_ID_2, + usdcAmount, + users.backer2Address, + address(usdcToken) + ); + confirmPayment(users.platform1AdminAddress, PAYMENT_ID_2); + + _createAndFundPaymentWithToken( + PAYMENT_ID_3, + BUYER_ID_1, + ITEM_ID_1, + cUSDAmount, + users.backer1Address, + address(cUSDToken) + ); + confirmPayment(users.platform1AdminAddress, PAYMENT_ID_3); + + address campaignOwner = CampaignInfo(campaignAddress).owner(); + uint256 ownerUSDTBefore = usdtToken.balanceOf(campaignOwner); + uint256 ownerUSDCBefore = usdcToken.balanceOf(campaignOwner); + uint256 ownerCUSDBefore = cUSDToken.balanceOf(campaignOwner); + + // Withdraw all tokens + withdraw(treasuryAddress); + + // Verify owner received all tokens (minus fees) + assertTrue(usdtToken.balanceOf(campaignOwner) > ownerUSDTBefore, "Should receive USDT"); + assertTrue(usdcToken.balanceOf(campaignOwner) > ownerUSDCBefore, "Should receive USDC"); + assertTrue(cUSDToken.balanceOf(campaignOwner) > ownerCUSDBefore, "Should receive cUSD"); + + // Verify available amount is zero + assertEq(paymentTreasury.getAvailableRaisedAmount(), 0, "Should have zero available after withdrawal"); + } + + function test_disburseFeesWithMultipleTokens() public { + uint256 usdtAmount = getTokenAmount(address(usdtToken), PAYMENT_AMOUNT_1); + uint256 cUSDAmount = PAYMENT_AMOUNT_2; + + // Create and confirm payments + _createAndFundPaymentWithToken( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + usdtAmount, + users.backer1Address, + address(usdtToken) + ); + confirmPayment(users.platform1AdminAddress, PAYMENT_ID_1); + + _createAndFundPaymentWithToken( + PAYMENT_ID_2, + BUYER_ID_2, + ITEM_ID_2, + cUSDAmount, + users.backer2Address, + address(cUSDToken) + ); + confirmPayment(users.platform1AdminAddress, PAYMENT_ID_2); + + // Withdraw to calculate fees + withdraw(treasuryAddress); + + uint256 protocolUSDTBefore = usdtToken.balanceOf(users.protocolAdminAddress); + uint256 protocolCUSDBefore = cUSDToken.balanceOf(users.protocolAdminAddress); + uint256 platformUSDTBefore = usdtToken.balanceOf(users.platform1AdminAddress); + uint256 platformCUSDBefore = cUSDToken.balanceOf(users.platform1AdminAddress); + + // Disburse fees + disburseFees(treasuryAddress); + + // Verify fees distributed for both tokens + uint256 expectedUSDTProtocolFee = (usdtAmount * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 expectedUSDTPlatformFee = (usdtAmount * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 expectedCUSDProtocolFee = (cUSDAmount * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 expectedCUSDPlatformFee = (cUSDAmount * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; + + assertEq( + usdtToken.balanceOf(users.protocolAdminAddress) - protocolUSDTBefore, + expectedUSDTProtocolFee, + "USDT protocol fee incorrect" + ); + assertEq( + cUSDToken.balanceOf(users.protocolAdminAddress) - protocolCUSDBefore, + expectedCUSDProtocolFee, + "cUSD protocol fee incorrect" + ); + assertEq( + usdtToken.balanceOf(users.platform1AdminAddress) - platformUSDTBefore, + expectedUSDTPlatformFee, + "USDT platform fee incorrect" + ); + assertEq( + cUSDToken.balanceOf(users.platform1AdminAddress) - platformCUSDBefore, + expectedCUSDPlatformFee, + "cUSD platform fee incorrect" + ); + + // Treasury should be empty + assertEq(usdtToken.balanceOf(treasuryAddress), 0, "USDT should be fully disbursed"); + assertEq(cUSDToken.balanceOf(treasuryAddress), 0, "cUSD should be fully disbursed"); + } + + function test_mixedPaymentTypesWithMultipleTokens() public { + // Regular payment with USDT + uint256 usdtAmount = getTokenAmount(address(usdtToken), 1000e18); + _createAndFundPaymentWithToken( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + usdtAmount, + users.backer1Address, + address(usdtToken) + ); + confirmPayment(users.platform1AdminAddress, PAYMENT_ID_1); + + // Crypto payment with USDC + uint256 usdcAmount = getTokenAmount(address(usdcToken), 1500e18); + _createAndProcessCryptoPaymentWithToken( + PAYMENT_ID_2, + ITEM_ID_2, + usdcAmount, + users.backer2Address, + address(usdcToken) + ); + + // Regular payment with cUSD + uint256 cUSDAmount = 2000e18; + _createAndFundPaymentWithToken( + PAYMENT_ID_3, + BUYER_ID_1, + ITEM_ID_1, + cUSDAmount, + users.backer1Address, + address(cUSDToken) + ); + confirmPayment(users.platform1AdminAddress, PAYMENT_ID_3); + + // Verify all contribute to raised amount + uint256 expectedTotal = 1000e18 + 1500e18 + 2000e18; + assertEq(paymentTreasury.getRaisedAmount(), expectedTotal, "Should sum all payment types"); + + // Withdraw and disburse + withdraw(treasuryAddress); + disburseFees(treasuryAddress); + + assertEq(paymentTreasury.getAvailableRaisedAmount(), 0); + } + + function test_revertWhenCreatingWithUnacceptedToken() public { + // Create a token not in the accepted list + TestToken rejectedToken = new TestToken("Rejected", "REJ", 18); + uint256 amount = 1000e18; + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + + // Try to create payment with unaccepted token + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(rejectedToken), + amount, + expiration + ); + } + + function test_revertWhenTokenNotAccepted() public { + // Create a token not in the accepted list + TestToken rejectedToken = new TestToken("Rejected", "REJ", 18); + uint256 amount = 1000e18; + rejectedToken.mint(users.backer1Address, amount); + + vm.prank(users.backer1Address); + rejectedToken.approve(treasuryAddress, amount); + + // Try to process crypto payment with unaccepted token + vm.expectRevert(); + processCryptoPayment( + users.backer1Address, + PAYMENT_ID_1, + ITEM_ID_1, + users.backer1Address, + address(rejectedToken), + amount + ); + } + + function test_balanceTrackingAcrossMultipleTokens() public { + // Create multiple payments with different tokens + uint256 usdtAmount1 = getTokenAmount(address(usdtToken), 500e18); + uint256 usdtAmount2 = getTokenAmount(address(usdtToken), 300e18); + uint256 cUSDAmount = 1000e18; + + _createAndFundPaymentWithToken( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + usdtAmount1, + users.backer1Address, + address(usdtToken) + ); + + _createAndFundPaymentWithToken( + PAYMENT_ID_2, + BUYER_ID_2, + ITEM_ID_2, + usdtAmount2, + users.backer2Address, + address(usdtToken) + ); + + _createAndFundPaymentWithToken( + PAYMENT_ID_3, + BUYER_ID_1, + ITEM_ID_1, + cUSDAmount, + users.backer1Address, + address(cUSDToken) + ); + + // Confirm all payments + confirmPayment(users.platform1AdminAddress, PAYMENT_ID_1); + confirmPayment(users.platform1AdminAddress, PAYMENT_ID_2); + confirmPayment(users.platform1AdminAddress, PAYMENT_ID_3); + + // Verify raised amounts + uint256 expectedTotal = 500e18 + 300e18 + 1000e18; + assertEq(paymentTreasury.getRaisedAmount(), expectedTotal, "Should track total correctly"); + + // Refund one USDT payment + claimRefund(users.platform1AdminAddress, PAYMENT_ID_1, users.backer1Address); + + uint256 afterRefund = 300e18 + 1000e18; + assertEq(paymentTreasury.getRaisedAmount(), afterRefund, "Should update after refund"); + + // Verify token balances + assertEq( + usdtToken.balanceOf(treasuryAddress), + usdtAmount2, + "Should only have remaining USDT" + ); + assertEq( + cUSDToken.balanceOf(treasuryAddress), + cUSDAmount, + "cUSD should be unchanged" + ); + } } \ No newline at end of file diff --git a/test/foundry/unit/CampaignInfoFactory.t.sol b/test/foundry/unit/CampaignInfoFactory.t.sol index 803a83bb..35c4b35f 100644 --- a/test/foundry/unit/CampaignInfoFactory.t.sol +++ b/test/foundry/unit/CampaignInfoFactory.t.sol @@ -1,10 +1,12 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import "forge-std/Test.sol"; import {CampaignInfoFactory} from "src/CampaignInfoFactory.sol"; import {GlobalParams} from "src/GlobalParams.sol"; import {TreasuryFactory} from "src/TreasuryFactory.sol"; +import {IGlobalParams} from "src/interfaces/IGlobalParams.sol"; +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; import {TestToken} from "../../mocks/TestToken.sol"; import {Defaults} from "../Base.t.sol"; import {ICampaignData} from "src/interfaces/ICampaignData.sol"; @@ -20,18 +22,61 @@ contract CampaignInfoFactory_UnitTest is Test, Defaults { address internal admin = address(0xA11CE); function setUp() public { - testToken = new TestToken(tokenName, tokenSymbol); - globalParams = new GlobalParams( + testToken = new TestToken(tokenName, tokenSymbol, 18); + + // Setup currencies and tokens for multi-token support + bytes32[] memory currencies = new bytes32[](1); + currencies[0] = bytes32("USD"); + + address[][] memory tokensPerCurrency = new address[][](1); + tokensPerCurrency[0] = new address[](1); + tokensPerCurrency[0][0] = address(testToken); + + // Deploy GlobalParams with proxy + GlobalParams globalParamsImpl = new GlobalParams(); + bytes memory globalParamsInitData = abi.encodeWithSelector( + GlobalParams.initialize.selector, admin, - address(testToken), - PROTOCOL_FEE_PERCENT + PROTOCOL_FEE_PERCENT, + currencies, + tokensPerCurrency ); - campaignInfoImplementation = new CampaignInfo(address(this)); - treasuryFactory = new TreasuryFactory(globalParams); - factory = new CampaignInfoFactory( - globalParams, - address(campaignInfoImplementation) + ERC1967Proxy globalParamsProxy = new ERC1967Proxy( + address(globalParamsImpl), + globalParamsInitData ); + globalParams = GlobalParams(address(globalParamsProxy)); + + // Deploy CampaignInfo implementation + campaignInfoImplementation = new CampaignInfo(); + + // Deploy TreasuryFactory with proxy + TreasuryFactory treasuryFactoryImpl = new TreasuryFactory(); + bytes memory treasuryFactoryInitData = abi.encodeWithSelector( + TreasuryFactory.initialize.selector, + IGlobalParams(address(globalParams)) + ); + ERC1967Proxy treasuryFactoryProxy = new ERC1967Proxy( + address(treasuryFactoryImpl), + treasuryFactoryInitData + ); + treasuryFactory = TreasuryFactory(address(treasuryFactoryProxy)); + + // Deploy CampaignInfoFactory with proxy + CampaignInfoFactory factoryImpl = new CampaignInfoFactory(); + bytes memory factoryInitData = abi.encodeWithSelector( + CampaignInfoFactory.initialize.selector, + address(this), + IGlobalParams(address(globalParams)), + address(campaignInfoImplementation), + address(treasuryFactory) + ); + ERC1967Proxy factoryProxy = new ERC1967Proxy( + address(factoryImpl), + factoryInitData + ); + factory = CampaignInfoFactory(address(factoryProxy)); + vm.startPrank(admin); globalParams.enlistPlatform( PLATFORM_1_HASH, @@ -41,17 +86,7 @@ contract CampaignInfoFactory_UnitTest is Test, Defaults { vm.stopPrank(); } - function testInitializeSetsTreasuryAndGlobalParams() public { - // vm.startPrank(address(this)); // this is owner - - factory._initialize(address(treasuryFactory), address(globalParams)); - // Success assumed if no revert - // vm.stopPrank(); - } - function testCreateCampaignDeploysSuccessfully() public { - factory._initialize(address(treasuryFactory), address(globalParams)); - bytes32[] memory platforms = new bytes32[](1); platforms[0] = PLATFORM_1_HASH; @@ -109,4 +144,52 @@ contract CampaignInfoFactory_UnitTest is Test, Defaults { "Campaign not marked valid" ); } + + function testUpgrade() public { + // Deploy new implementation + CampaignInfoFactory newImplementation = new CampaignInfoFactory(); + + // Upgrade as owner (address(this)) + factory.upgradeToAndCall(address(newImplementation), ""); + + // Factory should still work after upgrade + bytes32[] memory platforms = new bytes32[](1); + platforms[0] = PLATFORM_1_HASH; + + bytes32[] memory keys = new bytes32[](0); + bytes32[] memory values = new bytes32[](0); + + address creator = address(0xBEEF); + + vm.prank(admin); + factory.createCampaign( + creator, + CAMPAIGN_1_IDENTIFIER_HASH, + platforms, + keys, + values, + CAMPAIGN_DATA + ); + } + + function testUpgradeUnauthorizedReverts() public { + // Deploy new implementation + CampaignInfoFactory newImplementation = new CampaignInfoFactory(); + + // Try to upgrade as non-owner (should revert) + vm.prank(admin); + vm.expectRevert(); + factory.upgradeToAndCall(address(newImplementation), ""); + } + + function testCannotInitializeTwice() public { + // Try to initialize again (should revert) + vm.expectRevert(); + factory.initialize( + address(this), + IGlobalParams(address(globalParams)), + address(campaignInfoImplementation), + address(treasuryFactory) + ); + } } diff --git a/test/foundry/unit/GlobalParams.t.sol b/test/foundry/unit/GlobalParams.t.sol index 05c82ffa..309ffd88 100644 --- a/test/foundry/unit/GlobalParams.t.sol +++ b/test/foundry/unit/GlobalParams.t.sol @@ -1,27 +1,78 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import "forge-std/Test.sol"; import {GlobalParams} from "src/GlobalParams.sol"; +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; import {Defaults} from "../Base.t.sol"; import {TestToken} from "../../mocks/TestToken.sol"; -contract GlobalParams_UnitTest is Test, Defaults{ +contract GlobalParams_UnitTest is Test, Defaults { GlobalParams internal globalParams; - TestToken internal token; + GlobalParams internal implementation; + TestToken internal token1; + TestToken internal token2; + TestToken internal token3; address internal admin = address(0xA11CE); uint256 internal protocolFee = 300; // 3% + bytes32 internal constant USD = bytes32("USD"); + bytes32 internal constant EUR = bytes32("EUR"); + bytes32 internal constant BRL = bytes32("BRL"); + function setUp() public { - token = new TestToken(tokenName, tokenSymbol); - globalParams = new GlobalParams(admin, address(token), protocolFee); + token1 = new TestToken("Token1", "TK1", 18); + token2 = new TestToken("Token2", "TK2", 18); + token3 = new TestToken("Token3", "TK3", 18); + + // Setup initial currencies and tokens + bytes32[] memory currencies = new bytes32[](2); + currencies[0] = USD; + currencies[1] = EUR; + + address[][] memory tokensPerCurrency = new address[][](2); + tokensPerCurrency[0] = new address[](2); + tokensPerCurrency[0][0] = address(token1); + tokensPerCurrency[0][1] = address(token2); + + tokensPerCurrency[1] = new address[](1); + tokensPerCurrency[1][0] = address(token3); + + // Deploy implementation + implementation = new GlobalParams(); + + // Prepare initialization data + bytes memory initData = abi.encodeWithSelector( + GlobalParams.initialize.selector, + admin, + protocolFee, + currencies, + tokensPerCurrency + ); + + // Deploy proxy + ERC1967Proxy proxy = new ERC1967Proxy(address(implementation), initData); + globalParams = GlobalParams(address(proxy)); } function testInitialValues() public { assertEq(globalParams.getProtocolAdminAddress(), admin); - assertEq(globalParams.getTokenAddress(), address(token)); assertEq(globalParams.getProtocolFeePercent(), protocolFee); + + // Test USD tokens + address[] memory usdTokens = globalParams.getTokensForCurrency(USD); + assertEq(usdTokens.length, 2); + assertEq(usdTokens[0], address(token1)); + assertEq(usdTokens[1], address(token2)); + + // Test EUR tokens + address[] memory eurTokens = globalParams.getTokensForCurrency(EUR); + assertEq(eurTokens.length, 1); + assertEq(eurTokens[0], address(token3)); + + // Token validation is done by checking if token is in the returned array + // This is handled by the getTokensForCurrency function above } function testSetProtocolAdmin() public { @@ -31,24 +82,227 @@ contract GlobalParams_UnitTest is Test, Defaults{ assertEq(globalParams.getProtocolAdminAddress(), newAdmin); } - function testSetAcceptedToken() public { - address newToken = address(0xDEAD); - vm.prank(admin); - globalParams.updateTokenAddress(newToken); - assertEq(globalParams.getTokenAddress(), newToken); - } - function testSetProtocolFeePercent() public { vm.prank(admin); globalParams.updateProtocolFeePercent(500); // 5% assertEq(globalParams.getProtocolFeePercent(), 500); } + function testAddTokenToCurrency() public { + TestToken newToken = new TestToken("NewToken", "NEW", 18); + + vm.prank(admin); + globalParams.addTokenToCurrency(USD, address(newToken)); + + // Verify token was added + address[] memory usdTokens = globalParams.getTokensForCurrency(USD); + assertEq(usdTokens.length, 3); + assertEq(usdTokens[2], address(newToken)); + } + + function testAddTokenToNewCurrency() public { + TestToken newToken = new TestToken("BRLToken", "BRL", 18); + + vm.prank(admin); + globalParams.addTokenToCurrency(BRL, address(newToken)); + + // Verify token was added to new currency + address[] memory brlTokens = globalParams.getTokensForCurrency(BRL); + assertEq(brlTokens.length, 1); + assertEq(brlTokens[0], address(newToken)); + } + + function testAddTokenRevertWhenNotOwner() public { + TestToken newToken = new TestToken("NewToken", "NEW", 18); + + vm.expectRevert(); + globalParams.addTokenToCurrency(USD, address(newToken)); + } + + function testAddTokenToMultipleCurrencies() public { + // A token can be assigned to multiple currencies + vm.prank(admin); + globalParams.addTokenToCurrency(EUR, address(token1)); + + // Verify token is now in both USD and EUR + address[] memory usdTokens = globalParams.getTokensForCurrency(USD); + address[] memory eurTokens = globalParams.getTokensForCurrency(EUR); + + assertEq(usdTokens.length, 2); + assertEq(eurTokens.length, 2); + assertEq(eurTokens[1], address(token1)); + } + + function testRemoveTokenFromCurrency() public { + vm.prank(admin); + globalParams.removeTokenFromCurrency(USD, address(token1)); + + // Verify token was removed + address[] memory usdTokens = globalParams.getTokensForCurrency(USD); + assertEq(usdTokens.length, 1); + assertEq(usdTokens[0], address(token2)); + } + + function testRemoveTokenRevertWhenNotOwner() public { + vm.expectRevert(); + globalParams.removeTokenFromCurrency(USD, address(token1)); + } + + function testRemoveTokenThatDoesNotExist() public { + // Removing a non-existent token + TestToken nonExistentToken = new TestToken("NonExistent", "NE", 18); + + vm.expectRevert(); + vm.prank(admin); + globalParams.removeTokenFromCurrency(USD, address(nonExistentToken)); + } + + function testGetTokensForCurrency() public { + address[] memory usdTokens = globalParams.getTokensForCurrency(USD); + assertEq(usdTokens.length, 2); + + address[] memory eurTokens = globalParams.getTokensForCurrency(EUR); + assertEq(eurTokens.length, 1); + + // Non-existent currency returns empty array + address[] memory nonExistentTokens = globalParams.getTokensForCurrency(BRL); + assertEq(nonExistentTokens.length, 0); + } + function testUnauthorizedSettersRevert() public { vm.expectRevert(); globalParams.updateProtocolFeePercent(1000); vm.expectRevert(); - globalParams.updateTokenAddress(address(0xBEEF)); + globalParams.updateProtocolAdminAddress(address(0xBEEF)); + } + + function testInitializerWithEmptyArrays() public { + bytes32[] memory currencies = new bytes32[](0); + address[][] memory tokensPerCurrency = new address[][](0); + + GlobalParams emptyImpl = new GlobalParams(); + bytes memory initData = abi.encodeWithSelector( + GlobalParams.initialize.selector, + admin, + protocolFee, + currencies, + tokensPerCurrency + ); + + ERC1967Proxy emptyProxy = new ERC1967Proxy(address(emptyImpl), initData); + GlobalParams emptyGlobalParams = GlobalParams(address(emptyProxy)); + + address[] memory tokens = emptyGlobalParams.getTokensForCurrency(USD); + assertEq(tokens.length, 0); + } + + function testInitializerRevertOnMismatchedArrays() public { + bytes32[] memory currencies = new bytes32[](2); + currencies[0] = USD; + currencies[1] = EUR; + + address[][] memory tokensPerCurrency = new address[][](1); + tokensPerCurrency[0] = new address[](1); + tokensPerCurrency[0][0] = address(token1); + + GlobalParams mismatchImpl = new GlobalParams(); + bytes memory initData = abi.encodeWithSelector( + GlobalParams.initialize.selector, + admin, + protocolFee, + currencies, + tokensPerCurrency + ); + + vm.expectRevert(); + new ERC1967Proxy(address(mismatchImpl), initData); + } + + function testMultipleTokensPerCurrency() public { + // USD should have 2 tokens + address[] memory usdTokens = globalParams.getTokensForCurrency(USD); + assertEq(usdTokens.length, 2); + + // Add a third token to USD + TestToken token4 = new TestToken("Token4", "TK4", 18); + vm.prank(admin); + globalParams.addTokenToCurrency(USD, address(token4)); + + // Verify USD now has 3 tokens + usdTokens = globalParams.getTokensForCurrency(USD); + assertEq(usdTokens.length, 3); + assertEq(usdTokens[0], address(token1)); + assertEq(usdTokens[1], address(token2)); + assertEq(usdTokens[2], address(token4)); + } + + function testRemoveMiddleToken() public { + // Remove token1 (first token) from USD + vm.prank(admin); + globalParams.removeTokenFromCurrency(USD, address(token1)); + + address[] memory usdTokens = globalParams.getTokensForCurrency(USD); + assertEq(usdTokens.length, 1); + assertEq(usdTokens[0], address(token2)); + } + + function testAddRemoveMultipleTokens() public { + TestToken token4 = new TestToken("Token4", "TK4", 18); + TestToken token5 = new TestToken("Token5", "TK5", 18); + + // Add two new tokens + vm.startPrank(admin); + globalParams.addTokenToCurrency(USD, address(token4)); + globalParams.addTokenToCurrency(USD, address(token5)); + vm.stopPrank(); + + address[] memory usdTokens = globalParams.getTokensForCurrency(USD); + assertEq(usdTokens.length, 4); + + // Remove original tokens + vm.startPrank(admin); + globalParams.removeTokenFromCurrency(USD, address(token1)); + globalParams.removeTokenFromCurrency(USD, address(token2)); + vm.stopPrank(); + + usdTokens = globalParams.getTokensForCurrency(USD); + assertEq(usdTokens.length, 2); + assertEq(usdTokens[0], address(token5)); // token5 moved to index 0 + assertEq(usdTokens[1], address(token4)); // token4 moved to index 1 + } + + function testUpgrade() public { + // Deploy new implementation + GlobalParams newImplementation = new GlobalParams(); + + // Upgrade as admin + vm.prank(admin); + globalParams.upgradeToAndCall(address(newImplementation), ""); + + // Verify state is preserved after upgrade + assertEq(globalParams.getProtocolAdminAddress(), admin); + assertEq(globalParams.getProtocolFeePercent(), protocolFee); + + address[] memory usdTokens = globalParams.getTokensForCurrency(USD); + assertEq(usdTokens.length, 2); + } + + function testUpgradeUnauthorizedReverts() public { + // Deploy new implementation + GlobalParams newImplementation = new GlobalParams(); + + // Try to upgrade as non-admin (should revert) + vm.expectRevert(); + globalParams.upgradeToAndCall(address(newImplementation), ""); + } + + function testCannotInitializeTwice() public { + bytes32[] memory currencies = new bytes32[](0); + address[][] memory tokensPerCurrency = new address[][](0); + + // Try to initialize again (should revert) + vm.expectRevert(); + globalParams.initialize(admin, protocolFee, currencies, tokensPerCurrency); } } diff --git a/test/foundry/unit/KeepWhatsRaised.t.sol b/test/foundry/unit/KeepWhatsRaised.t.sol index d9562c92..3147ad3f 100644 --- a/test/foundry/unit/KeepWhatsRaised.t.sol +++ b/test/foundry/unit/KeepWhatsRaised.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import "../integration/KeepWhatsRaised/KeepWhatsRaised.t.sol"; import "forge-std/Test.sol"; @@ -12,6 +12,7 @@ import {TestToken} from "../../mocks/TestToken.sol"; import {Defaults} from "../Base.t.sol"; import {IReward} from "src/interfaces/IReward.sol"; import {ICampaignData} from "src/interfaces/ICampaignData.sol"; +import {TestToken} from "../../mocks/TestToken.sol"; contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Test { @@ -85,7 +86,8 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te ICampaignData.CampaignData memory newCampaignData = ICampaignData.CampaignData({ launchTime: block.timestamp + 1 days, deadline: block.timestamp + 31 days, - goalAmount: 5000 + goalAmount: 5000, + currency: bytes32("USD") }); KeepWhatsRaised.FeeValues memory feeValues = _createFeeValues(); @@ -108,7 +110,8 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te ICampaignData.CampaignData memory newCampaignData = ICampaignData.CampaignData({ launchTime: block.timestamp + 1 days, deadline: block.timestamp + 31 days, - goalAmount: 5000 + goalAmount: 5000, + currency: bytes32("USD") }); KeepWhatsRaised.FeeValues memory feeValues = _createFeeValues(); @@ -127,7 +130,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te bytes32[] memory rewardSelection = new bytes32[](1); rewardSelection[0] = TEST_REWARD_NAME; - keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, 0, rewardSelection); + keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), 0, rewardSelection); vm.stopPrank(); // Available amount should not include Colombian tax deduction at pledge time @@ -152,7 +155,8 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te ICampaignData.CampaignData memory invalidCampaignData = ICampaignData.CampaignData({ launchTime: block.timestamp - 1, deadline: block.timestamp + 31 days, - goalAmount: 5000 + goalAmount: 5000, + currency: bytes32("USD") }); KeepWhatsRaised.FeeValues memory feeValues = _createFeeValues(); @@ -447,7 +451,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te bytes32[] memory rewardSelection = new bytes32[](1); rewardSelection[0] = TEST_REWARD_NAME; - keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_TIP_AMOUNT, rewardSelection); + keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_TIP_AMOUNT, rewardSelection); vm.stopPrank(); // Verify @@ -469,12 +473,12 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te rewardSelection[0] = TEST_REWARD_NAME; // First pledge - keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, 0, rewardSelection); + keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), 0, rewardSelection); // Try to pledge with same ID bytes32 internalPledgeId = keccak256(abi.encodePacked(TEST_PLEDGE_ID, users.backer1Address)); vm.expectRevert(abi.encodeWithSelector(KeepWhatsRaised.KeepWhatsRaisedPledgeAlreadyProcessed.selector, internalPledgeId)); - keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, 0, rewardSelection); + keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), 0, rewardSelection); vm.stopPrank(); } @@ -498,7 +502,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te rewardSelection[0] = TEST_REWARD_NAME; vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedInvalidInput.selector); - keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, 0, rewardSelection); + keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), 0, rewardSelection); vm.stopPrank(); } @@ -512,7 +516,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), pledgeAmount + TEST_TIP_AMOUNT); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, pledgeAmount, TEST_TIP_AMOUNT); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), pledgeAmount, TEST_TIP_AMOUNT); vm.stopPrank(); // Verify @@ -530,12 +534,12 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT * 2); // First pledge - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); // Try to pledge with same ID - internal pledge ID includes caller bytes32 internalPledgeId = keccak256(abi.encodePacked(TEST_PLEDGE_ID, users.backer1Address)); vm.expectRevert(abi.encodeWithSelector(KeepWhatsRaised.KeepWhatsRaisedPledgeAlreadyProcessed.selector, internalPledgeId)); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); vm.stopPrank(); } @@ -544,13 +548,13 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(LAUNCH_TIME - 1); vm.expectRevert(); vm.prank(users.backer1Address); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); // After deadline vm.warp(DEADLINE + 1); vm.expectRevert(); vm.prank(users.backer1Address); - keepWhatsRaised.pledgeWithoutAReward(keccak256("newPledge"), users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward(keccak256("newPledge"), users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); } function testPledgeForARewardRevertWhenPaused() public { @@ -568,7 +572,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te rewardSelection[0] = TEST_REWARD_NAME; vm.expectRevert(); - keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_TIP_AMOUNT, rewardSelection); + keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_TIP_AMOUNT, rewardSelection); vm.stopPrank(); } @@ -589,6 +593,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te keepWhatsRaised.setFeeAndPledge( TEST_PLEDGE_ID, users.backer1Address, + address(testToken), 0, // ignored for reward pledges TEST_TIP_AMOUNT, PAYMENT_GATEWAY_FEE, @@ -623,7 +628,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te // Withdraw after deadline (as platform admin) vm.warp(DEADLINE + 1); vm.prank(users.platform2AdminAddress); - keepWhatsRaised.withdraw(0); + keepWhatsRaised.withdraw(address(testToken), 0); uint256 ownerBalanceAfter = testToken.balanceOf(owner); @@ -646,7 +651,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te // Withdraw partial amount before deadline (as platform admin) vm.warp(LAUNCH_TIME + 1 days); vm.prank(users.platform2AdminAddress); - keepWhatsRaised.withdraw(partialAmount); + keepWhatsRaised.withdraw(address(testToken), partialAmount); uint256 availableAfter = keepWhatsRaised.getAvailableRaisedAmount(); @@ -660,7 +665,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(DEADLINE + 1); vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedDisabled.selector); vm.prank(users.platform2AdminAddress); - keepWhatsRaised.withdraw(0); + keepWhatsRaised.withdraw(address(testToken), 0); } function testWithdrawRevertWhenAmountExceedsAvailable() public { @@ -674,7 +679,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(LAUNCH_TIME + 1 days); vm.expectRevert(); vm.prank(users.platform2AdminAddress); - keepWhatsRaised.withdraw(available + 1e18); + keepWhatsRaised.withdraw(address(testToken), available + 1e18); } function testWithdrawRevertWhenAlreadyWithdrawn() public { @@ -686,12 +691,12 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te // First withdrawal vm.warp(DEADLINE + 1); vm.prank(users.platform2AdminAddress); - keepWhatsRaised.withdraw(0); + keepWhatsRaised.withdraw(address(testToken), 0); // Second withdrawal attempt vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedAlreadyWithdrawn.selector); vm.prank(users.platform2AdminAddress); - keepWhatsRaised.withdraw(0); + keepWhatsRaised.withdraw(address(testToken), 0); } function testWithdrawRevertWhenPaused() public { @@ -706,7 +711,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(DEADLINE + 1); vm.expectRevert(); vm.prank(users.platform2AdminAddress); - keepWhatsRaised.withdraw(0); + keepWhatsRaised.withdraw(address(testToken), 0); } function testWithdrawWithMinimumFeeExemption() public { @@ -723,7 +728,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), largePledge); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, largePledge, 0); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), largePledge, 0); vm.stopPrank(); uint256 availableAfterPledge = keepWhatsRaised.getAvailableRaisedAmount(); @@ -740,7 +745,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(DEADLINE + 1); vm.prank(users.platform2AdminAddress); - keepWhatsRaised.withdraw(0); + keepWhatsRaised.withdraw(address(testToken), 0); uint256 ownerBalanceAfter = testToken.balanceOf(owner); uint256 received = ownerBalanceAfter - ownerBalanceBefore; @@ -762,7 +767,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); vm.stopPrank(); // Approve withdrawal @@ -776,7 +781,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te // Withdraw after deadline vm.warp(DEADLINE + 1); vm.prank(users.platform2AdminAddress); - keepWhatsRaised.withdraw(0); + keepWhatsRaised.withdraw(address(testToken), 0); uint256 ownerBalanceAfter = testToken.balanceOf(owner); uint256 received = ownerBalanceAfter - ownerBalanceBefore; @@ -803,7 +808,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); uint256 tokenId = 0; vm.stopPrank(); @@ -833,7 +838,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); uint256 tokenId = 0; vm.stopPrank(); @@ -851,7 +856,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); uint256 tokenId = 0; vm.stopPrank(); @@ -883,7 +888,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); uint256 tokenId = 0; vm.stopPrank(); @@ -903,7 +908,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); uint256 tokenId = 0; vm.stopPrank(); @@ -912,7 +917,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te keepWhatsRaised.approveWithdrawal(); vm.warp(DEADLINE + 1); vm.prank(users.platform2AdminAddress); - keepWhatsRaised.withdraw(0); + keepWhatsRaised.withdraw(address(testToken), 0); // Try to claim refund vm.warp(DEADLINE + 1 days); @@ -1057,7 +1062,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(DEADLINE + 1); vm.prank(users.platform2AdminAddress); - keepWhatsRaised.withdraw(0); + keepWhatsRaised.withdraw(address(testToken), 0); uint256 protocolBalanceBefore = testToken.balanceOf(users.protocolAdminAddress); uint256 platformBalanceBefore = testToken.balanceOf(users.platform2AdminAddress); @@ -1077,7 +1082,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te keepWhatsRaised.approveWithdrawal(); vm.warp(DEADLINE + 1); vm.prank(users.platform2AdminAddress); - keepWhatsRaised.withdraw(0); + keepWhatsRaised.withdraw(address(testToken), 0); _pauseTreasury(); @@ -1099,7 +1104,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(LAUNCH_TIME); vm.expectRevert(); vm.prank(users.backer1Address); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); } function testCancelTreasuryByCampaignOwner() public { @@ -1113,7 +1118,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(LAUNCH_TIME); vm.expectRevert(); vm.prank(users.backer1Address); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); } function testCancelTreasuryRevertWhenUnauthorized() public { @@ -1142,7 +1147,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(LAUNCH_TIME + 1 days); uint256 availableBefore1 = keepWhatsRaised.getAvailableRaisedAmount(); vm.prank(users.platform2AdminAddress); - keepWhatsRaised.withdraw(firstWithdrawal); + keepWhatsRaised.withdraw(address(testToken), firstWithdrawal); uint256 availableAfter1 = keepWhatsRaised.getAvailableRaisedAmount(); // Verify first withdrawal reduced available amount by withdrawal + fees @@ -1158,7 +1163,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(LAUNCH_TIME + 2 days); uint256 availableBefore2 = keepWhatsRaised.getAvailableRaisedAmount(); vm.prank(users.platform2AdminAddress); - keepWhatsRaised.withdraw(secondWithdrawal); + keepWhatsRaised.withdraw(address(testToken), secondWithdrawal); uint256 availableAfter2 = keepWhatsRaised.getAvailableRaisedAmount(); // Verify second withdrawal reduced available amount by withdrawal + fees @@ -1178,7 +1183,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), smallPledge); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, smallPledge, 0); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), smallPledge, 0); vm.stopPrank(); vm.prank(users.platform2AdminAddress); @@ -1191,7 +1196,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te // Try to withdraw an amount that with fees would exceed available uint256 withdrawAmount = available - 50e18; // Leave less than cumulative fee vm.expectRevert(); - keepWhatsRaised.withdraw(withdrawAmount); + keepWhatsRaised.withdraw(address(testToken), withdrawAmount); } function testZeroTipPledge() public { @@ -1200,7 +1205,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); vm.stopPrank(); assertEq(keepWhatsRaised.getRaisedAmount(), TEST_PLEDGE_AMOUNT); @@ -1213,7 +1218,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); vm.stopPrank(); uint256 available = keepWhatsRaised.getAvailableRaisedAmount(); @@ -1240,7 +1245,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(DEADLINE + 1); vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedAlreadyWithdrawn.selector); vm.prank(users.platform2AdminAddress); - keepWhatsRaised.withdraw(0); + keepWhatsRaised.withdraw(address(testToken), 0); } /*////////////////////////////////////////////////////////////// @@ -1265,7 +1270,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT + TEST_TIP_AMOUNT); bytes32[] memory rewardSelection = new bytes32[](1); rewardSelection[0] = TEST_REWARD_NAME; - keepWhatsRaised.pledgeForAReward(keccak256("pledge1"), users.backer1Address, TEST_TIP_AMOUNT, rewardSelection); + keepWhatsRaised.pledgeForAReward(keccak256("pledge1"), users.backer1Address, address(testToken), TEST_TIP_AMOUNT, rewardSelection); vm.stopPrank(); // Pledge 2: Without reward, different gateway fee @@ -1273,7 +1278,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("pledge2"), differentGatewayFee); vm.startPrank(users.backer2Address); testToken.approve(address(keepWhatsRaised), 2000e18); - keepWhatsRaised.pledgeWithoutAReward(keccak256("pledge2"), users.backer2Address, 2000e18, 0); + keepWhatsRaised.pledgeWithoutAReward(keccak256("pledge2"), users.backer2Address, address(testToken), 2000e18, 0); vm.stopPrank(); // Verify total raised and available amounts @@ -1293,7 +1298,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(LAUNCH_TIME + 1 days); vm.prank(users.platform2AdminAddress); - keepWhatsRaised.withdraw(partialWithdrawAmount); + keepWhatsRaised.withdraw(address(testToken), partialWithdrawAmount); uint256 ownerBalanceAfter = testToken.balanceOf(owner); uint256 netReceived = ownerBalanceAfter - ownerBalanceBefore; @@ -1312,7 +1317,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), smallAmount); - keepWhatsRaised.pledgeWithoutAReward(keccak256("small"), users.backer1Address, smallAmount, 0); + keepWhatsRaised.pledgeWithoutAReward(keccak256("small"), users.backer1Address, address(testToken), smallAmount, 0); vm.stopPrank(); vm.prank(users.platform2AdminAddress); @@ -1327,7 +1332,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te // Withdraw before deadline - should apply cumulative fee vm.warp(LAUNCH_TIME + 1 days); vm.prank(users.platform2AdminAddress); - keepWhatsRaised.withdraw(availableBeforeWithdraw - uint256(CUMULATIVE_FLAT_FEE_VALUE) - 10); // Leave small buffer + keepWhatsRaised.withdraw(address(testToken), availableBeforeWithdraw - uint256(CUMULATIVE_FLAT_FEE_VALUE) - 10); // Leave small buffer uint256 received = testToken.balanceOf(owner) - balanceBefore; @@ -1400,13 +1405,13 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT + TEST_TIP_AMOUNT); bytes32[] memory rewardSelection = new bytes32[](1); rewardSelection[0] = TEST_REWARD_NAME; - keepWhatsRaised.pledgeForAReward(keccak256("pledge1"), users.backer1Address, TEST_TIP_AMOUNT, rewardSelection); + keepWhatsRaised.pledgeForAReward(keccak256("pledge1"), users.backer1Address, address(testToken), TEST_TIP_AMOUNT, rewardSelection); vm.stopPrank(); // Backer 2 pledge without reward vm.startPrank(users.backer2Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT + TEST_TIP_AMOUNT); - keepWhatsRaised.pledgeWithoutAReward(keccak256("pledge2"), users.backer2Address, TEST_PLEDGE_AMOUNT, TEST_TIP_AMOUNT); + keepWhatsRaised.pledgeWithoutAReward(keccak256("pledge2"), users.backer2Address, address(testToken), TEST_PLEDGE_AMOUNT, TEST_TIP_AMOUNT); vm.stopPrank(); } @@ -1426,4 +1431,343 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te feeValues.grossPercentageFeeValues[1] = uint256(VAKI_COMMISSION_VALUE); return feeValues; } + + /*////////////////////////////////////////////////////////////// + MULTI-TOKEN SPECIFIC TESTS + //////////////////////////////////////////////////////////////*/ + + function test_pledgeWithMultipleTokenTypes() public { + _setupReward(); + + // Pledge with USDC + uint256 usdcAmount = getTokenAmount(address(usdcToken), TEST_PLEDGE_AMOUNT); + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("usdc_pledge"), 0); + + vm.warp(LAUNCH_TIME); + vm.startPrank(users.backer1Address); + usdcToken.approve(address(keepWhatsRaised), usdcAmount); + keepWhatsRaised.pledgeWithoutAReward( + keccak256("usdc_pledge"), + users.backer1Address, + address(usdcToken), + usdcAmount, + 0 + ); + vm.stopPrank(); + + // Pledge with cUSD + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("cusd_pledge"), 0); + + vm.startPrank(users.backer2Address); + cUSDToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); + keepWhatsRaised.pledgeWithoutAReward( + keccak256("cusd_pledge"), + users.backer2Address, + address(cUSDToken), + TEST_PLEDGE_AMOUNT, + 0 + ); + vm.stopPrank(); + + // Verify raised amount is normalized + uint256 totalRaised = keepWhatsRaised.getRaisedAmount(); + assertEq(totalRaised, TEST_PLEDGE_AMOUNT * 2, "Should normalize to same value"); + } + + function test_withdrawMultipleTokensCorrectly() public { + _setupReward(); + + // Use larger amounts to ensure enough remains after fees + uint256 largeAmount = 100_000e18; // 100k base amount + uint256 usdcAmount = getTokenAmount(address(usdcToken), largeAmount); + uint256 cUSDAmount = largeAmount; + + // Pledge with USDC + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("usdc"), 0); + + vm.warp(LAUNCH_TIME); + vm.startPrank(users.backer1Address); + deal(address(usdcToken), users.backer1Address, usdcAmount); // Ensure enough tokens + usdcToken.approve(address(keepWhatsRaised), usdcAmount); + keepWhatsRaised.pledgeWithoutAReward( + keccak256("usdc"), + users.backer1Address, + address(usdcToken), + usdcAmount, + 0 + ); + vm.stopPrank(); + + // Pledge with cUSD + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("cusd"), 0); + + vm.startPrank(users.backer2Address); + deal(address(cUSDToken), users.backer2Address, cUSDAmount); // Ensure enough tokens + cUSDToken.approve(address(keepWhatsRaised), cUSDAmount); + keepWhatsRaised.pledgeWithoutAReward( + keccak256("cusd"), + users.backer2Address, + address(cUSDToken), + cUSDAmount, + 0 + ); + vm.stopPrank(); + + // Approve withdrawal + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.approveWithdrawal(); + + address owner = CampaignInfo(campaignAddress).owner(); + uint256 ownerUSDCBefore = usdcToken.balanceOf(owner); + uint256 ownerCUSDBefore = cUSDToken.balanceOf(owner); + + // Withdraw USDC + vm.warp(DEADLINE + 1); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.withdraw(address(usdcToken), 0); + + // Withdraw cUSD + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.withdraw(address(cUSDToken), 0); + + // Verify withdrawals + assertTrue(usdcToken.balanceOf(owner) > ownerUSDCBefore, "Should receive USDC"); + assertTrue(cUSDToken.balanceOf(owner) > ownerCUSDBefore, "Should receive cUSD"); + } + + function test_disburseFeesForMultipleTokens() public { + _setupReward(); + + // Make pledges with different tokens + uint256 usdcAmount = getTokenAmount(address(usdcToken), PLEDGE_AMOUNT); + uint256 usdtAmount = getTokenAmount(address(usdtToken), PLEDGE_AMOUNT); + + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("usdc"), 0); + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("usdt"), 0); + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("cusd"), 0); + + vm.warp(LAUNCH_TIME); + + // USDC pledge + vm.startPrank(users.backer1Address); + usdcToken.approve(address(keepWhatsRaised), usdcAmount); + keepWhatsRaised.pledgeWithoutAReward(keccak256("usdc"), users.backer1Address, address(usdcToken), usdcAmount, 0); + vm.stopPrank(); + + // USDT pledge + vm.startPrank(users.backer2Address); + usdtToken.approve(address(keepWhatsRaised), usdtAmount); + keepWhatsRaised.pledgeWithoutAReward(keccak256("usdt"), users.backer2Address, address(usdtToken), usdtAmount, 0); + vm.stopPrank(); + + // cUSD pledge + vm.startPrank(users.backer1Address); + cUSDToken.approve(address(keepWhatsRaised), PLEDGE_AMOUNT); + keepWhatsRaised.pledgeWithoutAReward(keccak256("cusd"), users.backer1Address, address(cUSDToken), PLEDGE_AMOUNT, 0); + vm.stopPrank(); + + // Approve and make partial withdrawal to generate fees + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.approveWithdrawal(); + + vm.warp(DEADLINE + 1); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.withdraw(address(cUSDToken), 0); + + // Track balances before disbursement + uint256 protocolUSDCBefore = usdcToken.balanceOf(users.protocolAdminAddress); + uint256 protocolUSDTBefore = usdtToken.balanceOf(users.protocolAdminAddress); + uint256 protocolCUSDBefore = cUSDToken.balanceOf(users.protocolAdminAddress); + + uint256 platformUSDCBefore = usdcToken.balanceOf(users.platform2AdminAddress); + uint256 platformUSDTBefore = usdtToken.balanceOf(users.platform2AdminAddress); + uint256 platformCUSDBefore = cUSDToken.balanceOf(users.platform2AdminAddress); + + // Disburse fees + keepWhatsRaised.disburseFees(); + + // Verify fees were distributed for all tokens + assertTrue(usdcToken.balanceOf(users.protocolAdminAddress) > protocolUSDCBefore, "Should receive USDC protocol fees"); + assertTrue(usdtToken.balanceOf(users.protocolAdminAddress) > protocolUSDTBefore, "Should receive USDT protocol fees"); + assertTrue(cUSDToken.balanceOf(users.protocolAdminAddress) > protocolCUSDBefore, "Should receive cUSD protocol fees"); + + assertTrue(usdcToken.balanceOf(users.platform2AdminAddress) > platformUSDCBefore, "Should receive USDC platform fees"); + assertTrue(usdtToken.balanceOf(users.platform2AdminAddress) > platformUSDTBefore, "Should receive USDT platform fees"); + assertTrue(cUSDToken.balanceOf(users.platform2AdminAddress) > platformCUSDBefore, "Should receive cUSD platform fees"); + } + + function test_refundReturnsCorrectToken() public { + _setupReward(); + + // Backer1 pledges with USDC + uint256 usdcAmount = getTokenAmount(address(usdcToken), TEST_PLEDGE_AMOUNT); + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("usdc_pledge"), 0); + + vm.warp(LAUNCH_TIME); + vm.startPrank(users.backer1Address); + usdcToken.approve(address(keepWhatsRaised), usdcAmount); + keepWhatsRaised.pledgeWithoutAReward(keccak256("usdc_pledge"), users.backer1Address, address(usdcToken), usdcAmount, 0); + uint256 usdcTokenId = 0; + vm.stopPrank(); + + // Backer2 pledges with cUSD + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("cusd_pledge"), 0); + + vm.startPrank(users.backer2Address); + cUSDToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); + keepWhatsRaised.pledgeWithoutAReward(keccak256("cusd_pledge"), users.backer2Address, address(cUSDToken), TEST_PLEDGE_AMOUNT, 0); + uint256 cUSDTokenId = 1; + vm.stopPrank(); + + uint256 backer1USDCBefore = usdcToken.balanceOf(users.backer1Address); + uint256 backer2CUSDBefore = cUSDToken.balanceOf(users.backer2Address); + + // Claim refunds after deadline + vm.warp(DEADLINE + 1); + + vm.prank(users.backer1Address); + keepWhatsRaised.claimRefund(usdcTokenId); + + vm.prank(users.backer2Address); + keepWhatsRaised.claimRefund(cUSDTokenId); + + // Verify correct tokens were refunded (should get something back even after fees) + assertTrue(usdcToken.balanceOf(users.backer1Address) > backer1USDCBefore, "Should refund USDC"); + assertTrue(cUSDToken.balanceOf(users.backer2Address) > backer2CUSDBefore, "Should refund cUSD"); + } + + function test_claimTipWithMultipleTokens() public { + _setupReward(); + + uint256 tipAmountUSDC = getTokenAmount(address(usdcToken), TIP_AMOUNT); + uint256 tipAmountCUSD = TIP_AMOUNT; + + // Pledge with USDC + tip + uint256 usdcPledge = getTokenAmount(address(usdcToken), TEST_PLEDGE_AMOUNT); + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("usdc"), 0); + + vm.warp(LAUNCH_TIME); + vm.startPrank(users.backer1Address); + usdcToken.approve(address(keepWhatsRaised), usdcPledge + tipAmountUSDC); + keepWhatsRaised.pledgeWithoutAReward(keccak256("usdc"), users.backer1Address, address(usdcToken), usdcPledge, tipAmountUSDC); + vm.stopPrank(); + + // Pledge with cUSD + tip + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("cusd"), 0); + + vm.startPrank(users.backer2Address); + cUSDToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT + tipAmountCUSD); + keepWhatsRaised.pledgeWithoutAReward(keccak256("cusd"), users.backer2Address, address(cUSDToken), TEST_PLEDGE_AMOUNT, tipAmountCUSD); + vm.stopPrank(); + + uint256 platformUSDCBefore = usdcToken.balanceOf(users.platform2AdminAddress); + uint256 platformCUSDBefore = cUSDToken.balanceOf(users.platform2AdminAddress); + + // Claim tips + vm.warp(DEADLINE + 1); + vm.prank(users.platform2AdminAddress); + keepWhatsRaised.claimTip(); + + // Verify tips in both tokens + assertEq( + usdcToken.balanceOf(users.platform2AdminAddress) - platformUSDCBefore, + tipAmountUSDC, + "Should receive USDC tips" + ); + assertEq( + cUSDToken.balanceOf(users.platform2AdminAddress) - platformCUSDBefore, + tipAmountCUSD, + "Should receive cUSD tips" + ); + } + + function test_mixedTokenPledgesWithDecimalNormalization() public { + _setupReward(); + + // Make three pledges with same normalized value but different decimals + uint256 baseAmount = 1000e18; + uint256 usdcAmount = baseAmount / 1e12; // 6 decimals + uint256 usdtAmount = baseAmount / 1e12; // 6 decimals + uint256 cUSDAmount = baseAmount; // 18 decimals + + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("p1"), 0); + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("p2"), 0); + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("p3"), 0); + + vm.warp(LAUNCH_TIME); + + // USDC pledge + vm.startPrank(users.backer1Address); + usdcToken.approve(address(keepWhatsRaised), usdcAmount); + keepWhatsRaised.pledgeWithoutAReward(keccak256("p1"), users.backer1Address, address(usdcToken), usdcAmount, 0); + vm.stopPrank(); + + uint256 raisedAfterUSDC = keepWhatsRaised.getRaisedAmount(); + assertEq(raisedAfterUSDC, baseAmount, "USDC should normalize to base amount"); + + // USDT pledge + vm.startPrank(users.backer2Address); + usdtToken.approve(address(keepWhatsRaised), usdtAmount); + keepWhatsRaised.pledgeWithoutAReward(keccak256("p2"), users.backer2Address, address(usdtToken), usdtAmount, 0); + vm.stopPrank(); + + uint256 raisedAfterUSDT = keepWhatsRaised.getRaisedAmount(); + assertEq(raisedAfterUSDT, baseAmount * 2, "USDT should normalize to base amount"); + + // cUSD pledge + vm.startPrank(users.backer1Address); + cUSDToken.approve(address(keepWhatsRaised), cUSDAmount); + keepWhatsRaised.pledgeWithoutAReward(keccak256("p3"), users.backer1Address, address(cUSDToken), cUSDAmount, 0); + vm.stopPrank(); + + uint256 finalRaised = keepWhatsRaised.getRaisedAmount(); + assertEq(finalRaised, baseAmount * 3, "All pledges should contribute equally after normalization"); + } + + function testPaymentGatewayFeeWithDifferentDecimalTokens() public { + // Test that payment gateway fee is properly denormalized for different decimal tokens + uint256 baseAmount = 1000e18; // 1000 tokens in 18 decimals + uint256 usdtAmount = baseAmount / 1e12; // 1000 USDT (6 decimals) + uint256 usdcAmount = baseAmount / 1e12; // 1000 USDC (6 decimals) + + // Set payment gateway fee (stored in 18 decimals) + uint256 gatewayFee18Decimals = 40e18; // 40 tokens in 18 decimals + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("usdt_pledge"), gatewayFee18Decimals); + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("usdc_pledge"), gatewayFee18Decimals); + + vm.warp(LAUNCH_TIME); + + // USDT pledge + vm.startPrank(users.backer1Address); + usdtToken.approve(address(keepWhatsRaised), usdtAmount); + keepWhatsRaised.pledgeWithoutAReward(keccak256("usdt_pledge"), users.backer1Address, address(usdtToken), usdtAmount, 0); + vm.stopPrank(); + + // USDC pledge + vm.startPrank(users.backer2Address); + usdcToken.approve(address(keepWhatsRaised), usdcAmount); + keepWhatsRaised.pledgeWithoutAReward(keccak256("usdc_pledge"), users.backer2Address, address(usdcToken), usdcAmount, 0); + vm.stopPrank(); + + // Verify that both pledges contribute equally to raised amount (normalized) + uint256 raisedAmount = keepWhatsRaised.getRaisedAmount(); + assertEq(raisedAmount, baseAmount * 2, "Both 6-decimal token pledges should normalize to same 18-decimal amount"); + + // Verify that the payment gateway fees were properly denormalized + // For 6-decimal tokens, 40e18 should become 40e6 + uint256 expectedGatewayFee6Decimals = 40e6; + + // Check that fees were calculated correctly by checking available amount + uint256 availableAmount = keepWhatsRaised.getAvailableRaisedAmount(); + + // Calculate expected available amount after fees + uint256 platformFee = (baseAmount * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 vakiCommission = (baseAmount * uint256(VAKI_COMMISSION_VALUE)) / PERCENT_DIVIDER; + uint256 protocolFee = (baseAmount * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 gatewayFeeNormalized = expectedGatewayFee6Decimals * 1e12; // Convert 6-decimal fee to 18-decimal for comparison + + uint256 expectedAvailable = (baseAmount * 2) - (platformFee * 2) - (vakiCommission * 2) - (protocolFee * 2) - (gatewayFeeNormalized * 2); + + assertEq(availableAmount, expectedAvailable, "Available amount should account for properly denormalized gateway fees"); + } } \ No newline at end of file diff --git a/test/foundry/unit/PaymentTreasury.t.sol b/test/foundry/unit/PaymentTreasury.t.sol index 14f87c8e..5b6ad076 100644 --- a/test/foundry/unit/PaymentTreasury.t.sol +++ b/test/foundry/unit/PaymentTreasury.t.sol @@ -1,10 +1,11 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import "../integration/PaymentTreasury/PaymentTreasury.t.sol"; import "forge-std/Test.sol"; import {PaymentTreasury} from "src/treasuries/PaymentTreasury.sol"; import {CampaignInfo} from "src/CampaignInfo.sol"; +import {TestToken} from "../../mocks/TestToken.sol"; contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Test { @@ -74,6 +75,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, + address(testToken), // Added token parameter PAYMENT_AMOUNT_1, expiration ); @@ -90,6 +92,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, + address(testToken), PAYMENT_AMOUNT_1, expiration ); @@ -103,6 +106,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te PAYMENT_ID_1, bytes32(0), ITEM_ID_1, + address(testToken), PAYMENT_AMOUNT_1, expiration ); @@ -116,6 +120,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, + address(testToken), 0, expiration ); @@ -128,6 +133,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, + address(testToken), PAYMENT_AMOUNT_1, block.timestamp - 1 ); @@ -141,6 +147,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te bytes32(0), BUYER_ID_1, ITEM_ID_1, + address(testToken), PAYMENT_AMOUNT_1, expiration ); @@ -154,6 +161,38 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te PAYMENT_ID_1, BUYER_ID_1, bytes32(0), + address(testToken), + PAYMENT_AMOUNT_1, + expiration + ); + } + + function testCreatePaymentRevertWhenZeroTokenAddress() public { + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(0), // Zero token address + PAYMENT_AMOUNT_1, + expiration + ); + } + + function testCreatePaymentRevertWhenTokenNotAccepted() public { + // Create unaccepted token + TestToken unacceptedToken = new TestToken("Unaccepted", "UNACC", 18); + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(unacceptedToken), PAYMENT_AMOUNT_1, expiration ); @@ -166,6 +205,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, + address(testToken), PAYMENT_AMOUNT_1, expiration ); @@ -174,6 +214,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te PAYMENT_ID_1, BUYER_ID_2, ITEM_ID_2, + address(testToken), PAYMENT_AMOUNT_2, expiration ); @@ -193,6 +234,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, + address(testToken), PAYMENT_AMOUNT_1, expiration ); @@ -211,6 +253,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, + address(testToken), PAYMENT_AMOUNT_1, expiration ); @@ -227,7 +270,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.backer1Address); testToken.approve(treasuryAddress, amount); - processCryptoPayment(users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, amount); + processCryptoPayment(users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), amount); assertEq(paymentTreasury.getRaisedAmount(), amount); assertEq(paymentTreasury.getAvailableRaisedAmount(), amount); @@ -236,12 +279,12 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testProcessCryptoPaymentRevertWhenZeroBuyerAddress() public { vm.expectRevert(); - processCryptoPayment(users.platform1AdminAddress, PAYMENT_ID_1, ITEM_ID_1, address(0), 1000e18); + processCryptoPayment(users.platform1AdminAddress, PAYMENT_ID_1, ITEM_ID_1, address(0), address(testToken), 1000e18); } function testProcessCryptoPaymentRevertWhenZeroAmount() public { vm.expectRevert(); - processCryptoPayment(users.platform1AdminAddress, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, 0); + processCryptoPayment(users.platform1AdminAddress, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), 0); } function testProcessCryptoPaymentRevertWhenPaymentExists() public { @@ -251,10 +294,10 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.backer1Address); testToken.approve(treasuryAddress, amount * 2); - processCryptoPayment(users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, amount); + processCryptoPayment(users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), amount); vm.expectRevert(); - processCryptoPayment(users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, amount); + processCryptoPayment(users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), amount); } /*////////////////////////////////////////////////////////////// @@ -269,6 +312,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, + address(testToken), PAYMENT_AMOUNT_1, expiration ); @@ -288,7 +332,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testCancelPaymentRevertWhenAlreadyConfirmed() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter vm.expectRevert(); vm.prank(users.platform1AdminAddress); @@ -302,6 +346,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, + address(testToken), PAYMENT_AMOUNT_1, expiration ); @@ -329,7 +374,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testConfirmPayment() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter assertEq(paymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1); assertEq(paymentTreasury.getAvailableRaisedAmount(), PAYMENT_AMOUNT_1); @@ -346,7 +391,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te paymentIds[2] = PAYMENT_ID_3; vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPaymentBatch(paymentIds); + paymentTreasury.confirmPaymentBatch(paymentIds); // Removed token array uint256 totalAmount = PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2 + 500e18; assertEq(paymentTreasury.getRaisedAmount(), totalAmount); @@ -356,16 +401,16 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testConfirmPaymentRevertWhenNotExists() public { vm.expectRevert(); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter } function testConfirmPaymentRevertWhenAlreadyConfirmed() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.startPrank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter vm.expectRevert(); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter vm.stopPrank(); } @@ -375,7 +420,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.expectRevert(); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter } /*////////////////////////////////////////////////////////////// @@ -385,7 +430,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testClaimRefund() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter uint256 balanceBefore = testToken.balanceOf(users.backer1Address); @@ -437,6 +482,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, + address(testToken), PAYMENT_AMOUNT_1, expiration ); @@ -454,7 +500,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testClaimRefundRevertWhenPaused() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter // Pause treasury vm.prank(users.platform1AdminAddress); @@ -481,7 +527,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testDisburseFees() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter // Withdraw first to calculate fees paymentTreasury.withdraw(); @@ -502,14 +548,14 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te _createAndFundPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, PAYMENT_AMOUNT_2, users.backer2Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter // First withdrawal and disbursement paymentTreasury.withdraw(); paymentTreasury.disburseFees(); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_2); + paymentTreasury.confirmPayment(PAYMENT_ID_2); // Removed token parameter // Second withdrawal and disbursement paymentTreasury.withdraw(); @@ -519,7 +565,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testDisburseFeesRevertWhenPaused() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter paymentTreasury.withdraw(); @@ -538,7 +584,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testWithdraw() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter address owner = CampaignInfo(campaignAddress).owner(); uint256 ownerBalanceBefore = testToken.balanceOf(owner); @@ -558,7 +604,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testWithdrawRevertWhenAlreadyWithdrawn() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter paymentTreasury.withdraw(); paymentTreasury.disburseFees(); @@ -570,7 +616,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testWithdrawRevertWhenPaused() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter // Pause treasury vm.prank(users.platform1AdminAddress); @@ -588,7 +634,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te // First create and confirm a payment to test functions that require it _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter // Pause the treasury vm.prank(users.platform1AdminAddress); @@ -611,6 +657,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te PAYMENT_ID_2, BUYER_ID_1, ITEM_ID_2, + address(testToken), PAYMENT_AMOUNT_2, expiration ); @@ -630,6 +677,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, + address(testToken), PAYMENT_AMOUNT_1, expiration ); @@ -638,7 +686,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testCancelTreasuryByPlatformAdmin() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter vm.prank(users.platform1AdminAddress); paymentTreasury.cancelTreasury(keccak256("Cancel")); @@ -653,6 +701,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te PAYMENT_ID_2, BUYER_ID_1, ITEM_ID_2, + address(testToken), PAYMENT_AMOUNT_2, expiration ); @@ -661,7 +710,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testCancelTreasuryByCampaignOwner() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter address owner = CampaignInfo(campaignAddress).owner(); vm.prank(owner); @@ -677,6 +726,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te PAYMENT_ID_2, BUYER_ID_1, ITEM_ID_2, + address(testToken), PAYMENT_AMOUNT_2, expiration ); @@ -705,7 +755,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te paymentIds[2] = PAYMENT_ID_3; vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPaymentBatch(paymentIds); + paymentTreasury.confirmPaymentBatch(paymentIds); // Removed token array uint256 totalAmount = PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2 + 500e18; assertEq(paymentTreasury.getRaisedAmount(), totalAmount); @@ -728,8 +778,8 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te _createAndFundPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, PAYMENT_AMOUNT_2, users.backer2Address); vm.startPrank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); - paymentTreasury.confirmPayment(PAYMENT_ID_2); + paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_2); // Removed token parameter // Refund all payments paymentTreasury.claimRefund(PAYMENT_ID_1, users.backer1Address); @@ -754,6 +804,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, + address(testToken), PAYMENT_AMOUNT_1, shortExpiration ); @@ -761,6 +812,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, + address(testToken), PAYMENT_AMOUNT_2, longExpiration ); @@ -774,7 +826,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te testToken.transfer(treasuryAddress, PAYMENT_AMOUNT_2); // Confirm first payment before expiration vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter // Warp past first expiration but before second vm.warp(shortExpiration + 1); // Cannot cancel or confirm expired payment @@ -783,7 +835,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te paymentTreasury.cancelPayment(PAYMENT_ID_1); // Can still confirm non-expired payment vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_2); + paymentTreasury.confirmPayment(PAYMENT_ID_2); // Removed token parameter assertEq(paymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2); } @@ -795,7 +847,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te // Confirm regular payment vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter // Both should contribute to raised amount uint256 totalAmount = PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2; @@ -810,13 +862,14 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te } function testCannotCreatePhantomBalances() public { - // Create payment for 1000 USDC + // Create payment for 1000 tokens with USDC specified uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, + address(testToken), // Token specified during creation 1000e18, expiration ); @@ -839,11 +892,11 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te } function testCannotConfirmMoreThanBalance() public { - // Create two payments of 500 each + // Create two payments of 500 each, both with testToken uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.startPrank(users.platform1AdminAddress); - paymentTreasury.createPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, 500e18, expiration); - paymentTreasury.createPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, 500e18, expiration); + paymentTreasury.createPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, address(testToken), 500e18, expiration); + paymentTreasury.createPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, address(testToken), 500e18, expiration); vm.stopPrank(); // Send only 500 tokens total @@ -853,12 +906,12 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te // Can confirm one payment vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter // Cannot confirm second payment - total would exceed balance vm.expectRevert(); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_2); + paymentTreasury.confirmPayment(PAYMENT_ID_2); // Removed token parameter assertEq(paymentTreasury.getRaisedAmount(), 500e18); } @@ -867,8 +920,8 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te // Create two payments uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.startPrank(users.platform1AdminAddress); - paymentTreasury.createPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, 500e18, expiration); - paymentTreasury.createPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, 500e18, expiration); + paymentTreasury.createPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, address(testToken), 500e18, expiration); + paymentTreasury.createPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, address(testToken), 500e18, expiration); vm.stopPrank(); // Send only 500 tokens @@ -882,7 +935,362 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te paymentIds[1] = PAYMENT_ID_2; vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPaymentBatch(paymentIds); // Removed token array + } + + /*////////////////////////////////////////////////////////////// + MULTI-TOKEN SPECIFIC UNIT TESTS + //////////////////////////////////////////////////////////////*/ + + function testConfirmPaymentWithDifferentTokens() public { + // Create payments expecting different tokens + uint256 usdtAmount = getTokenAmount(address(usdtToken), 500e18); + uint256 cUSDAmount = 700e18; + + // Create USDT payment - token specified during creation + _createAndFundPaymentWithToken( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + usdtAmount, + users.backer1Address, + address(usdtToken) + ); + + // Create cUSD payment - token specified during creation + _createAndFundPaymentWithToken( + PAYMENT_ID_2, + BUYER_ID_2, + ITEM_ID_2, + cUSDAmount, + users.backer2Address, + address(cUSDToken) + ); + + // Confirm without specifying token + vm.startPrank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_2); + vm.stopPrank(); + + uint256 expectedTotal = 500e18 + 700e18; + assertEq(paymentTreasury.getRaisedAmount(), expectedTotal); + } + + function testProcessCryptoPaymentWithDifferentTokens() public { + uint256 usdcAmount = getTokenAmount(address(usdcToken), 800e18); + uint256 cUSDAmount = 1200e18; + + // USDC payment + deal(address(usdcToken), users.backer1Address, usdcAmount); + vm.prank(users.backer1Address); + usdcToken.approve(treasuryAddress, usdcAmount); + processCryptoPayment( + users.backer1Address, + PAYMENT_ID_1, + ITEM_ID_1, + users.backer1Address, + address(usdcToken), + usdcAmount + ); + + // cUSD payment + deal(address(cUSDToken), users.backer2Address, cUSDAmount); + vm.prank(users.backer2Address); + cUSDToken.approve(treasuryAddress, cUSDAmount); + processCryptoPayment( + users.backer2Address, + PAYMENT_ID_2, + ITEM_ID_2, + users.backer2Address, + address(cUSDToken), + cUSDAmount + ); + + uint256 expectedTotal = 800e18 + 1200e18; + assertEq(paymentTreasury.getRaisedAmount(), expectedTotal); + assertEq(usdcToken.balanceOf(treasuryAddress), usdcAmount); + assertEq(cUSDToken.balanceOf(treasuryAddress), cUSDAmount); + } + + function testBatchConfirmWithMixedTokens() public { + uint256 usdtAmount = getTokenAmount(address(usdtToken), 500e18); + uint256 usdcAmount = getTokenAmount(address(usdcToken), 600e18); + uint256 cUSDAmount = 700e18; + + // Create payments with tokens specified + _createAndFundPaymentWithToken(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, usdtAmount, users.backer1Address, address(usdtToken)); + _createAndFundPaymentWithToken(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, usdcAmount, users.backer2Address, address(usdcToken)); + _createAndFundPaymentWithToken(PAYMENT_ID_3, BUYER_ID_3, ITEM_ID_1, cUSDAmount, users.backer1Address, address(cUSDToken)); + + // Batch confirm without token array + bytes32[] memory paymentIds = new bytes32[](3); + paymentIds[0] = PAYMENT_ID_1; + paymentIds[1] = PAYMENT_ID_2; + paymentIds[2] = PAYMENT_ID_3; + vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPaymentBatch(paymentIds); + + uint256 expectedTotal = 500e18 + 600e18 + 700e18; + assertEq(paymentTreasury.getRaisedAmount(), expectedTotal); + } + + function testRefundReturnsCorrectTokenType() public { + uint256 usdtAmount = getTokenAmount(address(usdtToken), PAYMENT_AMOUNT_1); + + _createAndFundPaymentWithToken( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + usdtAmount, + users.backer1Address, + address(usdtToken) + ); + + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + + uint256 usdtBefore = usdtToken.balanceOf(users.backer1Address); + uint256 cUSDBefore = cUSDToken.balanceOf(users.backer1Address); + + vm.prank(users.platform1AdminAddress); + paymentTreasury.claimRefund(PAYMENT_ID_1, users.backer1Address); + + // Should receive USDT, not cUSD + assertEq( + usdtToken.balanceOf(users.backer1Address) - usdtBefore, + usdtAmount, + "Should receive USDT" + ); + assertEq( + cUSDToken.balanceOf(users.backer1Address), + cUSDBefore, + "cUSD should be unchanged" + ); + } + + function testWithdrawDistributesAllTokens() public { + uint256 usdtAmount = getTokenAmount(address(usdtToken), 1000e18); + uint256 cUSDAmount = 1500e18; + + _createAndFundPaymentWithToken( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + usdtAmount, + users.backer1Address, + address(usdtToken) + ); + + _createAndFundPaymentWithToken( + PAYMENT_ID_2, + BUYER_ID_2, + ITEM_ID_2, + cUSDAmount, + users.backer2Address, + address(cUSDToken) + ); + + vm.startPrank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_2); + vm.stopPrank(); + + address owner = CampaignInfo(campaignAddress).owner(); + uint256 ownerUSDTBefore = usdtToken.balanceOf(owner); + uint256 ownerCUSDBefore = cUSDToken.balanceOf(owner); + + paymentTreasury.withdraw(); + + // Should receive both tokens + assertTrue(usdtToken.balanceOf(owner) > ownerUSDTBefore, "Should receive USDT"); + assertTrue(cUSDToken.balanceOf(owner) > ownerCUSDBefore, "Should receive cUSD"); + } + + function testDisburseFeesDistributesAllTokens() public { + uint256 usdcAmount = getTokenAmount(address(usdcToken), PAYMENT_AMOUNT_1); + uint256 cUSDAmount = PAYMENT_AMOUNT_2; + + _createAndFundPaymentWithToken( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + usdcAmount, + users.backer1Address, + address(usdcToken) + ); + + _createAndFundPaymentWithToken( + PAYMENT_ID_2, + BUYER_ID_2, + ITEM_ID_2, + cUSDAmount, + users.backer2Address, + address(cUSDToken) + ); + + vm.startPrank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_2); + vm.stopPrank(); + + paymentTreasury.withdraw(); + + uint256 protocolUSDCBefore = usdcToken.balanceOf(users.protocolAdminAddress); + uint256 protocolCUSDBefore = cUSDToken.balanceOf(users.protocolAdminAddress); + uint256 platformUSDCBefore = usdcToken.balanceOf(users.platform1AdminAddress); + uint256 platformCUSDBefore = cUSDToken.balanceOf(users.platform1AdminAddress); + + paymentTreasury.disburseFees(); + + // All token types should have fees disbursed + assertTrue( + usdcToken.balanceOf(users.protocolAdminAddress) > protocolUSDCBefore, + "Should disburse USDC to protocol" + ); + assertTrue( + cUSDToken.balanceOf(users.protocolAdminAddress) > protocolCUSDBefore, + "Should disburse cUSD to protocol" + ); + assertTrue( + usdcToken.balanceOf(users.platform1AdminAddress) > platformUSDCBefore, + "Should disburse USDC to platform" + ); + assertTrue( + cUSDToken.balanceOf(users.platform1AdminAddress) > platformCUSDBefore, + "Should disburse cUSD to platform" + ); + } + + function testDecimalNormalizationAccuracy() public { + // Test that 1000 USDT (6 decimals) = 1000 cUSD (18 decimals) after normalization + uint256 baseAmount = 1000e18; + uint256 usdtAmount = baseAmount / 1e12; // 1000 USDT (1000000000) + uint256 cUSDAmount = baseAmount; // 1000 cUSD (1000000000000000000000) + + _createAndFundPaymentWithToken( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + usdtAmount, + users.backer1Address, + address(usdtToken) + ); + + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + + uint256 raisedAfterUSDT = paymentTreasury.getRaisedAmount(); + assertEq(raisedAfterUSDT, baseAmount, "1000 USDT should equal 1000e18 normalized"); + + _createAndFundPaymentWithToken( + PAYMENT_ID_2, + BUYER_ID_2, + ITEM_ID_2, + cUSDAmount, + users.backer2Address, + address(cUSDToken) + ); + + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_2); + + uint256 totalRaised = paymentTreasury.getRaisedAmount(); + assertEq(totalRaised, baseAmount * 2, "Both should contribute equally"); + } + + function testCannotConfirmWithInsufficientBalancePerToken() public { + uint256 usdtAmount = getTokenAmount(address(usdtToken), 1000e18); + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + + // Create two payments expecting USDT + _createAndFundPaymentWithToken(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, usdtAmount, users.backer1Address, address(usdtToken)); + + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_2, + BUYER_ID_2, + ITEM_ID_2, + address(usdtToken), // Token specified + usdtAmount, + expiration + ); + + // Only funded first payment, second has no tokens + + // Can confirm first + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + + // Cannot confirm second - insufficient USDT balance + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_2); + } + + function testMixedTokenRefundsAfterPartialWithdraw() public { + // This tests the edge case where some tokens are withdrawn but others have pending refunds + uint256 usdtAmount = getTokenAmount(address(usdtToken), 1000e18); + uint256 cUSDAmount = 1500e18; + + _createAndFundPaymentWithToken( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + usdtAmount, + users.backer1Address, + address(usdtToken) + ); + + _createAndFundPaymentWithToken( + PAYMENT_ID_2, + BUYER_ID_2, + ITEM_ID_2, + cUSDAmount, + users.backer2Address, + address(cUSDToken) + ); + + vm.startPrank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_2); + vm.stopPrank(); + + // Withdraw (takes fees) + paymentTreasury.withdraw(); + + // Try to refund - should fail because funds were withdrawn + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.claimRefund(PAYMENT_ID_1, users.backer1Address); + } + + function testZeroBalanceTokensHandledGracefully() public { + // Create payment with USDT only + uint256 usdtAmount = getTokenAmount(address(usdtToken), PAYMENT_AMOUNT_1); + + _createAndFundPaymentWithToken( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + usdtAmount, + users.backer1Address, + address(usdtToken) + ); + + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1); + + // Withdraw should handle zero-balance tokens (USDC, cUSD) gracefully + paymentTreasury.withdraw(); + + // Disburse should also handle it + paymentTreasury.disburseFees(); + + // Verify only USDT was processed + assertEq(usdcToken.balanceOf(treasuryAddress), 0, "USDC should remain zero"); + assertEq(cUSDToken.balanceOf(treasuryAddress), 0, "cUSD should remain zero"); } } \ No newline at end of file diff --git a/test/foundry/unit/TestToken.t.sol b/test/foundry/unit/TestToken.t.sol index 0ba3c4ed..4181e0c5 100644 --- a/test/foundry/unit/TestToken.t.sol +++ b/test/foundry/unit/TestToken.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import "forge-std/Test.sol"; import {TestToken} from "../../mocks/TestToken.sol"; @@ -12,7 +12,7 @@ contract TestToken_UnitTest is Test, Defaults { uint256 internal mintAmount = 1_000 * 1e18; function setUp() public { - token = new TestToken(tokenName, tokenSymbol); + token = new TestToken(tokenName, tokenSymbol, 18); } function testMintIncreasesBalance() public { diff --git a/test/foundry/unit/TreasuryFactory.t.sol b/test/foundry/unit/TreasuryFactory.t.sol index 3a7a6785..489a0fe7 100644 --- a/test/foundry/unit/TreasuryFactory.t.sol +++ b/test/foundry/unit/TreasuryFactory.t.sol @@ -1,9 +1,11 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import "forge-std/Test.sol"; import {TreasuryFactory} from "src/TreasuryFactory.sol"; import {GlobalParams} from "src/GlobalParams.sol"; +import {IGlobalParams} from "src/interfaces/IGlobalParams.sol"; +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; import {TestToken} from "../../mocks/TestToken.sol"; import {Defaults} from "../Base.t.sol"; import {AdminAccessChecker} from "src/utils/AdminAccessChecker.sol"; @@ -24,9 +26,42 @@ contract TreasuryFactory_UpdatedUnitTest is Test, Defaults { uint256 internal platformFee = 300; // 3% function setUp() public { - testToken = new TestToken(tokenName, tokenSymbol); - globalParams = new GlobalParams(protocolAdmin, address(testToken), 300); - factory = new TreasuryFactory(globalParams); + testToken = new TestToken(tokenName, tokenSymbol, 18); + + // Setup currencies and tokens for multi-token support + bytes32[] memory currencies = new bytes32[](1); + currencies[0] = bytes32("USD"); + + address[][] memory tokensPerCurrency = new address[][](1); + tokensPerCurrency[0] = new address[](1); + tokensPerCurrency[0][0] = address(testToken); + + // Deploy GlobalParams with proxy + GlobalParams globalParamsImpl = new GlobalParams(); + bytes memory globalParamsInitData = abi.encodeWithSelector( + GlobalParams.initialize.selector, + protocolAdmin, + 300, + currencies, + tokensPerCurrency + ); + ERC1967Proxy globalParamsProxy = new ERC1967Proxy( + address(globalParamsImpl), + globalParamsInitData + ); + globalParams = GlobalParams(address(globalParamsProxy)); + + // Deploy TreasuryFactory with proxy + TreasuryFactory factoryImpl = new TreasuryFactory(); + bytes memory factoryInitData = abi.encodeWithSelector( + TreasuryFactory.initialize.selector, + IGlobalParams(address(globalParams)) + ); + ERC1967Proxy factoryProxy = new ERC1967Proxy( + address(factoryImpl), + factoryInitData + ); + factory = TreasuryFactory(address(factoryProxy)); // Label addresses for clarity vm.label(protocolAdmin, "ProtocolAdmin"); @@ -132,4 +167,38 @@ contract TreasuryFactory_UpdatedUnitTest is Test, Defaults { ); vm.stopPrank(); } + + function testUpgrade() public { + // Deploy new implementation + TreasuryFactory newImplementation = new TreasuryFactory(); + + // Upgrade as protocol admin + vm.prank(protocolAdmin); + factory.upgradeToAndCall(address(newImplementation), ""); + + // Factory should still work after upgrade + vm.startPrank(platformAdmin); + factory.registerTreasuryImplementation( + platformHash, + implementationId, + implementation + ); + vm.stopPrank(); + } + + function testUpgradeUnauthorizedReverts() public { + // Deploy new implementation + TreasuryFactory newImplementation = new TreasuryFactory(); + + // Try to upgrade as non-protocol-admin (should revert) + vm.prank(other); + vm.expectRevert(); + factory.upgradeToAndCall(address(newImplementation), ""); + } + + function testCannotInitializeTwice() public { + // Try to initialize again (should revert) + vm.expectRevert(); + factory.initialize(IGlobalParams(address(globalParams))); + } } diff --git a/test/foundry/unit/Upgrades.t.sol b/test/foundry/unit/Upgrades.t.sol new file mode 100644 index 00000000..9c594ef0 --- /dev/null +++ b/test/foundry/unit/Upgrades.t.sol @@ -0,0 +1,382 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.22; + +import "forge-std/Test.sol"; +import {GlobalParams} from "src/GlobalParams.sol"; +import {TreasuryFactory} from "src/TreasuryFactory.sol"; +import {CampaignInfoFactory} from "src/CampaignInfoFactory.sol"; +import {CampaignInfo} from "src/CampaignInfo.sol"; +import {IGlobalParams} from "src/interfaces/IGlobalParams.sol"; +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; +import {TestToken} from "../../mocks/TestToken.sol"; +import {Defaults} from "../Base.t.sol"; + +/** + * @title Upgrades_Test + * @notice Comprehensive upgrade tests for all UUPS upgradeable contracts + */ +contract Upgrades_Test is Test, Defaults { + GlobalParams internal globalParams; + TreasuryFactory internal treasuryFactory; + CampaignInfoFactory internal campaignFactory; + TestToken internal testToken; + + address internal admin = address(0xA11CE); + address internal platformAdmin = address(0xBEEF); + address internal attacker = address(0xDEAD); + + bytes32 internal platformHash = keccak256(abi.encodePacked("TEST_PLATFORM")); + uint256 internal protocolFee = 300; + uint256 internal platformFee = 200; + + function setUp() public { + testToken = new TestToken("Test", "TST", 18); + + bytes32[] memory currencies = new bytes32[](1); + currencies[0] = bytes32("USD"); + + address[][] memory tokensPerCurrency = new address[][](1); + tokensPerCurrency[0] = new address[](1); + tokensPerCurrency[0][0] = address(testToken); + + // Deploy GlobalParams with proxy + GlobalParams globalParamsImpl = new GlobalParams(); + bytes memory globalParamsInitData = abi.encodeWithSelector( + GlobalParams.initialize.selector, + admin, + protocolFee, + currencies, + tokensPerCurrency + ); + ERC1967Proxy globalParamsProxy = new ERC1967Proxy( + address(globalParamsImpl), + globalParamsInitData + ); + globalParams = GlobalParams(address(globalParamsProxy)); + + // Deploy TreasuryFactory with proxy + TreasuryFactory treasuryFactoryImpl = new TreasuryFactory(); + bytes memory treasuryFactoryInitData = abi.encodeWithSelector( + TreasuryFactory.initialize.selector, + IGlobalParams(address(globalParams)) + ); + ERC1967Proxy treasuryFactoryProxy = new ERC1967Proxy( + address(treasuryFactoryImpl), + treasuryFactoryInitData + ); + treasuryFactory = TreasuryFactory(address(treasuryFactoryProxy)); + + // Deploy CampaignInfoFactory with proxy + CampaignInfo campaignInfoImpl = new CampaignInfo(); + CampaignInfoFactory campaignFactoryImpl = new CampaignInfoFactory(); + bytes memory campaignFactoryInitData = abi.encodeWithSelector( + CampaignInfoFactory.initialize.selector, + admin, + IGlobalParams(address(globalParams)), + address(campaignInfoImpl), + address(treasuryFactory) + ); + ERC1967Proxy campaignFactoryProxy = new ERC1967Proxy( + address(campaignFactoryImpl), + campaignFactoryInitData + ); + campaignFactory = CampaignInfoFactory(address(campaignFactoryProxy)); + + // Enlist a platform + vm.prank(admin); + globalParams.enlistPlatform(platformHash, platformAdmin, platformFee); + } + + // ============ GlobalParams Upgrade Tests ============ + + function testGlobalParamsUpgrade() public { + // Record initial state + uint256 initialFee = globalParams.getProtocolFeePercent(); + address initialAdmin = globalParams.getProtocolAdminAddress(); + + // Deploy new implementation + GlobalParams newImpl = new GlobalParams(); + + // Upgrade + vm.prank(admin); + globalParams.upgradeToAndCall(address(newImpl), ""); + + // Verify state is preserved + assertEq(globalParams.getProtocolFeePercent(), initialFee); + assertEq(globalParams.getProtocolAdminAddress(), initialAdmin); + + // Verify functionality still works + vm.prank(admin); + globalParams.updateProtocolFeePercent(500); + assertEq(globalParams.getProtocolFeePercent(), 500); + } + + function testGlobalParamsUpgradeUnauthorized() public { + GlobalParams newImpl = new GlobalParams(); + + // Try to upgrade as non-owner + vm.prank(attacker); + vm.expectRevert(); + globalParams.upgradeToAndCall(address(newImpl), ""); + } + + function testGlobalParamsStorageSlotIntegrity() public { + // Add some data + vm.prank(admin); + globalParams.addTokenToCurrency(bytes32("EUR"), address(testToken)); + + // Verify data before upgrade + address[] memory eurTokens = globalParams.getTokensForCurrency(bytes32("EUR")); + assertEq(eurTokens.length, 1); + assertEq(eurTokens[0], address(testToken)); + + // Upgrade + GlobalParams newImpl = new GlobalParams(); + vm.prank(admin); + globalParams.upgradeToAndCall(address(newImpl), ""); + + // Verify data after upgrade + eurTokens = globalParams.getTokensForCurrency(bytes32("EUR")); + assertEq(eurTokens.length, 1); + assertEq(eurTokens[0], address(testToken)); + } + + function testGlobalParamsCannotInitializeTwice() public { + bytes32[] memory currencies = new bytes32[](0); + address[][] memory tokensPerCurrency = new address[][](0); + + vm.expectRevert(); + globalParams.initialize(admin, protocolFee, currencies, tokensPerCurrency); + } + + // ============ TreasuryFactory Upgrade Tests ============ + + function testTreasuryFactoryUpgrade() public { + // Register an implementation + address mockImpl = address(0xC0DE); + vm.prank(platformAdmin); + treasuryFactory.registerTreasuryImplementation(platformHash, 1, mockImpl); + + // Deploy new implementation + TreasuryFactory newImpl = new TreasuryFactory(); + + // Upgrade as protocol admin + vm.prank(admin); + treasuryFactory.upgradeToAndCall(address(newImpl), ""); + + // Verify functionality still works after upgrade + vm.prank(platformAdmin); + treasuryFactory.registerTreasuryImplementation(platformHash, 2, address(0xBEEF)); + } + + function testTreasuryFactoryUpgradeUnauthorized() public { + TreasuryFactory newImpl = new TreasuryFactory(); + + // Try to upgrade as non-protocol-admin + vm.prank(attacker); + vm.expectRevert(); + treasuryFactory.upgradeToAndCall(address(newImpl), ""); + } + + function testTreasuryFactoryStorageSlotIntegrity() public { + // Register and approve an implementation + address mockImpl = address(0xC0DE); + vm.prank(platformAdmin); + treasuryFactory.registerTreasuryImplementation(platformHash, 1, mockImpl); + + vm.prank(admin); + treasuryFactory.approveTreasuryImplementation(platformHash, 1); + + // Upgrade + TreasuryFactory newImpl = new TreasuryFactory(); + vm.prank(admin); + treasuryFactory.upgradeToAndCall(address(newImpl), ""); + + // Verify registered implementations are preserved after upgrade + // by registering another implementation (which proves the mapping still works) + address mockImpl2 = address(0xBEEF); + vm.prank(platformAdmin); + treasuryFactory.registerTreasuryImplementation(platformHash, 2, mockImpl2); + } + + function testTreasuryFactoryCannotInitializeTwice() public { + vm.expectRevert(); + treasuryFactory.initialize(IGlobalParams(address(globalParams))); + } + + // ============ CampaignInfoFactory Upgrade Tests ============ + + function testCampaignInfoFactoryUpgrade() public { + // Create a campaign before upgrade + bytes32[] memory platforms = new bytes32[](1); + platforms[0] = platformHash; + bytes32[] memory keys = new bytes32[](0); + bytes32[] memory values = new bytes32[](0); + + vm.prank(admin); + campaignFactory.createCampaign( + address(0xBEEF), + CAMPAIGN_1_IDENTIFIER_HASH, + platforms, + keys, + values, + CAMPAIGN_DATA + ); + + address campaignBefore = campaignFactory.identifierToCampaignInfo(CAMPAIGN_1_IDENTIFIER_HASH); + assertTrue(campaignBefore != address(0), "Campaign not created"); + + // Deploy new implementation + CampaignInfoFactory newImpl = new CampaignInfoFactory(); + + // Upgrade as owner + vm.prank(admin); + campaignFactory.upgradeToAndCall(address(newImpl), ""); + + // Verify previous campaign is still accessible + address campaignAfter = campaignFactory.identifierToCampaignInfo(CAMPAIGN_1_IDENTIFIER_HASH); + assertEq(campaignAfter, campaignBefore, "Campaign address changed after upgrade"); + assertTrue(campaignFactory.isValidCampaignInfo(campaignAfter), "Campaign no longer valid"); + } + + function testCampaignInfoFactoryUpgradeUnauthorized() public { + CampaignInfoFactory newImpl = new CampaignInfoFactory(); + + // Try to upgrade as non-owner + vm.prank(attacker); + vm.expectRevert(); + campaignFactory.upgradeToAndCall(address(newImpl), ""); + } + + function testCampaignInfoFactoryStorageSlotIntegrity() public { + // Create multiple campaigns + bytes32[] memory platforms = new bytes32[](1); + platforms[0] = platformHash; + bytes32[] memory keys = new bytes32[](0); + bytes32[] memory values = new bytes32[](0); + + bytes32 identifier1 = bytes32(uint256(1)); + bytes32 identifier2 = bytes32(uint256(2)); + + vm.startPrank(admin); + campaignFactory.createCampaign( + address(0xBEEF), + identifier1, + platforms, + keys, + values, + CAMPAIGN_DATA + ); + + campaignFactory.createCampaign( + address(0xCAFE), + identifier2, + platforms, + keys, + values, + CAMPAIGN_DATA + ); + vm.stopPrank(); + + address campaign1Before = campaignFactory.identifierToCampaignInfo(identifier1); + address campaign2Before = campaignFactory.identifierToCampaignInfo(identifier2); + + // Upgrade + CampaignInfoFactory newImpl = new CampaignInfoFactory(); + vm.prank(admin); + campaignFactory.upgradeToAndCall(address(newImpl), ""); + + // Verify all campaigns are preserved + assertEq(campaignFactory.identifierToCampaignInfo(identifier1), campaign1Before); + assertEq(campaignFactory.identifierToCampaignInfo(identifier2), campaign2Before); + assertTrue(campaignFactory.isValidCampaignInfo(campaign1Before)); + assertTrue(campaignFactory.isValidCampaignInfo(campaign2Before)); + } + + function testCampaignInfoFactoryCannotInitializeTwice() public { + CampaignInfo campaignInfoImpl = new CampaignInfo(); + + vm.expectRevert(); + campaignFactory.initialize( + admin, + IGlobalParams(address(globalParams)), + address(campaignInfoImpl), + address(treasuryFactory) + ); + } + + // ============ Cross-Contract Upgrade Tests ============ + + function testUpgradeAllContractsIndependently() public { + // Upgrade all three contracts + GlobalParams newGlobalParamsImpl = new GlobalParams(); + TreasuryFactory newTreasuryFactoryImpl = new TreasuryFactory(); + CampaignInfoFactory newCampaignFactoryImpl = new CampaignInfoFactory(); + + vm.startPrank(admin); + globalParams.upgradeToAndCall(address(newGlobalParamsImpl), ""); + treasuryFactory.upgradeToAndCall(address(newTreasuryFactoryImpl), ""); + campaignFactory.upgradeToAndCall(address(newCampaignFactoryImpl), ""); + vm.stopPrank(); + + // Verify all contracts still function correctly + assertEq(globalParams.getProtocolAdminAddress(), admin); + + vm.prank(platformAdmin); + treasuryFactory.registerTreasuryImplementation(platformHash, 99, address(0xABCD)); + + bytes32[] memory platforms = new bytes32[](1); + platforms[0] = platformHash; + bytes32[] memory keys = new bytes32[](0); + bytes32[] memory values = new bytes32[](0); + + vm.prank(admin); + campaignFactory.createCampaign( + address(0xBEEF), + bytes32(uint256(999)), + platforms, + keys, + values, + CAMPAIGN_DATA + ); + } + + function testUpgradeDoesNotAffectImplementationContract() public { + // The implementation contract itself should not be usable directly + GlobalParams standaloneImpl = new GlobalParams(); + + bytes32[] memory currencies = new bytes32[](1); + currencies[0] = bytes32("USD"); + address[][] memory tokensPerCurrency = new address[][](1); + tokensPerCurrency[0] = new address[](1); + tokensPerCurrency[0][0] = address(testToken); + + // Should revert because initializers are disabled in constructor + vm.expectRevert(); + standaloneImpl.initialize(admin, protocolFee, currencies, tokensPerCurrency); + } + + // ============ Storage Collision Tests ============ + + function testNoStorageCollisionAfterUpgrade() public { + // Add data to all storage slots + vm.startPrank(admin); + globalParams.updateProtocolFeePercent(999); + globalParams.addTokenToCurrency(bytes32("BRL"), address(0x1111)); + globalParams.enlistPlatform(bytes32("NEW_PLATFORM"), address(0x2222), 123); + vm.stopPrank(); + + // Upgrade + GlobalParams newImpl = new GlobalParams(); + vm.prank(admin); + globalParams.upgradeToAndCall(address(newImpl), ""); + + // Verify all data is intact + assertEq(globalParams.getProtocolFeePercent(), 999); + address[] memory brlTokens = globalParams.getTokensForCurrency(bytes32("BRL")); + assertEq(brlTokens.length, 1); + assertEq(brlTokens[0], address(0x1111)); + assertTrue(globalParams.checkIfPlatformIsListed(bytes32("NEW_PLATFORM"))); + } +} + diff --git a/test/foundry/utils/Constants.sol b/test/foundry/utils/Constants.sol index f25eb6f0..a1009e65 100644 --- a/test/foundry/utils/Constants.sol +++ b/test/foundry/utils/Constants.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; abstract contract Constants { uint40 internal constant OCTOBER_1_2023 = 1_696_118_400; diff --git a/test/foundry/utils/Defaults.sol b/test/foundry/utils/Defaults.sol index ddbaaa90..49bbe437 100644 --- a/test/foundry/utils/Defaults.sol +++ b/test/foundry/utils/Defaults.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import {Constants} from "./Constants.sol"; import {ICampaignData} from "src/interfaces/ICampaignData.sol"; @@ -83,7 +83,12 @@ contract Defaults is Constants, ICampaignData, IReward { DEADLINE = LAUNCH_TIME + CAMPAIGN_DURATION; //Add Campaign Data - CAMPAIGN_DATA = CampaignData({launchTime: LAUNCH_TIME, deadline: DEADLINE, goalAmount: GOAL_AMOUNT}); + CAMPAIGN_DATA = CampaignData({ + launchTime: LAUNCH_TIME, + deadline: DEADLINE, + goalAmount: GOAL_AMOUNT, + currency: bytes32("USD") + }); // Initialize the reward arrays setupRewardData(); diff --git a/test/foundry/utils/LogDecoder.sol b/test/foundry/utils/LogDecoder.sol index e5255200..53c345bb 100644 --- a/test/foundry/utils/LogDecoder.sol +++ b/test/foundry/utils/LogDecoder.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import "forge-std/Test.sol"; diff --git a/test/foundry/utils/Types.sol b/test/foundry/utils/Types.sol index 1331e769..67d3b4a3 100644 --- a/test/foundry/utils/Types.sol +++ b/test/foundry/utils/Types.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; struct Users { // Default owner for all contracts. diff --git a/test/mocks/TestToken.sol b/test/mocks/TestToken.sol index 19414ef1..9f649192 100644 --- a/test/mocks/TestToken.sol +++ b/test/mocks/TestToken.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.22; import {ERC20} from "../../lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; import {Ownable} from "../../lib/openzeppelin-contracts/contracts/access/Ownable.sol"; @@ -9,10 +9,19 @@ import {Ownable} from "../../lib/openzeppelin-contracts/contracts/access/Ownable * @notice A test token `tUSD` which is used in the tests. */ contract TestToken is ERC20, Ownable { + uint8 private _decimals; + constructor( string memory _name, - string memory _symbol - ) ERC20(_name, _symbol) Ownable(msg.sender) {} + string memory _symbol, + uint8 decimals_ + ) ERC20(_name, _symbol) Ownable(msg.sender) { + _decimals = decimals_; + } + + function decimals() public view virtual override returns (uint8) { + return _decimals; + } /** * @notice Mints testToken token. From 70a90d3f5d0e90d8560e8ae5c1b670787b644f14 Mon Sep 17 00:00:00 2001 From: mahabubAlahi <32974385+mahabubAlahi@users.noreply.github.com> Date: Mon, 20 Oct 2025 16:08:33 +0600 Subject: [PATCH 44/63] Add TimeConstrainedPaymentTreasury and batch payment support to PaymentTreasury (#34) * Update environment configuration and add Celo Sepolia RPC endpoint * Add CELO_SEPOLIA_RPC_URL to env.example for new network support * Update foundry.toml with celo_sepolia RPC endpoint * Add batch payment functionality to PaymentTreasury - Introduced `createPaymentBatch` method in `ICampaignPaymentTreasury` interface for creating multiple payment entries in a single transaction. - Implemented the `createPaymentBatch` function in `PaymentTreasury` and `BasePaymentTreasury` with necessary validations and event emissions. - Added unit tests for batch payment creation, including scenarios for input validation and error handling. * Add payment token support in batch payment functionality - Updated the `createPaymentBatch` method in `ICampaignPaymentTreasury` to include an array of payment tokens. - Modified the implementation in `PaymentTreasury` and `BasePaymentTreasury` to handle payment tokens, including necessary validations. - Enhanced unit tests to cover scenarios with multiple payment tokens and validate token acceptance during payment creation. * Add DataRegistryKeys and DataRegistryHelper contracts - Introduced `DataRegistryKeys` library for centralized storage of dataRegistry keys, ensuring consistency and preventing key collisions. - Added `DataRegistryHelper` abstract contract to facilitate access and validation of dataRegistry values from `GlobalParams`, including a method to retrieve the buffer time. * Add TimeConstrainedPaymentTreasury contract - Introduced `TimeConstrainedPaymentTreasury` contract that extends `BasePaymentTreasury`, incorporating time-based constraints for payment operations. - Implemented functions to check time validity before creating, processing, and confirming payments, ensuring actions are only allowed within specified timeframes. * Add integration and unit tests for TimeConstrainedPaymentTreasury - Introduced integration tests for `TimeConstrainedPaymentTreasury`, covering payment creation, processing, cancellation, and time constraint validations. - Added unit tests to ensure correct behavior of payment operations within specified timeframes, including batch payment functionality and edge cases. - Implemented helper functions for setting up test scenarios, including funding users and managing time constraints. - Enhanced test coverage for refund claims, fee disbursement, and withdrawal operations, ensuring compliance with time constraints. * Update environment configuration by removing Alfajores references - Removed Alfajores RPC URL and chain ID from env.example to streamline configuration. - Updated foundry.toml by removing the Alfajores RPC endpoint, reflecting the current network support. --- env.example | 4 +- foundry.toml | 2 +- src/constants/DataRegistryKeys.sol | 13 + src/interfaces/ICampaignPaymentTreasury.sol | 18 + src/treasuries/PaymentTreasury.sol | 14 + .../TimeConstrainedPaymentTreasury.sol | 213 +++++++ src/utils/BasePaymentTreasury.sol | 94 +++ src/utils/DataRegistryHelper.sol | 32 + .../TimeConstrainedPaymentTreasury.t.sol | 181 ++++++ ...meConstrainedPaymentTreasuryFunction.t.sol | 465 ++++++++++++++ test/foundry/unit/PaymentTreasury.t.sol | 170 +++++ .../unit/TimeConstrainedPaymentTreasury.t.sol | 579 ++++++++++++++++++ 12 files changed, 1782 insertions(+), 3 deletions(-) create mode 100644 src/constants/DataRegistryKeys.sol create mode 100644 src/treasuries/TimeConstrainedPaymentTreasury.sol create mode 100644 src/utils/DataRegistryHelper.sol create mode 100644 test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasury.t.sol create mode 100644 test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasuryFunction.t.sol create mode 100644 test/foundry/unit/TimeConstrainedPaymentTreasury.t.sol diff --git a/env.example b/env.example index 9265a035..84bf4aea 100644 --- a/env.example +++ b/env.example @@ -7,13 +7,13 @@ PRIVATE_KEY= RPC_URL= # Optional: Separate RPC URLs for multiple chains -ALFAJORES_RPC_URL= CELO_RPC_URL= +CELO_SEPOLIA_RPC_URL= # Chain IDs CHAIN_ID= -ALFAJORES_CHAIN_ID= CELO_CHAIN_ID= +CELO_SEPOLIA_CHAIN_ID= # ========================= diff --git a/foundry.toml b/foundry.toml index 16049412..4ba7667b 100644 --- a/foundry.toml +++ b/foundry.toml @@ -14,4 +14,4 @@ remappings = [ [rpc_endpoints] mainnet = "https://forno.celo.org/" -alfajores = "https://alfajores-forno.celo-testnet.org/" +celo_sepolia = "https://forno.celo-sepolia.celo-testnet.org/" diff --git a/src/constants/DataRegistryKeys.sol b/src/constants/DataRegistryKeys.sol new file mode 100644 index 00000000..fba022d1 --- /dev/null +++ b/src/constants/DataRegistryKeys.sol @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.22; + +/** + * @title DataRegistryKeys + * @notice Centralized storage for all dataRegistry keys used in GlobalParams + * @dev This library provides a single source of truth for all dataRegistry keys + * to ensure consistency across contracts and prevent key collisions. + */ +library DataRegistryKeys { + // Time-related keys + bytes32 public constant BUFFER_TIME = keccak256("bufferTime"); +} diff --git a/src/interfaces/ICampaignPaymentTreasury.sol b/src/interfaces/ICampaignPaymentTreasury.sol index b9601fbb..3e222215 100644 --- a/src/interfaces/ICampaignPaymentTreasury.sol +++ b/src/interfaces/ICampaignPaymentTreasury.sol @@ -25,6 +25,24 @@ interface ICampaignPaymentTreasury { uint256 expiration ) external; + /** + * @notice Creates multiple payment entries in a single transaction to prevent nonce conflicts. + * @param paymentIds An array of unique identifiers for the payments. + * @param buyerIds An array of buyer IDs corresponding to each payment. + * @param itemIds An array of item identifiers corresponding to each payment. + * @param paymentTokens An array of tokens corresponding to each payment. + * @param amounts An array of amounts corresponding to each payment. + * @param expirations An array of expiration timestamps corresponding to each payment. + */ + function createPaymentBatch( + bytes32[] calldata paymentIds, + bytes32[] calldata buyerIds, + bytes32[] calldata itemIds, + address[] calldata paymentTokens, + uint256[] calldata amounts, + uint256[] calldata expirations + ) external; + /** * @notice Allows a buyer to make a direct crypto payment for an item. * @dev This function transfers tokens directly from the buyer's wallet and confirms the payment immediately. diff --git a/src/treasuries/PaymentTreasury.sol b/src/treasuries/PaymentTreasury.sol index b9211016..fe62cf3d 100644 --- a/src/treasuries/PaymentTreasury.sol +++ b/src/treasuries/PaymentTreasury.sol @@ -57,6 +57,20 @@ contract PaymentTreasury is super.createPayment(paymentId, buyerId, itemId, paymentToken, amount, expiration); } + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function createPaymentBatch( + bytes32[] calldata paymentIds, + bytes32[] calldata buyerIds, + bytes32[] calldata itemIds, + address[] calldata paymentTokens, + uint256[] calldata amounts, + uint256[] calldata expirations + ) public override whenNotPaused whenNotCancelled { + super.createPaymentBatch(paymentIds, buyerIds, itemIds, paymentTokens, amounts, expirations); + } + /** * @inheritdoc ICampaignPaymentTreasury */ diff --git a/src/treasuries/TimeConstrainedPaymentTreasury.sol b/src/treasuries/TimeConstrainedPaymentTreasury.sol new file mode 100644 index 00000000..7345d71f --- /dev/null +++ b/src/treasuries/TimeConstrainedPaymentTreasury.sol @@ -0,0 +1,213 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.22; + +import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; + +import {BasePaymentTreasury} from "../utils/BasePaymentTreasury.sol"; +import {ICampaignPaymentTreasury} from "../interfaces/ICampaignPaymentTreasury.sol"; +import {TimestampChecker} from "../utils/TimestampChecker.sol"; +import {DataRegistryHelper} from "../utils/DataRegistryHelper.sol"; + +contract TimeConstrainedPaymentTreasury is + BasePaymentTreasury, + TimestampChecker, + DataRegistryHelper +{ + using SafeERC20 for IERC20; + + string private s_name; + string private s_symbol; + + + /** + * @dev Emitted when an unauthorized action is attempted. + */ + error TimeConstrainedPaymentTreasuryUnAuthorized(); + + /** + * @dev Constructor for the TimeConstrainedPaymentTreasury contract. + */ + constructor() {} + + function initialize( + bytes32 _platformHash, + address _infoAddress, + string calldata _name, + string calldata _symbol + ) external initializer { + __BaseContract_init(_platformHash, _infoAddress); + s_name = _name; + s_symbol = _symbol; + } + + function name() public view returns (string memory) { + return s_name; + } + + function symbol() public view returns (string memory) { + return s_symbol; + } + + + + /** + * @dev Internal function to check if current time is within the allowed range. + */ + function _checkTimeWithinRange() internal view { + uint256 launchTime = INFO.getLaunchTime(); + uint256 deadline = INFO.getDeadline(); + uint256 bufferTime = _getBufferTime(); + _revertIfCurrentTimeIsNotWithinRange(launchTime, deadline + bufferTime); + } + + /** + * @dev Internal function to check if current time is greater than launch time. + */ + function _checkTimeIsGreater() internal view { + uint256 launchTime = INFO.getLaunchTime(); + _revertIfCurrentTimeIsNotGreater(launchTime); + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function createPayment( + bytes32 paymentId, + bytes32 buyerId, + bytes32 itemId, + address paymentToken, + uint256 amount, + uint256 expiration + ) public override whenCampaignNotPaused whenCampaignNotCancelled { + _checkTimeWithinRange(); + super.createPayment(paymentId, buyerId, itemId, paymentToken, amount, expiration); + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function createPaymentBatch( + bytes32[] calldata paymentIds, + bytes32[] calldata buyerIds, + bytes32[] calldata itemIds, + address[] calldata paymentTokens, + uint256[] calldata amounts, + uint256[] calldata expirations + ) public override whenCampaignNotPaused whenCampaignNotCancelled { + _checkTimeWithinRange(); + super.createPaymentBatch(paymentIds, buyerIds, itemIds, paymentTokens, amounts, expirations); + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function processCryptoPayment( + bytes32 paymentId, + bytes32 itemId, + address buyerAddress, + address paymentToken, + uint256 amount + ) public override whenCampaignNotPaused whenCampaignNotCancelled { + _checkTimeWithinRange(); + super.processCryptoPayment(paymentId, itemId, buyerAddress, paymentToken, amount); + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function cancelPayment( + bytes32 paymentId + ) public override whenCampaignNotPaused whenCampaignNotCancelled { + _checkTimeWithinRange(); + super.cancelPayment(paymentId); + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function confirmPayment( + bytes32 paymentId + ) public override whenCampaignNotPaused whenCampaignNotCancelled { + _checkTimeWithinRange(); + super.confirmPayment(paymentId); + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function confirmPaymentBatch( + bytes32[] calldata paymentIds + ) public override whenCampaignNotPaused whenCampaignNotCancelled { + _checkTimeWithinRange(); + super.confirmPaymentBatch(paymentIds); + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function claimRefund( + bytes32 paymentId, + address refundAddress + ) public override whenCampaignNotPaused whenCampaignNotCancelled { + _checkTimeIsGreater(); + super.claimRefund(paymentId, refundAddress); + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function claimRefund( + bytes32 paymentId + ) public override whenCampaignNotPaused whenCampaignNotCancelled { + _checkTimeIsGreater(); + super.claimRefund(paymentId); + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function disburseFees() + public + override + whenCampaignNotPaused + whenCampaignNotCancelled + { + _checkTimeIsGreater(); + super.disburseFees(); + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function withdraw() public override whenCampaignNotPaused whenCampaignNotCancelled { + _checkTimeIsGreater(); + super.withdraw(); + } + + /** + * @inheritdoc BasePaymentTreasury + * @dev This function is overridden to allow the platform admin and the campaign owner to cancel a treasury. + */ + function cancelTreasury(bytes32 message) public override { + if ( + _msgSender() != INFO.getPlatformAdminAddress(PLATFORM_HASH) && + _msgSender() != INFO.owner() + ) { + revert TimeConstrainedPaymentTreasuryUnAuthorized(); + } + _cancel(message); + } + + /** + * @inheritdoc BasePaymentTreasury + */ + function _checkSuccessCondition() + internal + view + virtual + override + returns (bool) + { + return true; + } +} diff --git a/src/utils/BasePaymentTreasury.sol b/src/utils/BasePaymentTreasury.sol index bf51ea48..49902645 100644 --- a/src/utils/BasePaymentTreasury.sol +++ b/src/utils/BasePaymentTreasury.sol @@ -103,6 +103,14 @@ abstract contract BasePaymentTreasury is bytes32[] paymentIds ); + /** + * @dev Emitted when multiple payments are created in a single batch operation. + * @param paymentIds An array of unique identifiers for the created payments. + */ + event PaymentBatchCreated( + bytes32[] paymentIds + ); + /** * @notice Emitted when fees are successfully disbursed. * @param token The token in which fees were disbursed. @@ -374,6 +382,92 @@ abstract contract BasePaymentTreasury is ); } + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function createPaymentBatch( + bytes32[] calldata paymentIds, + bytes32[] calldata buyerIds, + bytes32[] calldata itemIds, + address[] calldata paymentTokens, + uint256[] calldata amounts, + uint256[] calldata expirations + ) public override virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { + + // Validate array lengths are consistent + uint256 length = paymentIds.length; + if (length == 0 || + length != buyerIds.length || + length != itemIds.length || + length != paymentTokens.length || + length != amounts.length || + length != expirations.length) { + revert PaymentTreasuryInvalidInput(); + } + + // Process each payment in the batch + for (uint256 i = 0; i < length;) { + bytes32 paymentId = paymentIds[i]; + bytes32 buyerId = buyerIds[i]; + bytes32 itemId = itemIds[i]; + address paymentToken = paymentTokens[i]; + uint256 amount = amounts[i]; + uint256 expiration = expirations[i]; + + // Validate individual payment parameters + if(buyerId == ZERO_BYTES || + amount == 0 || + expiration <= block.timestamp || + paymentId == ZERO_BYTES || + itemId == ZERO_BYTES || + paymentToken == address(0) + ){ + revert PaymentTreasuryInvalidInput(); + } + + // Validate token is accepted + if (!INFO.isTokenAccepted(paymentToken)) { + revert PaymentTreasuryTokenNotAccepted(paymentToken); + } + + // Check if payment already exists + if(s_payment[paymentId].buyerId != ZERO_BYTES || s_payment[paymentId].buyerAddress != address(0)){ + revert PaymentTreasuryPaymentAlreadyExist(paymentId); + } + + // Create the payment + s_payment[paymentId] = PaymentInfo({ + buyerId: buyerId, + buyerAddress: address(0), + itemId: itemId, + amount: amount, // Amount in token's native decimals + expiration: expiration, + isConfirmed: false, + isCryptoPayment: false + }); + + s_paymentIdToToken[paymentId] = paymentToken; + s_pendingPaymentPerToken[paymentToken] += amount; + + emit PaymentCreated( + address(0), + paymentId, + buyerId, + itemId, + paymentToken, + amount, + expiration, + false + ); + + unchecked { + ++i; + } + } + + emit PaymentBatchCreated(paymentIds); + } + /** * @inheritdoc ICampaignPaymentTreasury */ diff --git a/src/utils/DataRegistryHelper.sol b/src/utils/DataRegistryHelper.sol new file mode 100644 index 00000000..1ea41a2e --- /dev/null +++ b/src/utils/DataRegistryHelper.sol @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.22; + +import {GlobalParamsStorage} from "../storage/GlobalParamsStorage.sol"; +import {DataRegistryKeys} from "../constants/DataRegistryKeys.sol"; + +/** + * @title DataRegistryHelper + * @notice Helper contract for accessing dataRegistry values from GlobalParams + * @dev This contract provides convenient functions to retrieve and validate dataRegistry values + */ +abstract contract DataRegistryHelper { + + /** + * @dev Retrieves a uint256 value from the dataRegistry + * @param key The dataRegistry key + * @return value The retrieved value + */ + function _getRegistryUint(bytes32 key) internal view returns (uint256 value) { + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + bytes32 valueBytes = $.dataRegistry[key]; + value = uint256(valueBytes); + } + + /** + * @dev Gets the buffer time from dataRegistry + * @return bufferTime The buffer time value + */ + function _getBufferTime() internal view returns (uint256 bufferTime) { + return _getRegistryUint(DataRegistryKeys.BUFFER_TIME); + } +} diff --git a/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasury.t.sol b/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasury.t.sol new file mode 100644 index 00000000..bc45221b --- /dev/null +++ b/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasury.t.sol @@ -0,0 +1,181 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.22; + +import "forge-std/Vm.sol"; +import "forge-std/console.sol"; +import {TimeConstrainedPaymentTreasury} from "src/treasuries/TimeConstrainedPaymentTreasury.sol"; +import {CampaignInfo} from "src/CampaignInfo.sol"; +import {ICampaignPaymentTreasury} from "src/interfaces/ICampaignPaymentTreasury.sol"; +import {LogDecoder} from "../../utils/LogDecoder.sol"; +import {Base_Test} from "../../Base.t.sol"; +import {DataRegistryKeys} from "src/constants/DataRegistryKeys.sol"; + +/// @notice Common testing logic needed by all TimeConstrainedPaymentTreasury integration tests. +abstract contract TimeConstrainedPaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Test { + address campaignAddress; + address treasuryAddress; + TimeConstrainedPaymentTreasury internal timeConstrainedPaymentTreasury; + + // Payment test data + bytes32 internal constant PAYMENT_ID_1 = keccak256("payment1"); + bytes32 internal constant PAYMENT_ID_2 = keccak256("payment2"); + bytes32 internal constant PAYMENT_ID_3 = keccak256("payment3"); + bytes32 internal constant ITEM_ID_1 = keccak256("item1"); + bytes32 internal constant ITEM_ID_2 = keccak256("item2"); + uint256 internal constant PAYMENT_AMOUNT_1 = 1000e18; + uint256 internal constant PAYMENT_AMOUNT_2 = 2000e18; + uint256 internal constant PAYMENT_EXPIRATION = 7 days; + bytes32 internal constant BUYER_ID_1 = keccak256("buyer1"); + bytes32 internal constant BUYER_ID_2 = keccak256("buyer2"); + bytes32 internal constant BUYER_ID_3 = keccak256("buyer3"); + + // Time constraint test data + uint256 internal constant BUFFER_TIME = 1 days; + uint256 internal campaignLaunchTime; + uint256 internal campaignDeadline; + + /// @dev Initial dependent functions setup included for TimeConstrainedPaymentTreasury Integration Tests. + function setUp() public virtual override { + super.setUp(); + console.log("setUp: enlistPlatform"); + + // Enlist Platform + enlistPlatform(PLATFORM_1_HASH); + console.log("enlisted platform"); + + registerTreasuryImplementation(PLATFORM_1_HASH); + console.log("registered treasury"); + + approveTreasuryImplementation(PLATFORM_1_HASH); + console.log("approved treasury"); + + // Set buffer time in GlobalParams + setBufferTime(); + console.log("set buffer time"); + + // Create Campaign with specific time constraints + createCampaignWithTimeConstraints(PLATFORM_1_HASH); + console.log("created campaign with time constraints"); + + // Deploy Treasury Contract + deploy(PLATFORM_1_HASH); + console.log("deployed treasury"); + } + + /** + * @notice Sets buffer time in GlobalParams dataRegistry + */ + function setBufferTime() internal { + vm.startPrank(users.protocolAdminAddress); + globalParams.addToRegistry(DataRegistryKeys.BUFFER_TIME, bytes32(BUFFER_TIME)); + vm.stopPrank(); + } + + /** + * @notice Implements enlistPlatform helper function. + * @param platformHash The platform bytes. + */ + function enlistPlatform(bytes32 platformHash) internal { + vm.startPrank(users.protocolAdminAddress); + globalParams.enlistPlatform(platformHash, users.platform1AdminAddress, PLATFORM_FEE_PERCENT); + vm.stopPrank(); + } + + function registerTreasuryImplementation(bytes32 platformHash) internal { + TimeConstrainedPaymentTreasury implementation = new TimeConstrainedPaymentTreasury(); + vm.startPrank(users.platform1AdminAddress); + treasuryFactory.registerTreasuryImplementation(platformHash, 3, address(implementation)); + vm.stopPrank(); + } + + function approveTreasuryImplementation(bytes32 platformHash) internal { + vm.startPrank(users.protocolAdminAddress); + treasuryFactory.approveTreasuryImplementation(platformHash, 3); + vm.stopPrank(); + } + + /** + * @notice Creates campaign with specific time constraints for testing + * @param platformHash The platform bytes. + */ + function createCampaignWithTimeConstraints(bytes32 platformHash) internal { + bytes32 identifierHash = keccak256(abi.encodePacked(platformHash)); + bytes32[] memory selectedPlatformHash = new bytes32[](1); + selectedPlatformHash[0] = platformHash; + + bytes32[] memory platformDataKey = new bytes32[](0); + bytes32[] memory platformDataValue = new bytes32[](0); + + vm.startPrank(users.creator1Address); + vm.recordLogs(); + + campaignInfoFactory.createCampaign( + users.creator1Address, + identifierHash, + selectedPlatformHash, + platformDataKey, + platformDataValue, + CAMPAIGN_DATA + ); + + campaignAddress = campaignInfoFactory.identifierToCampaignInfo(identifierHash); + campaignInfo = CampaignInfo(campaignAddress); + + // Store the actual campaign times for testing + campaignLaunchTime = campaignInfo.getLaunchTime(); + campaignDeadline = campaignInfo.getDeadline(); + + // Set specific launch time and deadline for testing + vm.warp(campaignLaunchTime); + vm.stopPrank(); + } + + /** + * @notice Implements deploy helper function. It deploys new treasury contract + * @param platformHash The platform bytes. + */ + function deploy(bytes32 platformHash) internal { + vm.startPrank(users.platform1AdminAddress); + vm.recordLogs(); + + treasuryAddress = treasuryFactory.deploy( + platformHash, + campaignAddress, + 3, // TimeConstrainedPaymentTreasury type + "TimeConstrainedPaymentTreasury", + "TCPT" + ); + + timeConstrainedPaymentTreasury = TimeConstrainedPaymentTreasury(treasuryAddress); + vm.stopPrank(); + } + + /** + * @notice Helper function to advance time to within the allowed range + */ + function advanceToWithinRange() internal { + uint256 currentTime = campaignLaunchTime + (campaignDeadline - campaignLaunchTime) / 2; // Middle of the range + vm.warp(currentTime); + } + + /** + * @notice Helper function to advance time to before launch time + */ + function advanceToBeforeLaunch() internal { + vm.warp(campaignLaunchTime - 1); + } + + /** + * @notice Helper function to advance time to after deadline + buffer time + */ + function advanceToAfterDeadline() internal { + vm.warp(campaignDeadline + BUFFER_TIME + 1); + } + + /** + * @notice Helper function to advance time to after launch time but before deadline + */ + function advanceToAfterLaunch() internal { + vm.warp(campaignLaunchTime + 1); + } +} diff --git a/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasuryFunction.t.sol b/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasuryFunction.t.sol new file mode 100644 index 00000000..22d28a09 --- /dev/null +++ b/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasuryFunction.t.sol @@ -0,0 +1,465 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.22; + +import "./TimeConstrainedPaymentTreasury.t.sol"; +import "forge-std/Vm.sol"; +import "forge-std/Test.sol"; +import {Defaults} from "../../utils/Defaults.sol"; +import {Constants} from "../../utils/Constants.sol"; +import {Users} from "../../utils/Types.sol"; +import {ICampaignPaymentTreasury} from "src/interfaces/ICampaignPaymentTreasury.sol"; +import {TimeConstrainedPaymentTreasury} from "src/treasuries/TimeConstrainedPaymentTreasury.sol"; +import {CampaignInfo} from "src/CampaignInfo.sol"; +import {TestToken} from "../../../mocks/TestToken.sol"; + +contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeConstrainedPaymentTreasury_Integration_Shared_Test { + function setUp() public virtual override { + super.setUp(); + + // Fund test users with tokens + deal(address(testToken), users.backer1Address, 1_000_000e18); + deal(address(testToken), users.backer2Address, 1_000_000e18); + deal(address(testToken), users.creator1Address, 1_000_000e18); + deal(address(testToken), users.platform1AdminAddress, 1_000_000e18); + } + + function test_createPayment() external { + advanceToWithinRange(); + + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration + ); + + // Payment created successfully + assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); + assertEq(timeConstrainedPaymentTreasury.getAvailableRaisedAmount(), 0); + } + + function test_createPaymentBatch() external { + advanceToWithinRange(); + + bytes32[] memory paymentIds = new bytes32[](2); + paymentIds[0] = PAYMENT_ID_1; + paymentIds[1] = PAYMENT_ID_2; + + bytes32[] memory buyerIds = new bytes32[](2); + buyerIds[0] = BUYER_ID_1; + buyerIds[1] = BUYER_ID_2; + + bytes32[] memory itemIds = new bytes32[](2); + itemIds[0] = ITEM_ID_1; + itemIds[1] = ITEM_ID_2; + + address[] memory paymentTokens = new address[](2); + paymentTokens[0] = address(testToken); + paymentTokens[1] = address(testToken); + + uint256[] memory amounts = new uint256[](2); + amounts[0] = PAYMENT_AMOUNT_1; + amounts[1] = PAYMENT_AMOUNT_2; + + uint256[] memory expirations = new uint256[](2); + expirations[0] = block.timestamp + PAYMENT_EXPIRATION; + expirations[1] = block.timestamp + PAYMENT_EXPIRATION; + + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.createPaymentBatch( + paymentIds, + buyerIds, + itemIds, + paymentTokens, + amounts, + expirations + ); + + // Payments created successfully + assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); + } + + function test_processCryptoPayment() external { + advanceToWithinRange(); + + // Approve tokens for the treasury + vm.prank(users.backer1Address); + testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); + + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.processCryptoPayment( + PAYMENT_ID_1, + ITEM_ID_1, + users.backer1Address, + address(testToken), + PAYMENT_AMOUNT_1 + ); + + // Payment processed successfully + assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1); + assertEq(timeConstrainedPaymentTreasury.getAvailableRaisedAmount(), PAYMENT_AMOUNT_1); + } + + function test_cancelPayment() external { + advanceToWithinRange(); + + // First create a payment + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration + ); + + // Then cancel it + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.cancelPayment(PAYMENT_ID_1); + + // Payment cancelled successfully + assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); + } + + function test_confirmPayment() external { + advanceToWithinRange(); + + // Use a unique payment ID for this test + bytes32 uniquePaymentId = keccak256("confirmPaymentTest"); + + // Use processCryptoPayment which creates and confirms payment in one step + vm.prank(users.backer1Address); + testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); + + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.processCryptoPayment( + uniquePaymentId, + ITEM_ID_1, + users.backer1Address, + address(testToken), + PAYMENT_AMOUNT_1 + ); + + // Payment created and confirmed successfully by processCryptoPayment + assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1); + assertEq(timeConstrainedPaymentTreasury.getAvailableRaisedAmount(), PAYMENT_AMOUNT_1); + } + + function test_confirmPaymentBatch() external { + advanceToWithinRange(); + + // Use unique payment IDs for this test + bytes32 uniquePaymentId1 = keccak256("confirmPaymentBatchTest1"); + bytes32 uniquePaymentId2 = keccak256("confirmPaymentBatchTest2"); + + // Use processCryptoPayment for both payments which creates and confirms them + vm.prank(users.backer1Address); + testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); + + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.processCryptoPayment( + uniquePaymentId1, + ITEM_ID_1, + users.backer1Address, + address(testToken), + PAYMENT_AMOUNT_1 + ); + + vm.prank(users.backer2Address); + testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_2); + + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.processCryptoPayment( + uniquePaymentId2, + ITEM_ID_2, + users.backer2Address, + address(testToken), + PAYMENT_AMOUNT_2 + ); + + // Payments created and confirmed successfully by processCryptoPayment + assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2); + assertEq(timeConstrainedPaymentTreasury.getAvailableRaisedAmount(), PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2); + } + + function test_claimRefund() external { + // First create payment within the allowed time range + advanceToWithinRange(); + + // Use a unique payment ID for this test + bytes32 uniquePaymentId = keccak256("claimRefundTest"); + + // Use processCryptoPayment which creates and confirms payment in one step + vm.prank(users.backer1Address); + testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); + + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.processCryptoPayment( + uniquePaymentId, + ITEM_ID_1, + users.backer1Address, + address(testToken), + PAYMENT_AMOUNT_1 + ); + + // Advance to after launch to be able to claim refund + advanceToAfterLaunch(); + + // Then claim refund (use the overload without refundAddress since processCryptoPayment uses buyerAddress) + vm.prank(users.backer1Address); + timeConstrainedPaymentTreasury.claimRefund(uniquePaymentId); + + // Refund claimed successfully + assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); + assertEq(timeConstrainedPaymentTreasury.getAvailableRaisedAmount(), 0); + } + + function test_disburseFees() external { + // First create payment within the allowed time range + advanceToWithinRange(); + + // Use a unique payment ID for this test + bytes32 uniquePaymentId = keccak256("disburseFeesTest"); + + // Use processCryptoPayment which creates and confirms payment in one step + vm.prank(users.backer1Address); + testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); + + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.processCryptoPayment( + uniquePaymentId, + ITEM_ID_1, + users.backer1Address, + address(testToken), + PAYMENT_AMOUNT_1 + ); + + // Advance to after launch to be able to disburse fees + advanceToAfterLaunch(); + + // Then disburse fees + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.disburseFees(); + + // Fees disbursed successfully (no revert) + } + + function test_withdraw() external { + // First create payment within the allowed time range + advanceToWithinRange(); + + // Use a unique payment ID for this test + bytes32 uniquePaymentId = keccak256("withdrawTest"); + + // Use processCryptoPayment which creates and confirms payment in one step + vm.prank(users.backer1Address); + testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); + + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.processCryptoPayment( + uniquePaymentId, + ITEM_ID_1, + users.backer1Address, + address(testToken), + PAYMENT_AMOUNT_1 + ); + + // Advance to after launch to be able to withdraw + advanceToAfterLaunch(); + + // Then withdraw + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.withdraw(); + + // Withdrawal successful (no revert) + } + + function test_timeConstraints_createPaymentBeforeLaunch() external { + advanceToBeforeLaunch(); + + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration + ); + } + + function test_timeConstraints_createPaymentAfterDeadline() external { + advanceToAfterDeadline(); + + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration + ); + } + + function test_timeConstraints_claimRefundBeforeLaunch() external { + advanceToBeforeLaunch(); + + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.claimRefund(PAYMENT_ID_1, users.backer1Address); + } + + function test_timeConstraints_disburseFeesBeforeLaunch() external { + advanceToBeforeLaunch(); + + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.disburseFees(); + } + + function test_timeConstraints_withdrawBeforeLaunch() external { + advanceToBeforeLaunch(); + + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.withdraw(); + } + + function test_bufferTimeRetrieval() external { + // Test that buffer time is correctly retrieved from GlobalParams + // We can't access _getBufferTime() directly, so we test it indirectly + // by checking that operations work within the buffer time window + // Use a time that should be within the allowed range + vm.warp(campaignDeadline - 1); // Use deadline - 1 to be within range + + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration + ); + + // Should succeed at deadline - 1 + assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); + } + + function test_operationsAtDeadlinePlusBuffer() external { + // Test operations at the exact deadline + buffer time + vm.warp(campaignDeadline - 1); // Use deadline - 1 to be within range + + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration + ); + + // Should succeed at deadline - 1 + assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); + } + + function test_operationsAfterDeadlinePlusBuffer() external { + // Test operations after deadline + buffer time + advanceToAfterDeadline(); + + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration + ); + } + + function test_operationsAtExactLaunchTime() external { + // Test operations at the exact launch time + vm.warp(campaignLaunchTime); + + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration + ); + + // Should succeed at the exact launch time + assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); + } + + function test_operationsAtExactDeadline() external { + // Test operations at the exact deadline + vm.warp(campaignDeadline); + + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration + ); + + // Should succeed at the exact deadline + assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); + } + + function test_multipleTimeConstraintChecks() external { + // Test that multiple operations respect time constraints + advanceToWithinRange(); + + // Use a unique payment ID for this test + bytes32 uniquePaymentId = keccak256("multipleTimeConstraintChecksTest"); + + // Use processCryptoPayment which creates and confirms payment in one step + vm.prank(users.backer1Address); + testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); + + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.processCryptoPayment( + uniquePaymentId, + ITEM_ID_1, + users.backer1Address, + address(testToken), + PAYMENT_AMOUNT_1 + ); + + // Advance to after launch time + advanceToAfterLaunch(); + + // Withdraw (should work after launch time) + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.withdraw(); + + // All operations should succeed + assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1); + } +} diff --git a/test/foundry/unit/PaymentTreasury.t.sol b/test/foundry/unit/PaymentTreasury.t.sol index 5b6ad076..42ec0db5 100644 --- a/test/foundry/unit/PaymentTreasury.t.sol +++ b/test/foundry/unit/PaymentTreasury.t.sol @@ -9,6 +9,15 @@ import {TestToken} from "../../mocks/TestToken.sol"; contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Test { + // Helper function to create payment tokens array with same token for all payments + function _createPaymentTokensArray(uint256 length, address token) internal pure returns (address[] memory) { + address[] memory paymentTokens = new address[](length); + for (uint256 i = 0; i < length; i++) { + paymentTokens[i] = token; + } + return paymentTokens; + } + function setUp() public virtual override { super.setUp(); // Fund test addresses @@ -1293,4 +1302,165 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te assertEq(usdcToken.balanceOf(treasuryAddress), 0, "USDC should remain zero"); assertEq(cUSDToken.balanceOf(treasuryAddress), 0, "cUSD should remain zero"); } + + /*////////////////////////////////////////////////////////////// + PAYMENT BATCH CREATION + //////////////////////////////////////////////////////////////*/ + + function testCreatePaymentBatch() public { + bytes32[] memory paymentIds = new bytes32[](3); + bytes32[] memory buyerIds = new bytes32[](3); + bytes32[] memory itemIds = new bytes32[](3); + uint256[] memory amounts = new uint256[](3); + uint256[] memory expirations = new uint256[](3); + + // Set up payment data + paymentIds[0] = keccak256("batchPayment1"); + paymentIds[1] = keccak256("batchPayment2"); + paymentIds[2] = keccak256("batchPayment3"); + + buyerIds[0] = BUYER_ID_1; + buyerIds[1] = BUYER_ID_2; + buyerIds[2] = BUYER_ID_3; + + itemIds[0] = ITEM_ID_1; + itemIds[1] = ITEM_ID_2; + itemIds[2] = ITEM_ID_1; // Reuse existing item ID + + amounts[0] = 100 * 10**18; + amounts[1] = 200 * 10**18; + amounts[2] = 300 * 10**18; + + expirations[0] = block.timestamp + 1 days; + expirations[1] = block.timestamp + 2 days; + expirations[2] = block.timestamp + 3 days; + + // Execute batch creation + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPaymentBatch(paymentIds, buyerIds, itemIds, _createPaymentTokensArray(3, address(testToken)), amounts, expirations); + + // Verify that payments were created by checking raised amount is still 0 (not confirmed yet) + assertEq(paymentTreasury.getRaisedAmount(), 0); + assertEq(paymentTreasury.getAvailableRaisedAmount(), 0); + } + + function testCreatePaymentBatchRevertWhenArrayLengthMismatch() public { + bytes32[] memory paymentIds = new bytes32[](2); + bytes32[] memory buyerIds = new bytes32[](3); // Different length + bytes32[] memory itemIds = new bytes32[](2); + uint256[] memory amounts = new uint256[](2); + uint256[] memory expirations = new uint256[](2); + + vm.prank(users.platform1AdminAddress); + vm.expectRevert(); + paymentTreasury.createPaymentBatch(paymentIds, buyerIds, itemIds, _createPaymentTokensArray(paymentIds.length, address(testToken)), amounts, expirations); + } + + function testCreatePaymentBatchRevertWhenEmptyArray() public { + bytes32[] memory paymentIds = new bytes32[](0); + bytes32[] memory buyerIds = new bytes32[](0); + bytes32[] memory itemIds = new bytes32[](0); + uint256[] memory amounts = new uint256[](0); + uint256[] memory expirations = new uint256[](0); + + vm.prank(users.platform1AdminAddress); + vm.expectRevert(); + paymentTreasury.createPaymentBatch(paymentIds, buyerIds, itemIds, _createPaymentTokensArray(paymentIds.length, address(testToken)), amounts, expirations); + } + + function testCreatePaymentBatchRevertWhenPaymentAlreadyExists() public { + // First create a single payment + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration + ); + + // Now try to create a batch with the same payment ID + bytes32[] memory paymentIds = new bytes32[](1); + bytes32[] memory buyerIds = new bytes32[](1); + bytes32[] memory itemIds = new bytes32[](1); + uint256[] memory amounts = new uint256[](1); + uint256[] memory expirations = new uint256[](1); + + paymentIds[0] = PAYMENT_ID_1; // Same ID as above + buyerIds[0] = BUYER_ID_2; + itemIds[0] = ITEM_ID_2; + amounts[0] = PAYMENT_AMOUNT_2; + expirations[0] = block.timestamp + 2 days; + + vm.prank(users.platform1AdminAddress); + vm.expectRevert(); + paymentTreasury.createPaymentBatch(paymentIds, buyerIds, itemIds, _createPaymentTokensArray(paymentIds.length, address(testToken)), amounts, expirations); + } + + function testCreatePaymentBatchRevertWhenNotPlatformAdmin() public { + bytes32[] memory paymentIds = new bytes32[](1); + bytes32[] memory buyerIds = new bytes32[](1); + bytes32[] memory itemIds = new bytes32[](1); + uint256[] memory amounts = new uint256[](1); + uint256[] memory expirations = new uint256[](1); + + paymentIds[0] = keccak256("batchPayment1"); + buyerIds[0] = BUYER_ID_1; + itemIds[0] = ITEM_ID_1; + amounts[0] = PAYMENT_AMOUNT_1; + expirations[0] = block.timestamp + 1 days; + + vm.prank(users.creator1Address); // Not platform admin + vm.expectRevert(); + paymentTreasury.createPaymentBatch(paymentIds, buyerIds, itemIds, _createPaymentTokensArray(paymentIds.length, address(testToken)), amounts, expirations); + } + + function testCreatePaymentBatchWithMultipleTokens() public { + // Create payments with different tokens + bytes32[] memory paymentIds = new bytes32[](3); + bytes32[] memory buyerIds = new bytes32[](3); + bytes32[] memory itemIds = new bytes32[](3); + address[] memory paymentTokens = new address[](3); + uint256[] memory amounts = new uint256[](3); + uint256[] memory expirations = new uint256[](3); + + paymentIds[0] = keccak256("payment1"); + paymentIds[1] = keccak256("payment2"); + paymentIds[2] = keccak256("payment3"); + + buyerIds[0] = BUYER_ID_1; + buyerIds[1] = BUYER_ID_2; + buyerIds[2] = BUYER_ID_3; + + itemIds[0] = ITEM_ID_1; + itemIds[1] = ITEM_ID_2; + itemIds[2] = ITEM_ID_1; + + // Use different tokens for each payment + paymentTokens[0] = address(testToken); // cUSD + paymentTokens[1] = address(testToken); // cUSD (same token for simplicity in test) + paymentTokens[2] = address(testToken); // cUSD (same token for simplicity in test) + + amounts[0] = 100 * 10**18; + amounts[1] = 200 * 10**18; + amounts[2] = 300 * 10**18; + + expirations[0] = block.timestamp + 1 days; + expirations[1] = block.timestamp + 2 days; + expirations[2] = block.timestamp + 3 days; + + // Execute batch creation with multiple tokens + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPaymentBatch(paymentIds, buyerIds, itemIds, paymentTokens, amounts, expirations); + + // Verify that payments were created + assertEq(paymentTreasury.getRaisedAmount(), 0); + assertEq(paymentTreasury.getAvailableRaisedAmount(), 0); + + // Verify that the batch operation completed successfully + // (The fact that no revert occurred means all payments were created successfully) + assertTrue(true); // This test passes if no revert occurred during batch creation + } } \ No newline at end of file diff --git a/test/foundry/unit/TimeConstrainedPaymentTreasury.t.sol b/test/foundry/unit/TimeConstrainedPaymentTreasury.t.sol new file mode 100644 index 00000000..b279dc6e --- /dev/null +++ b/test/foundry/unit/TimeConstrainedPaymentTreasury.t.sol @@ -0,0 +1,579 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.22; + +import "../integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasuryFunction.t.sol"; +import "forge-std/Test.sol"; +import {TimeConstrainedPaymentTreasury} from "src/treasuries/TimeConstrainedPaymentTreasury.sol"; +import {CampaignInfo} from "src/CampaignInfo.sol"; +import {TestToken} from "../../mocks/TestToken.sol"; +import {DataRegistryKeys} from "src/constants/DataRegistryKeys.sol"; + +contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test { + + // Helper function to create payment tokens array with same token for all payments + function _createPaymentTokensArray(uint256 length, address token) internal pure returns (address[] memory) { + address[] memory paymentTokens = new address[](length); + for (uint256 i = 0; i < length; i++) { + paymentTokens[i] = token; + } + return paymentTokens; + } + + function setUp() public virtual override { + super.setUp(); + // Fund test addresses + deal(address(testToken), users.backer1Address, 10_000e18); + deal(address(testToken), users.backer2Address, 10_000e18); + // Label addresses + vm.label(users.protocolAdminAddress, "ProtocolAdmin"); + vm.label(users.platform1AdminAddress, "PlatformAdmin"); + vm.label(users.creator1Address, "CampaignOwner"); + vm.label(users.backer1Address, "Backer1"); + vm.label(users.backer2Address, "Backer2"); + vm.label(address(timeConstrainedPaymentTreasury), "TimeConstrainedPaymentTreasury"); + } + + /*////////////////////////////////////////////////////////////// + INITIALIZATION + //////////////////////////////////////////////////////////////*/ + + function testInitialize() public { + // Create a new campaign for this test + bytes32 newIdentifierHash = keccak256(abi.encodePacked("newTimeConstrainedCampaign")); + bytes32[] memory selectedPlatformHash = new bytes32[](1); + selectedPlatformHash[0] = PLATFORM_1_HASH; + + bytes32[] memory platformDataKey = new bytes32[](0); + bytes32[] memory platformDataValue = new bytes32[](0); + + vm.prank(users.creator1Address); + campaignInfoFactory.createCampaign( + users.creator1Address, + newIdentifierHash, + selectedPlatformHash, + platformDataKey, + platformDataValue, + CAMPAIGN_DATA + ); + address newCampaignAddress = campaignInfoFactory.identifierToCampaignInfo(newIdentifierHash); + + // Deploy a new treasury + vm.prank(users.platform1AdminAddress); + address newTreasury = treasuryFactory.deploy( + PLATFORM_1_HASH, + newCampaignAddress, + 3, // TimeConstrainedPaymentTreasury type + "NewTimeConstrainedPaymentTreasury", + "NTCPT" + ); + TimeConstrainedPaymentTreasury newContract = TimeConstrainedPaymentTreasury(newTreasury); + + assertEq(newContract.name(), "NewTimeConstrainedPaymentTreasury"); + assertEq(newContract.symbol(), "NTCPT"); + assertEq(newContract.getplatformHash(), PLATFORM_1_HASH); + assertEq(newContract.getplatformFeePercent(), PLATFORM_FEE_PERCENT); + } + + /*////////////////////////////////////////////////////////////// + TIME CONSTRAINT TESTS + //////////////////////////////////////////////////////////////*/ + + function testCreatePaymentWithinTimeRange() public { + advanceToWithinRange(); + + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration + ); + + // Payment created successfully + assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); + assertEq(timeConstrainedPaymentTreasury.getAvailableRaisedAmount(), 0); + } + + function testCreatePaymentRevertWhenBeforeLaunchTime() public { + advanceToBeforeLaunch(); + + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration + ); + } + + function testCreatePaymentRevertWhenAfterDeadlinePlusBuffer() public { + advanceToAfterDeadline(); + + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration + ); + } + + function testCreatePaymentBatchWithinTimeRange() public { + advanceToWithinRange(); + + bytes32[] memory paymentIds = new bytes32[](2); + paymentIds[0] = PAYMENT_ID_1; + paymentIds[1] = PAYMENT_ID_2; + + bytes32[] memory buyerIds = new bytes32[](2); + buyerIds[0] = BUYER_ID_1; + buyerIds[1] = BUYER_ID_2; + + bytes32[] memory itemIds = new bytes32[](2); + itemIds[0] = ITEM_ID_1; + itemIds[1] = ITEM_ID_2; + + address[] memory paymentTokens = _createPaymentTokensArray(2, address(testToken)); + + uint256[] memory amounts = new uint256[](2); + amounts[0] = PAYMENT_AMOUNT_1; + amounts[1] = PAYMENT_AMOUNT_2; + + uint256[] memory expirations = new uint256[](2); + expirations[0] = block.timestamp + PAYMENT_EXPIRATION; + expirations[1] = block.timestamp + PAYMENT_EXPIRATION; + + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.createPaymentBatch( + paymentIds, + buyerIds, + itemIds, + paymentTokens, + amounts, + expirations + ); + + // Payments created successfully + assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); + } + + function testCreatePaymentBatchRevertWhenBeforeLaunchTime() public { + advanceToBeforeLaunch(); + + bytes32[] memory paymentIds = new bytes32[](1); + paymentIds[0] = PAYMENT_ID_1; + + bytes32[] memory buyerIds = new bytes32[](1); + buyerIds[0] = BUYER_ID_1; + + bytes32[] memory itemIds = new bytes32[](1); + itemIds[0] = ITEM_ID_1; + + address[] memory paymentTokens = _createPaymentTokensArray(1, address(testToken)); + + uint256[] memory amounts = new uint256[](1); + amounts[0] = PAYMENT_AMOUNT_1; + + uint256[] memory expirations = new uint256[](1); + expirations[0] = block.timestamp + PAYMENT_EXPIRATION; + + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.createPaymentBatch( + paymentIds, + buyerIds, + itemIds, + paymentTokens, + amounts, + expirations + ); + } + + function testProcessCryptoPaymentWithinTimeRange() public { + advanceToWithinRange(); + + // Approve tokens for the treasury + vm.prank(users.backer1Address); + testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); + + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.processCryptoPayment( + PAYMENT_ID_1, + ITEM_ID_1, + users.backer1Address, + address(testToken), + PAYMENT_AMOUNT_1 + ); + + // Payment processed successfully + assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1); + } + + function testProcessCryptoPaymentRevertWhenBeforeLaunchTime() public { + advanceToBeforeLaunch(); + + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.processCryptoPayment( + PAYMENT_ID_1, + ITEM_ID_1, + users.backer1Address, + address(testToken), + PAYMENT_AMOUNT_1 + ); + } + + function testCancelPaymentWithinTimeRange() public { + advanceToWithinRange(); + + // First create a payment + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration + ); + + // Then cancel it + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.cancelPayment(PAYMENT_ID_1); + + // Payment cancelled successfully + assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); + } + + function testCancelPaymentRevertWhenBeforeLaunchTime() public { + advanceToBeforeLaunch(); + + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.cancelPayment(PAYMENT_ID_1); + } + + function testConfirmPaymentWithinTimeRange() public { + advanceToWithinRange(); + + // Use processCryptoPayment which creates and confirms payment in one step + vm.prank(users.backer1Address); + testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); + + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.processCryptoPayment( + PAYMENT_ID_1, + ITEM_ID_1, + users.backer1Address, + address(testToken), + PAYMENT_AMOUNT_1 + ); + + // Payment created and confirmed successfully by processCryptoPayment + assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1); + } + + function testConfirmPaymentRevertWhenBeforeLaunchTime() public { + advanceToBeforeLaunch(); + + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.confirmPayment(PAYMENT_ID_1); + } + + function testConfirmPaymentBatchWithinTimeRange() public { + advanceToWithinRange(); + + // Use processCryptoPayment for both payments which creates and confirms them + vm.prank(users.backer1Address); + testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); + + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.processCryptoPayment( + PAYMENT_ID_1, + ITEM_ID_1, + users.backer1Address, + address(testToken), + PAYMENT_AMOUNT_1 + ); + + vm.prank(users.backer2Address); + testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_2); + + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.processCryptoPayment( + PAYMENT_ID_2, + ITEM_ID_2, + users.backer2Address, + address(testToken), + PAYMENT_AMOUNT_2 + ); + + // Payments created and confirmed successfully by processCryptoPayment + assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2); + } + + function testConfirmPaymentBatchRevertWhenBeforeLaunchTime() public { + advanceToBeforeLaunch(); + + bytes32[] memory paymentIds = new bytes32[](1); + paymentIds[0] = PAYMENT_ID_1; + + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.confirmPaymentBatch(paymentIds); + } + + /*////////////////////////////////////////////////////////////// + POST-LAUNCH TIME TESTS + //////////////////////////////////////////////////////////////*/ + + function testClaimRefundAfterLaunchTime() public { + // First create payment within the allowed time range + advanceToWithinRange(); + + // Use processCryptoPayment which creates and confirms payment in one step + vm.prank(users.backer1Address); + testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); + + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.processCryptoPayment( + PAYMENT_ID_1, + ITEM_ID_1, + users.backer1Address, + address(testToken), + PAYMENT_AMOUNT_1 + ); + + // Advance to after launch to be able to claim refund + advanceToAfterLaunch(); + + // Then claim refund (use the overload without refundAddress since processCryptoPayment uses buyerAddress) + vm.prank(users.backer1Address); + timeConstrainedPaymentTreasury.claimRefund(PAYMENT_ID_1); + + // Refund claimed successfully + assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); + } + + function testClaimRefundRevertWhenBeforeLaunchTime() public { + advanceToBeforeLaunch(); + + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.claimRefund(PAYMENT_ID_1, users.backer1Address); + } + + function testDisburseFeesAfterLaunchTime() public { + // First create payment within the allowed time range + advanceToWithinRange(); + + // Use processCryptoPayment which creates and confirms payment in one step + vm.prank(users.backer1Address); + testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); + + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.processCryptoPayment( + PAYMENT_ID_1, + ITEM_ID_1, + users.backer1Address, + address(testToken), + PAYMENT_AMOUNT_1 + ); + + // Advance to after launch time + advanceToAfterLaunch(); + + // Then disburse fees + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.disburseFees(); + + // Fees disbursed successfully (no revert) + } + + function testDisburseFeesRevertWhenBeforeLaunchTime() public { + advanceToBeforeLaunch(); + + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.disburseFees(); + } + + function testWithdrawAfterLaunchTime() public { + // First create payment within the allowed time range + advanceToWithinRange(); + + // Use processCryptoPayment which creates and confirms payment in one step + vm.prank(users.backer1Address); + testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); + + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.processCryptoPayment( + PAYMENT_ID_1, + ITEM_ID_1, + users.backer1Address, + address(testToken), + PAYMENT_AMOUNT_1 + ); + + // Advance to after launch time + advanceToAfterLaunch(); + + // Then withdraw + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.withdraw(); + + // Withdrawal successful (no revert) + } + + function testWithdrawRevertWhenBeforeLaunchTime() public { + advanceToBeforeLaunch(); + + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.withdraw(); + } + + /*////////////////////////////////////////////////////////////// + BUFFER TIME TESTS + //////////////////////////////////////////////////////////////*/ + + function testBufferTimeRetrieval() public { + // Test that buffer time is correctly retrieved from GlobalParams + // We can't access _getBufferTime() directly, so we test it indirectly + // by checking that operations work within the buffer time window + vm.warp(campaignDeadline - 1); // Use deadline - 1 to be within range + + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration + ); + + // Should succeed at deadline - 1 + assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); + } + + function testOperationsAtDeadlinePlusBuffer() public { + // Test operations at the exact deadline + buffer time + vm.warp(campaignDeadline - 1); // Use deadline - 1 to be within range + + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration + ); + + // Should succeed at deadline - 1 + assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); + } + + function testOperationsAfterDeadlinePlusBuffer() public { + // Test operations after deadline + buffer time + advanceToAfterDeadline(); + + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration + ); + } + + /*////////////////////////////////////////////////////////////// + EDGE CASE TESTS + //////////////////////////////////////////////////////////////*/ + + function testOperationsAtExactLaunchTime() public { + // Test operations at the exact launch time + vm.warp(campaignLaunchTime); + + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration + ); + + // Should succeed at the exact launch time + assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); + } + + function testOperationsAtExactDeadline() public { + // Test operations at the exact deadline + vm.warp(campaignDeadline); + + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration + ); + + // Should succeed at the exact deadline + assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); + } + + function testMultipleTimeConstraintChecks() public { + // Test that multiple operations respect time constraints + advanceToWithinRange(); + + // Use processCryptoPayment which creates and confirms payment in one step + vm.prank(users.backer1Address); + testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); + + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.processCryptoPayment( + PAYMENT_ID_1, + ITEM_ID_1, + users.backer1Address, + address(testToken), + PAYMENT_AMOUNT_1 + ); + + // Advance to after launch time + advanceToAfterLaunch(); + + // Withdraw (should work after launch time) + vm.prank(users.platform1AdminAddress); + timeConstrainedPaymentTreasury.withdraw(); + + // All operations should succeed + assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1); + } +} From b5f7011a898a799f214f8856423d44b1c104f62c Mon Sep 17 00:00:00 2001 From: AdnanHKx Date: Fri, 24 Oct 2025 19:15:18 +0600 Subject: [PATCH 45/63] Fix data registry storage read issue (#36) --- src/CampaignInfo.sol | 18 ++++++++++- src/interfaces/ICampaignInfo.sol | 13 ++++++++ src/interfaces/IGlobalParams.sol | 7 ++++ .../TimeConstrainedPaymentTreasury.sol | 8 ++--- src/utils/DataRegistryHelper.sol | 32 ------------------- 5 files changed, 39 insertions(+), 39 deletions(-) delete mode 100644 src/utils/DataRegistryHelper.sol diff --git a/src/CampaignInfo.sol b/src/CampaignInfo.sol index e80fe943..fac6e3b0 100644 --- a/src/CampaignInfo.sol +++ b/src/CampaignInfo.sol @@ -12,6 +12,7 @@ import {IGlobalParams} from "./interfaces/IGlobalParams.sol"; import {TimestampChecker} from "./utils/TimestampChecker.sol"; import {AdminAccessChecker} from "./utils/AdminAccessChecker.sol"; import {PausableCancellable} from "./utils/PausableCancellable.sol"; +import {DataRegistryKeys} from "./constants/DataRegistryKeys.sol"; /** * @title CampaignInfo @@ -208,7 +209,7 @@ contract CampaignInfo is function getProtocolAdminAddress() public view override returns (address) { return _getGlobalParams().getProtocolAdminAddress(); } - + /** * @inheritdoc ICampaignInfo */ @@ -337,6 +338,21 @@ contract CampaignInfo is return config.identifierHash; } + /** + * @inheritdoc ICampaignInfo + */ + function getDataFromRegistry(bytes32 key) external view override returns (bytes32 value) { + return _getGlobalParams().getFromRegistry(key); + } + + /** + * @inheritdoc ICampaignInfo + */ + function getBufferTime() external view override returns (uint256 bufferTime) { + bytes32 valueBytes = _getGlobalParams().getFromRegistry(DataRegistryKeys.BUFFER_TIME); + bufferTime = uint256(valueBytes); + } + /** * @inheritdoc Ownable */ diff --git a/src/interfaces/ICampaignInfo.sol b/src/interfaces/ICampaignInfo.sol index 203d8172..2e612da1 100644 --- a/src/interfaces/ICampaignInfo.sol +++ b/src/interfaces/ICampaignInfo.sol @@ -157,4 +157,17 @@ interface ICampaignInfo { * @dev Returns true if the campaign is cancelled, and false otherwise. */ function cancelled() external view returns (bool); + + /** + * @notice Retrieves a value from the GlobalParams data registry. + * @param key The registry key. + * @return value The registry value. + */ + function getDataFromRegistry(bytes32 key) external view returns (bytes32 value); + + /** + * @notice Retrieves the buffer time from the GlobalParams data registry. + * @return bufferTime The buffer time value. + */ + function getBufferTime() external view returns (uint256 bufferTime); } diff --git a/src/interfaces/IGlobalParams.sol b/src/interfaces/IGlobalParams.sol index f44bea73..d02f2460 100644 --- a/src/interfaces/IGlobalParams.sol +++ b/src/interfaces/IGlobalParams.sol @@ -113,4 +113,11 @@ interface IGlobalParams { function getTokensForCurrency( bytes32 currency ) external view returns (address[] memory); + + /** + * @notice Retrieves a value from the data registry. + * @param key The registry key. + * @return value The registry value. + */ + function getFromRegistry(bytes32 key) external view returns (bytes32 value); } diff --git a/src/treasuries/TimeConstrainedPaymentTreasury.sol b/src/treasuries/TimeConstrainedPaymentTreasury.sol index 7345d71f..3d663e99 100644 --- a/src/treasuries/TimeConstrainedPaymentTreasury.sol +++ b/src/treasuries/TimeConstrainedPaymentTreasury.sol @@ -6,12 +6,10 @@ import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeE import {BasePaymentTreasury} from "../utils/BasePaymentTreasury.sol"; import {ICampaignPaymentTreasury} from "../interfaces/ICampaignPaymentTreasury.sol"; import {TimestampChecker} from "../utils/TimestampChecker.sol"; -import {DataRegistryHelper} from "../utils/DataRegistryHelper.sol"; contract TimeConstrainedPaymentTreasury is BasePaymentTreasury, - TimestampChecker, - DataRegistryHelper + TimestampChecker { using SafeERC20 for IERC20; @@ -48,15 +46,13 @@ contract TimeConstrainedPaymentTreasury is return s_symbol; } - - /** * @dev Internal function to check if current time is within the allowed range. */ function _checkTimeWithinRange() internal view { uint256 launchTime = INFO.getLaunchTime(); uint256 deadline = INFO.getDeadline(); - uint256 bufferTime = _getBufferTime(); + uint256 bufferTime = INFO.getBufferTime(); _revertIfCurrentTimeIsNotWithinRange(launchTime, deadline + bufferTime); } diff --git a/src/utils/DataRegistryHelper.sol b/src/utils/DataRegistryHelper.sol deleted file mode 100644 index 1ea41a2e..00000000 --- a/src/utils/DataRegistryHelper.sol +++ /dev/null @@ -1,32 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.22; - -import {GlobalParamsStorage} from "../storage/GlobalParamsStorage.sol"; -import {DataRegistryKeys} from "../constants/DataRegistryKeys.sol"; - -/** - * @title DataRegistryHelper - * @notice Helper contract for accessing dataRegistry values from GlobalParams - * @dev This contract provides convenient functions to retrieve and validate dataRegistry values - */ -abstract contract DataRegistryHelper { - - /** - * @dev Retrieves a uint256 value from the dataRegistry - * @param key The dataRegistry key - * @return value The retrieved value - */ - function _getRegistryUint(bytes32 key) internal view returns (uint256 value) { - GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); - bytes32 valueBytes = $.dataRegistry[key]; - value = uint256(valueBytes); - } - - /** - * @dev Gets the buffer time from dataRegistry - * @return bufferTime The buffer time value - */ - function _getBufferTime() internal view returns (uint256 bufferTime) { - return _getRegistryUint(DataRegistryKeys.BUFFER_TIME); - } -} From dffcc787aeb7c27b21c739b7fb54ef1ff0d03507 Mon Sep 17 00:00:00 2001 From: AdnanHKx Date: Mon, 10 Nov 2025 12:52:15 +0600 Subject: [PATCH 46/63] Add time constraints for campaign creation (#37) * Add time constraints for campaign creation * Fix unauthorized caller issue in tests --- src/CampaignInfoFactory.sol | 32 ++++++---- src/constants/DataRegistryKeys.sol | 2 + test/foundry/Base.t.sol | 16 +++++ test/foundry/unit/CampaignInfoFactory.t.sol | 69 +++++++++++++++++++++ test/foundry/utils/Defaults.sol | 2 +- 5 files changed, 109 insertions(+), 12 deletions(-) diff --git a/src/CampaignInfoFactory.sol b/src/CampaignInfoFactory.sol index 91c8c02c..90c016a4 100644 --- a/src/CampaignInfoFactory.sol +++ b/src/CampaignInfoFactory.sol @@ -9,6 +9,7 @@ import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/U import {IGlobalParams} from "./interfaces/IGlobalParams.sol"; import {ICampaignInfoFactory} from "./interfaces/ICampaignInfoFactory.sol"; import {CampaignInfoFactoryStorage} from "./storage/CampaignInfoFactoryStorage.sol"; +import {DataRegistryKeys} from "./constants/DataRegistryKeys.sol"; /** * @title CampaignInfoFactory @@ -95,21 +96,30 @@ contract CampaignInfoFactory is Initializable, ICampaignInfoFactory, OwnableUpgr if (creator == address(0)) { revert CampaignInfoFactoryInvalidInput(); } - if ( - campaignData.launchTime < block.timestamp || - campaignData.deadline <= campaignData.launchTime - ) { - revert CampaignInfoFactoryInvalidInput(); - } if (platformDataKey.length != platformDataValue.length) { revert CampaignInfoFactoryInvalidInput(); } CampaignInfoFactoryStorage.Storage storage $ = CampaignInfoFactoryStorage._getCampaignInfoFactoryStorage(); + // Cache globalParams to save gas on repeated storage reads + IGlobalParams globalParams = $.globalParams; + + // Retrieve time constraints from GlobalParams dataRegistry + uint256 campaignLaunchBuffer = uint256(globalParams.getFromRegistry(DataRegistryKeys.CAMPAIGN_LAUNCH_BUFFER)); + uint256 minimumCampaignDuration = uint256(globalParams.getFromRegistry(DataRegistryKeys.MINIMUM_CAMPAIGN_DURATION)); + + // Validate campaign timing constraints + if (campaignData.launchTime < block.timestamp + campaignLaunchBuffer) { + revert CampaignInfoFactoryInvalidInput(); + } + if (campaignData.deadline < campaignData.launchTime + minimumCampaignDuration) { + revert CampaignInfoFactoryInvalidInput(); + } + bool isValid; for (uint256 i = 0; i < platformDataKey.length; i++) { - isValid = $.globalParams.checkIfPlatformDataKeyValid( + isValid = globalParams.checkIfPlatformDataKeyValid( platformDataKey[i] ); if (!isValid) { @@ -130,21 +140,21 @@ contract CampaignInfoFactory is Initializable, ICampaignInfoFactory, OwnableUpgr bytes32 platformHash; for (uint256 i = 0; i < selectedPlatformHash.length; i++) { platformHash = selectedPlatformHash[i]; - isListed = $.globalParams.checkIfPlatformIsListed(platformHash); + isListed = globalParams.checkIfPlatformIsListed(platformHash); if (!isListed) { revert CampaignInfoFactoryPlatformNotListed(platformHash); } } // Get accepted tokens for the campaign currency - address[] memory acceptedTokens = $.globalParams.getTokensForCurrency(campaignData.currency); + address[] memory acceptedTokens = globalParams.getTokensForCurrency(campaignData.currency); if (acceptedTokens.length == 0) { revert CampaignInfoInvalidTokenList(); } bytes memory args = abi.encode( $.treasuryFactoryAddress, - $.globalParams.getProtocolFeePercent(), + globalParams.getProtocolFeePercent(), identifierHash ); address clone = Clones.cloneWithImmutableArgs($.implementation, args); @@ -152,7 +162,7 @@ contract CampaignInfoFactory is Initializable, ICampaignInfoFactory, OwnableUpgr abi.encodeWithSignature( "initialize(address,address,bytes32[],bytes32[],bytes32[],(uint256,uint256,uint256,bytes32),address[])", creator, - address($.globalParams), + address(globalParams), selectedPlatformHash, platformDataKey, platformDataValue, diff --git a/src/constants/DataRegistryKeys.sol b/src/constants/DataRegistryKeys.sol index fba022d1..80bf4771 100644 --- a/src/constants/DataRegistryKeys.sol +++ b/src/constants/DataRegistryKeys.sol @@ -10,4 +10,6 @@ pragma solidity ^0.8.22; library DataRegistryKeys { // Time-related keys bytes32 public constant BUFFER_TIME = keccak256("bufferTime"); + bytes32 public constant CAMPAIGN_LAUNCH_BUFFER = keccak256("campaignLaunchBuffer"); + bytes32 public constant MINIMUM_CAMPAIGN_DURATION = keccak256("minimumCampaignDuration"); } diff --git a/test/foundry/Base.t.sol b/test/foundry/Base.t.sol index 4ab89305..5d06f3ca 100644 --- a/test/foundry/Base.t.sol +++ b/test/foundry/Base.t.sol @@ -13,6 +13,7 @@ import {AllOrNothing} from "src/treasuries/AllOrNothing.sol"; import {KeepWhatsRaised} from "src/treasuries/KeepWhatsRaised.sol"; import {IGlobalParams} from "src/interfaces/IGlobalParams.sol"; import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; +import {DataRegistryKeys} from "src/constants/DataRegistryKeys.sol"; /// @notice Base test contract with common logic needed by all tests. abstract contract Base_Test is Test, Defaults { @@ -116,6 +117,21 @@ abstract contract Base_Test is Test, Defaults { allOrNothingImplementation = new AllOrNothing(); keepWhatsRaisedImplementation = new KeepWhatsRaised(); + vm.stopPrank(); + + // Set time constraints in dataRegistry (requires protocol admin) + vm.startPrank(users.protocolAdminAddress); + globalParams.addToRegistry( + DataRegistryKeys.CAMPAIGN_LAUNCH_BUFFER, + bytes32(uint256(0)) // No buffer for most tests + ); + globalParams.addToRegistry( + DataRegistryKeys.MINIMUM_CAMPAIGN_DURATION, + bytes32(uint256(0)) // No minimum duration for most tests + ); + vm.stopPrank(); + + vm.startPrank(users.contractOwner); //Mint tokens to backers - all three token types usdtToken.mint(users.backer1Address, TOKEN_MINT_AMOUNT / 1e12); // Adjust for 6 decimals usdtToken.mint(users.backer2Address, TOKEN_MINT_AMOUNT / 1e12); diff --git a/test/foundry/unit/CampaignInfoFactory.t.sol b/test/foundry/unit/CampaignInfoFactory.t.sol index 35c4b35f..fde49b8b 100644 --- a/test/foundry/unit/CampaignInfoFactory.t.sol +++ b/test/foundry/unit/CampaignInfoFactory.t.sol @@ -11,6 +11,7 @@ import {TestToken} from "../../mocks/TestToken.sol"; import {Defaults} from "../Base.t.sol"; import {ICampaignData} from "src/interfaces/ICampaignData.sol"; import {CampaignInfo} from "src/CampaignInfo.sol"; +import {DataRegistryKeys} from "src/constants/DataRegistryKeys.sol"; contract CampaignInfoFactory_UnitTest is Test, Defaults { CampaignInfoFactory internal factory; @@ -83,6 +84,16 @@ contract CampaignInfoFactory_UnitTest is Test, Defaults { admin, PLATFORM_FEE_PERCENT ); + + // Set time constraints in dataRegistry + globalParams.addToRegistry( + DataRegistryKeys.CAMPAIGN_LAUNCH_BUFFER, + bytes32(uint256(1 hours)) + ); + globalParams.addToRegistry( + DataRegistryKeys.MINIMUM_CAMPAIGN_DURATION, + bytes32(uint256(1 days)) + ); vm.stopPrank(); } @@ -192,4 +203,62 @@ contract CampaignInfoFactory_UnitTest is Test, Defaults { address(treasuryFactory) ); } + + function testCreateCampaignRevertsWithInsufficientLaunchBuffer() public { + bytes32[] memory platforms = new bytes32[](1); + platforms[0] = PLATFORM_1_HASH; + + bytes32[] memory keys = new bytes32[](0); + bytes32[] memory values = new bytes32[](0); + + address creator = address(0xBEEF); + + // Create campaign data with launch time less than required buffer (1 hour) + ICampaignData.CampaignData memory campaignData = ICampaignData.CampaignData({ + launchTime: block.timestamp + 30 minutes, // Only 30 minutes buffer + deadline: block.timestamp + 30 minutes + 7 days, + goalAmount: GOAL_AMOUNT, + currency: bytes32("USD") + }); + + vm.prank(admin); + vm.expectRevert(CampaignInfoFactory.CampaignInfoFactoryInvalidInput.selector); + factory.createCampaign( + creator, + CAMPAIGN_1_IDENTIFIER_HASH, + platforms, + keys, + values, + campaignData + ); + } + + function testCreateCampaignRevertsWithInsufficientDuration() public { + bytes32[] memory platforms = new bytes32[](1); + platforms[0] = PLATFORM_1_HASH; + + bytes32[] memory keys = new bytes32[](0); + bytes32[] memory values = new bytes32[](0); + + address creator = address(0xBEEF); + + // Create campaign data with duration less than minimum (1 day) + ICampaignData.CampaignData memory campaignData = ICampaignData.CampaignData({ + launchTime: block.timestamp + 2 hours, // Good buffer + deadline: block.timestamp + 2 hours + 12 hours, // Only 12 hours duration + goalAmount: GOAL_AMOUNT, + currency: bytes32("USD") + }); + + vm.prank(admin); + vm.expectRevert(CampaignInfoFactory.CampaignInfoFactoryInvalidInput.selector); + factory.createCampaign( + creator, + CAMPAIGN_1_IDENTIFIER_HASH, + platforms, + keys, + values, + campaignData + ); + } } diff --git a/test/foundry/utils/Defaults.sol b/test/foundry/utils/Defaults.sol index 49bbe437..9235f3d2 100644 --- a/test/foundry/utils/Defaults.sol +++ b/test/foundry/utils/Defaults.sol @@ -79,7 +79,7 @@ contract Defaults is Constants, ICampaignData, IReward { bytes32[] public GROSS_PERCENTAGE_FEE_VALUES; constructor() { - LAUNCH_TIME = OCTOBER_1_2023 + 300 seconds; + LAUNCH_TIME = OCTOBER_1_2023 + 2 hours; // 2 hours buffer to accommodate time constraints DEADLINE = LAUNCH_TIME + CAMPAIGN_DURATION; //Add Campaign Data From 52e1ed9eca67a4ca0c92bd70c8121c7ba0335350 Mon Sep 17 00:00:00 2001 From: mahabubAlahi <32974385+mahabubAlahi@users.noreply.github.com> Date: Mon, 10 Nov 2025 13:02:10 +0600 Subject: [PATCH 47/63] Add Lock Mechanism in `CampaignInfo` Contract (#40) * Add lock mechanism to CampaignInfo contract - Introduced a lock mechanism to prevent operations after treasury deployment. - Added `isLocked` function to check the lock status of the campaign. - Implemented `whenNotLocked` modifier to restrict access to certain functions when the campaign is locked. - Emitted `CampaignInfoIsLocked` error when locked operations are attempted. - Updated relevant functions to utilize the new locking mechanism, enhancing security and control over campaign operations. * Refactor platform approval checks in CampaignInfo contract - Simplified the logic for handling platform approval by consolidating checks into a single conditional statement. - Removed redundant checks for platform approval and campaign lock status, enhancing code clarity and maintainability. * Add unit tests for CampaignInfo contract - Introduced comprehensive unit tests for the CampaignInfo contract, covering various functionalities including ownership, campaign state, platform selection, and updates to launch time, deadline, and goal amount. - Implemented tests for both successful operations and expected reverts, ensuring robust validation of contract behavior under different scenarios. - Enhanced test coverage for locking mechanisms and platform approval processes, reinforcing the integrity and security of campaign operations. * Add current time check in CampaignInfo contract's updateSelectedPlatform function * Update isLocked function in CampaignInfo contract to override base implementation --- src/CampaignInfo.sol | 37 +- src/interfaces/ICampaignInfo.sol | 5 + test/foundry/unit/CampaignInfo.t.sol | 963 +++++++++++++++++++++++++++ 3 files changed, 1002 insertions(+), 3 deletions(-) create mode 100644 test/foundry/unit/CampaignInfo.t.sol diff --git a/src/CampaignInfo.sol b/src/CampaignInfo.sol index fac6e3b0..2acd3707 100644 --- a/src/CampaignInfo.sol +++ b/src/CampaignInfo.sol @@ -40,6 +40,9 @@ contract CampaignInfo is // Multi-token support address[] private s_acceptedTokens; // Accepted tokens for this campaign mapping(address => bool) private s_isAcceptedToken; // O(1) token validation + + // Lock mechanism - prevents certain operations after treasury deployment + bool private s_isLocked; function getApprovedPlatformHashes() external @@ -49,6 +52,14 @@ contract CampaignInfo is return s_approvedPlatformHashes; } + /** + * @dev Returns whether the campaign is locked (after treasury deployment). + * @return True if the campaign is locked, false otherwise. + */ + function isLocked() external view override returns (bool) { + return s_isLocked; + } + /** * @dev Emitted when the launch time of the campaign is updated. * @param newLaunchTime The new launch time. @@ -119,10 +130,25 @@ contract CampaignInfo is */ error CampaignInfoPlatformAlreadyApproved(bytes32 platformHash); + /** + * @dev Emitted when an operation is attempted on a locked campaign. + */ + error CampaignInfoIsLocked(); + constructor() Ownable(_msgSender()) { _disableInitializers(); } + /** + * @dev Modifier that checks if the campaign is not locked. + */ + modifier whenNotLocked() { + if (s_isLocked) { + revert CampaignInfoIsLocked(); + } + _; + } + function initialize( address creator, IGlobalParams globalParams, @@ -377,9 +403,9 @@ contract CampaignInfo is external override onlyOwner - currentTimeIsLess(getLaunchTime()) whenNotPaused whenNotCancelled + whenNotLocked { if (launchTime < block.timestamp || getDeadline() <= launchTime) { revert CampaignInfoInvalidInput(); @@ -397,9 +423,9 @@ contract CampaignInfo is external override onlyOwner - currentTimeIsLess(getLaunchTime()) whenNotPaused whenNotCancelled + whenNotLocked { if (deadline <= getLaunchTime()) { revert CampaignInfoInvalidInput(); @@ -418,9 +444,9 @@ contract CampaignInfo is external override onlyOwner - currentTimeIsLess(getLaunchTime()) whenNotPaused whenNotCancelled + whenNotLocked { if (goalAmount == 0) { revert CampaignInfoInvalidInput(); @@ -535,6 +561,11 @@ contract CampaignInfo is s_approvedPlatformHashes.push(platformHash); s_isApprovedPlatform[platformHash] = true; + // Lock the campaign after the first treasury deployment + if (!s_isLocked) { + s_isLocked = true; + } + emit CampaignInfoPlatformInfoUpdated( platformHash, platformTreasuryAddress diff --git a/src/interfaces/ICampaignInfo.sol b/src/interfaces/ICampaignInfo.sol index 2e612da1..50c3ad07 100644 --- a/src/interfaces/ICampaignInfo.sol +++ b/src/interfaces/ICampaignInfo.sol @@ -170,4 +170,9 @@ interface ICampaignInfo { * @return bufferTime The buffer time value. */ function getBufferTime() external view returns (uint256 bufferTime); + + /** + * @dev Returns true if the campaign is locked (after treasury deployment), and false otherwise. + */ + function isLocked() external view returns (bool); } diff --git a/test/foundry/unit/CampaignInfo.t.sol b/test/foundry/unit/CampaignInfo.t.sol new file mode 100644 index 00000000..e5872a78 --- /dev/null +++ b/test/foundry/unit/CampaignInfo.t.sol @@ -0,0 +1,963 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.22; + +import "forge-std/Test.sol"; +import {CampaignInfo} from "src/CampaignInfo.sol"; +import {CampaignInfoFactory} from "src/CampaignInfoFactory.sol"; +import {GlobalParams} from "src/GlobalParams.sol"; +import {TreasuryFactory} from "src/TreasuryFactory.sol"; +import {AllOrNothing} from "src/treasuries/AllOrNothing.sol"; +import {IGlobalParams} from "src/interfaces/IGlobalParams.sol"; +import {ICampaignData} from "src/interfaces/ICampaignData.sol"; +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; +import {TestToken} from "../../mocks/TestToken.sol"; +import {Defaults} from "../Base.t.sol"; + +contract CampaignInfo_UnitTest is Test, Defaults { + CampaignInfo internal campaignInfo; + CampaignInfoFactory internal campaignInfoFactory; + GlobalParams internal globalParams; + TreasuryFactory internal treasuryFactory; + AllOrNothing internal allOrNothingImpl; + TestToken internal testToken; + + address internal admin = address(0xA11CE); + address internal campaignOwner = address(0xB22DE); + address internal newOwner = address(0xC33FF); + bytes32 internal platformHash1 = keccak256("platform1"); + bytes32 internal platformHash2 = keccak256("platform2"); + bytes32 internal platformDataKey1 = keccak256("key1"); + bytes32 internal platformDataKey2 = keccak256("key2"); + bytes32 internal platformDataValue1 = keccak256("value1"); + bytes32 internal platformDataValue2 = keccak256("value2"); + + function setUp() public { + testToken = new TestToken(tokenName, tokenSymbol, 18); + + // Setup currencies and tokens + bytes32[] memory currencies = new bytes32[](1); + currencies[0] = bytes32("USD"); + + address[][] memory tokensPerCurrency = new address[][](1); + tokensPerCurrency[0] = new address[](1); + tokensPerCurrency[0][0] = address(testToken); + + // Deploy GlobalParams with proxy + GlobalParams globalParamsImpl = new GlobalParams(); + bytes memory globalParamsInitData = abi.encodeWithSelector( + GlobalParams.initialize.selector, + admin, + PROTOCOL_FEE_PERCENT, + currencies, + tokensPerCurrency + ); + ERC1967Proxy globalParamsProxy = new ERC1967Proxy( + address(globalParamsImpl), + globalParamsInitData + ); + globalParams = GlobalParams(address(globalParamsProxy)); + + // Setup platforms in GlobalParams + vm.startPrank(admin); + globalParams.enlistPlatform(platformHash1, admin, 1000); // 10% fee + globalParams.enlistPlatform(platformHash2, admin, 2000); // 20% fee + + // Add platform data keys + globalParams.addPlatformData(platformHash1, platformDataKey1); + globalParams.addPlatformData(platformHash2, platformDataKey2); + vm.stopPrank(); + + // Deploy TreasuryFactory + TreasuryFactory treasuryFactoryImpl = new TreasuryFactory(); + bytes memory treasuryFactoryInitData = abi.encodeWithSelector( + TreasuryFactory.initialize.selector, + IGlobalParams(address(globalParams)) + ); + ERC1967Proxy treasuryFactoryProxy = new ERC1967Proxy( + address(treasuryFactoryImpl), + treasuryFactoryInitData + ); + treasuryFactory = TreasuryFactory(address(treasuryFactoryProxy)); + + // Deploy AllOrNothing implementation for testing + allOrNothingImpl = new AllOrNothing(); + + // Register and approve treasury implementation (after platform is enlisted) + vm.startPrank(admin); + treasuryFactory.registerTreasuryImplementation(platformHash1, 1, address(allOrNothingImpl)); + treasuryFactory.approveTreasuryImplementation(platformHash1, 1); + vm.stopPrank(); + + // Deploy CampaignInfoFactory + CampaignInfoFactory campaignInfoFactoryImpl = new CampaignInfoFactory(); + bytes memory campaignInfoFactoryInitData = abi.encodeWithSelector( + CampaignInfoFactory.initialize.selector, + admin, + IGlobalParams(address(globalParams)), + address(new CampaignInfo()), + address(treasuryFactory) + ); + ERC1967Proxy campaignInfoFactoryProxy = new ERC1967Proxy( + address(campaignInfoFactoryImpl), + campaignInfoFactoryInitData + ); + campaignInfoFactory = CampaignInfoFactory(address(campaignInfoFactoryProxy)); + + // Create a campaign using the factory + ICampaignData.CampaignData memory campaignData = ICampaignData.CampaignData({ + launchTime: block.timestamp + 1 days, + deadline: block.timestamp + 30 days, + goalAmount: 1000 * 10**18, + currency: bytes32("USD") + }); + + bytes32[] memory selectedPlatformHashes = new bytes32[](0); // No platforms selected initially + bytes32[] memory platformDataKeys = new bytes32[](0); + bytes32[] memory platformDataValues = new bytes32[](0); + bytes32 identifierHash = keccak256("test-campaign"); + + vm.startPrank(admin); + campaignInfoFactory.createCampaign( + campaignOwner, + identifierHash, + selectedPlatformHashes, + platformDataKeys, + platformDataValues, + campaignData + ); + vm.stopPrank(); + + campaignInfo = CampaignInfo(campaignInfoFactory.identifierToCampaignInfo(identifierHash)); + } + + // ============ View Functions Tests ============ + + function test_Owner() public { + assertEq(campaignInfo.owner(), campaignOwner); + } + + function test_IsLocked_InitiallyFalse() public { + assertFalse(campaignInfo.isLocked()); + } + + function test_GetLaunchTime() public { + uint256 launchTime = campaignInfo.getLaunchTime(); + assertTrue(launchTime > 0); + } + + function test_GetDeadline() public { + uint256 deadline = campaignInfo.getDeadline(); + assertTrue(deadline > campaignInfo.getLaunchTime()); + } + + function test_GetGoalAmount() public { + uint256 goalAmount = campaignInfo.getGoalAmount(); + assertEq(goalAmount, 1000 * 10**18); + } + + + function test_GetCampaignCurrency() public { + bytes32 currency = campaignInfo.getCampaignCurrency(); + assertEq(currency, bytes32("USD")); + } + + function test_GetAcceptedTokens() public { + address[] memory tokens = campaignInfo.getAcceptedTokens(); + assertEq(tokens.length, 1); + assertEq(tokens[0], address(testToken)); + } + + function test_IsTokenAccepted() public { + assertTrue(campaignInfo.isTokenAccepted(address(testToken))); + assertFalse(campaignInfo.isTokenAccepted(address(0x1234))); + } + + function test_GetPlatformFeePercent() public { + // Initially no platforms selected, should return 0 + assertEq(campaignInfo.getPlatformFeePercent(platformHash1), 0); + } + + function test_GetPlatformData_NotSet() public { + vm.expectRevert(CampaignInfo.CampaignInfoInvalidInput.selector); + campaignInfo.getPlatformData(platformDataKey1); + } + + function test_CheckIfPlatformSelected_InitiallyFalse() public { + assertFalse(campaignInfo.checkIfPlatformSelected(platformHash1)); + } + + function test_CheckIfPlatformApproved_InitiallyFalse() public { + assertFalse(campaignInfo.checkIfPlatformApproved(platformHash1)); + } + + function test_GetApprovedPlatformHashes_InitiallyEmpty() public { + bytes32[] memory approvedPlatforms = campaignInfo.getApprovedPlatformHashes(); + assertEq(approvedPlatforms.length, 0); + } + + function test_Paused_InitiallyFalse() public { + assertFalse(campaignInfo.paused()); + } + + function test_Cancelled_InitiallyFalse() public { + assertFalse(campaignInfo.cancelled()); + } + + // ============ UpdateSelectedPlatform Tests ============ + + function test_UpdateSelectedPlatform_SelectPlatform_Success() public { + vm.startPrank(campaignOwner); + + bytes32[] memory dataKeys = new bytes32[](2); + dataKeys[0] = platformDataKey1; + dataKeys[1] = platformDataKey2; + + bytes32[] memory dataValues = new bytes32[](2); + dataValues[0] = platformDataValue1; + dataValues[1] = platformDataValue2; + + campaignInfo.updateSelectedPlatform( + platformHash1, + true, + dataKeys, + dataValues + ); + + // Verify platform is selected + assertTrue(campaignInfo.checkIfPlatformSelected(platformHash1)); + + // Verify platform data is stored + assertEq(campaignInfo.getPlatformData(platformDataKey1), platformDataValue1); + assertEq(campaignInfo.getPlatformData(platformDataKey2), platformDataValue2); + + // Verify platform fee is set + assertEq(campaignInfo.getPlatformFeePercent(platformHash1), 1000); + + vm.stopPrank(); + } + + + function test_UpdateSelectedPlatform_InvalidPlatform_Reverts() public { + vm.startPrank(campaignOwner); + + bytes32 invalidPlatformHash = keccak256("invalid"); + bytes32[] memory dataKeys = new bytes32[](1); + dataKeys[0] = platformDataKey1; + + bytes32[] memory dataValues = new bytes32[](1); + dataValues[0] = platformDataValue1; + + vm.expectRevert( + abi.encodeWithSelector( + CampaignInfo.CampaignInfoInvalidPlatformUpdate.selector, + invalidPlatformHash, + true + ) + ); + campaignInfo.updateSelectedPlatform( + invalidPlatformHash, + true, + dataKeys, + dataValues + ); + vm.stopPrank(); + } + + function test_UpdateSelectedPlatform_AlreadySelected_Reverts() public { + vm.startPrank(campaignOwner); + + bytes32[] memory dataKeys = new bytes32[](1); + dataKeys[0] = platformDataKey1; + + bytes32[] memory dataValues = new bytes32[](1); + dataValues[0] = platformDataValue1; + + // Select platform first time + campaignInfo.updateSelectedPlatform( + platformHash1, + true, + dataKeys, + dataValues + ); + + // Try to select again - should revert + vm.expectRevert(CampaignInfo.CampaignInfoInvalidInput.selector); + campaignInfo.updateSelectedPlatform( + platformHash1, + true, + dataKeys, + dataValues + ); + vm.stopPrank(); + } + + function test_UpdateSelectedPlatform_DataKeyValueLengthMismatch_Reverts() public { + vm.startPrank(campaignOwner); + + bytes32[] memory dataKeys = new bytes32[](2); + dataKeys[0] = platformDataKey1; + dataKeys[1] = platformDataKey2; + + bytes32[] memory dataValues = new bytes32[](1); + dataValues[0] = platformDataValue1; + + vm.expectRevert(CampaignInfo.CampaignInfoInvalidInput.selector); + campaignInfo.updateSelectedPlatform( + platformHash1, + true, + dataKeys, + dataValues + ); + vm.stopPrank(); + } + + function test_UpdateSelectedPlatform_InvalidDataKey_Reverts() public { + vm.startPrank(campaignOwner); + + bytes32[] memory dataKeys = new bytes32[](1); + dataKeys[0] = keccak256("invalid_key"); + + bytes32[] memory dataValues = new bytes32[](1); + dataValues[0] = platformDataValue1; + + vm.expectRevert(CampaignInfo.CampaignInfoInvalidInput.selector); + campaignInfo.updateSelectedPlatform( + platformHash1, + true, + dataKeys, + dataValues + ); + vm.stopPrank(); + } + + function test_UpdateSelectedPlatform_ZeroDataValue_Reverts() public { + vm.startPrank(campaignOwner); + + bytes32[] memory dataKeys = new bytes32[](1); + dataKeys[0] = platformDataKey1; + + bytes32[] memory dataValues = new bytes32[](1); + dataValues[0] = bytes32(0); + + vm.expectRevert(CampaignInfo.CampaignInfoInvalidInput.selector); + campaignInfo.updateSelectedPlatform( + platformHash1, + true, + dataKeys, + dataValues + ); + vm.stopPrank(); + } + + function test_UpdateSelectedPlatform_Unauthorized_Reverts() public { + address unauthorizedUser = address(0xC33FF); + + bytes32[] memory dataKeys = new bytes32[](1); + dataKeys[0] = platformDataKey1; + + bytes32[] memory dataValues = new bytes32[](1); + dataValues[0] = platformDataValue1; + + vm.startPrank(unauthorizedUser); + vm.expectRevert(); + campaignInfo.updateSelectedPlatform( + platformHash1, + true, + dataKeys, + dataValues + ); + vm.stopPrank(); + } + + // ============ Update Functions Tests ============ + + function test_UpdateLaunchTime_Success() public { + vm.startPrank(campaignOwner); + + uint256 newLaunchTime = block.timestamp + 1 days; + + vm.expectEmit(true, false, false, true); + emit CampaignInfo.CampaignInfoLaunchTimeUpdated(newLaunchTime); + + campaignInfo.updateLaunchTime(newLaunchTime); + + assertEq(campaignInfo.getLaunchTime(), newLaunchTime); + vm.stopPrank(); + } + + function test_UpdateLaunchTime_InvalidTime_Reverts() public { + vm.startPrank(campaignOwner); + + // Launch time in the past + vm.expectRevert(CampaignInfo.CampaignInfoInvalidInput.selector); + campaignInfo.updateLaunchTime(block.timestamp - 1); + + vm.stopPrank(); + } + + function test_UpdateDeadline_Success() public { + vm.startPrank(campaignOwner); + + uint256 newDeadline = campaignInfo.getLaunchTime() + 60 days; + + vm.expectEmit(true, false, false, true); + emit CampaignInfo.CampaignInfoDeadlineUpdated(newDeadline); + + campaignInfo.updateDeadline(newDeadline); + + assertEq(campaignInfo.getDeadline(), newDeadline); + vm.stopPrank(); + } + + function test_UpdateGoalAmount_Success() public { + vm.startPrank(campaignOwner); + + uint256 newGoalAmount = 2000 * 10**18; + + vm.expectEmit(true, false, false, true); + emit CampaignInfo.CampaignInfoGoalAmountUpdated(newGoalAmount); + + campaignInfo.updateGoalAmount(newGoalAmount); + + assertEq(campaignInfo.getGoalAmount(), newGoalAmount); + vm.stopPrank(); + } + + function test_UpdateGoalAmount_ZeroAmount_Reverts() public { + vm.startPrank(campaignOwner); + + vm.expectRevert(CampaignInfo.CampaignInfoInvalidInput.selector); + campaignInfo.updateGoalAmount(0); + + vm.stopPrank(); + } + + + // ============ Transfer Ownership Tests ============ + + function test_TransferOwnership_Success() public { + vm.startPrank(campaignOwner); + + campaignInfo.transferOwnership(newOwner); + + assertEq(campaignInfo.owner(), newOwner); + vm.stopPrank(); + } + + function test_TransferOwnership_WhenPaused_Reverts() public { + // Pause the campaign + vm.startPrank(admin); + campaignInfo._pauseCampaign(keccak256("test")); + vm.stopPrank(); + + vm.startPrank(campaignOwner); + vm.expectRevert(); + campaignInfo.transferOwnership(newOwner); + vm.stopPrank(); + } + + function test_TransferOwnership_WhenCancelled_Reverts() public { + // Cancel the campaign + vm.startPrank(admin); + campaignInfo._cancelCampaign(keccak256("test")); + vm.stopPrank(); + + vm.startPrank(campaignOwner); + vm.expectRevert(); + campaignInfo.transferOwnership(newOwner); + vm.stopPrank(); + } + + // ============ Admin Functions Tests ============ + + function test_PauseCampaign_Success() public { + vm.startPrank(admin); + + bytes32 message = keccak256("test pause"); + campaignInfo._pauseCampaign(message); + + assertTrue(campaignInfo.paused()); + vm.stopPrank(); + } + + function test_UnpauseCampaign_Success() public { + // First pause + vm.startPrank(admin); + campaignInfo._pauseCampaign(keccak256("test pause")); + vm.stopPrank(); + + // Then unpause + vm.startPrank(admin); + bytes32 message = keccak256("test unpause"); + campaignInfo._unpauseCampaign(message); + + assertFalse(campaignInfo.paused()); + vm.stopPrank(); + } + + function test_CancelCampaign_ByAdmin_Success() public { + vm.startPrank(admin); + + bytes32 message = keccak256("test cancel"); + campaignInfo._cancelCampaign(message); + + assertTrue(campaignInfo.cancelled()); + vm.stopPrank(); + } + + function test_CancelCampaign_ByOwner_Success() public { + vm.startPrank(campaignOwner); + + bytes32 message = keccak256("test cancel"); + campaignInfo._cancelCampaign(message); + + assertTrue(campaignInfo.cancelled()); + vm.stopPrank(); + } + + function test_CancelCampaign_Unauthorized_Reverts() public { + address unauthorizedUser = address(0xD44F); + + vm.startPrank(unauthorizedUser); + vm.expectRevert(CampaignInfo.CampaignInfoUnauthorized.selector); + campaignInfo._cancelCampaign(keccak256("test cancel")); + vm.stopPrank(); + } + + // ============ Locked Functionality Tests ============ + + + function test_UpdateSelectedPlatform_SelectPlatform_WhenNotLocked_Success() public { + // Test that platform selection works when not locked + vm.startPrank(campaignOwner); + + bytes32[] memory dataKeys = new bytes32[](1); + dataKeys[0] = platformDataKey1; + bytes32[] memory dataValues = new bytes32[](1); + dataValues[0] = platformDataValue1; + + campaignInfo.updateSelectedPlatform( + platformHash1, + true, + dataKeys, + dataValues + ); + + // Verify platform is selected + assertTrue(campaignInfo.checkIfPlatformSelected(platformHash1)); + vm.stopPrank(); + } + + function test_UpdateSelectedPlatform_DeselectPlatform_WhenNotLocked_Success() public { + // First select a platform + vm.startPrank(campaignOwner); + + bytes32[] memory dataKeys = new bytes32[](1); + dataKeys[0] = platformDataKey1; + bytes32[] memory dataValues = new bytes32[](1); + dataValues[0] = platformDataValue1; + + campaignInfo.updateSelectedPlatform( + platformHash1, + true, + dataKeys, + dataValues + ); + + // Now deselect it + campaignInfo.updateSelectedPlatform( + platformHash1, + false, + new bytes32[](0), + new bytes32[](0) + ); + + // Verify platform is not selected + assertFalse(campaignInfo.checkIfPlatformSelected(platformHash1)); + + // Verify platform fee is reset to 0 + assertEq(campaignInfo.getPlatformFeePercent(platformHash1), 0); + + vm.stopPrank(); + } + + function test_UpdateLaunchTime_WhenNotLocked_Success() public { + // Test that launch time update works when not locked + vm.startPrank(campaignOwner); + + uint256 newLaunchTime = block.timestamp + 1 days; + + campaignInfo.updateLaunchTime(newLaunchTime); + + assertEq(campaignInfo.getLaunchTime(), newLaunchTime); + vm.stopPrank(); + } + + function test_UpdateDeadline_WhenNotLocked_Success() public { + // Test that deadline update works when not locked + vm.startPrank(campaignOwner); + + uint256 newDeadline = campaignInfo.getLaunchTime() + 60 days; + + campaignInfo.updateDeadline(newDeadline); + + assertEq(campaignInfo.getDeadline(), newDeadline); + vm.stopPrank(); + } + + function test_UpdateGoalAmount_WhenNotLocked_Success() public { + // Test that goal amount update works when not locked + vm.startPrank(campaignOwner); + + uint256 newGoalAmount = 2000 * 10**18; + + campaignInfo.updateGoalAmount(newGoalAmount); + + assertEq(campaignInfo.getGoalAmount(), newGoalAmount); + vm.stopPrank(); + } + + // ============ Locked Campaign Tests ============ + + function test_LockMechanism_AfterTreasuryDeployment() public { + // First select a platform + vm.startPrank(campaignOwner); + bytes32[] memory dataKeys = new bytes32[](1); + dataKeys[0] = platformDataKey1; + bytes32[] memory dataValues = new bytes32[](1); + dataValues[0] = platformDataValue1; + + campaignInfo.updateSelectedPlatform( + platformHash1, + true, + dataKeys, + dataValues + ); + vm.stopPrank(); + + // Verify campaign is not locked initially + assertFalse(campaignInfo.isLocked()); + + // Deploy a treasury using the treasury factory - this will call _setPlatformInfo + vm.startPrank(admin); + address treasury = treasuryFactory.deploy( + platformHash1, + address(campaignInfo), + 1, // implementationId + "Test Treasury", + "TT" + ); + vm.stopPrank(); + + // Verify campaign is now locked + assertTrue(campaignInfo.isLocked()); + assertTrue(campaignInfo.checkIfPlatformApproved(platformHash1)); + } + + function test_UpdateLaunchTime_WhenLocked_Reverts() public { + // Lock the campaign first + _lockCampaign(); + + vm.startPrank(campaignOwner); + uint256 newLaunchTime = block.timestamp + 1 days; + + vm.expectRevert(CampaignInfo.CampaignInfoIsLocked.selector); + campaignInfo.updateLaunchTime(newLaunchTime); + vm.stopPrank(); + } + + function test_UpdateDeadline_WhenLocked_Reverts() public { + // Lock the campaign first + _lockCampaign(); + + vm.startPrank(campaignOwner); + uint256 newDeadline = campaignInfo.getLaunchTime() + 60 days; + + vm.expectRevert(CampaignInfo.CampaignInfoIsLocked.selector); + campaignInfo.updateDeadline(newDeadline); + vm.stopPrank(); + } + + function test_UpdateGoalAmount_WhenLocked_Reverts() public { + // Lock the campaign first + _lockCampaign(); + + vm.startPrank(campaignOwner); + uint256 newGoalAmount = 2000 * 10**18; + + vm.expectRevert(CampaignInfo.CampaignInfoIsLocked.selector); + campaignInfo.updateGoalAmount(newGoalAmount); + vm.stopPrank(); + } + + function test_UpdateSelectedPlatform_DeselectPlatform_WhenLocked_Reverts() public { + // First select a platform and lock the campaign + vm.startPrank(campaignOwner); + bytes32[] memory dataKeys = new bytes32[](1); + dataKeys[0] = platformDataKey1; + bytes32[] memory dataValues = new bytes32[](1); + dataValues[0] = platformDataValue1; + + campaignInfo.updateSelectedPlatform( + platformHash1, + true, + dataKeys, + dataValues + ); + vm.stopPrank(); + + // Lock the campaign by deploying treasury + vm.startPrank(admin); + treasuryFactory.deploy( + platformHash1, + address(campaignInfo), + 1, // implementationId + "Test Treasury", + "TT" + ); + vm.stopPrank(); + + // Now try to deselect the platform - should revert with already approved error + vm.startPrank(campaignOwner); + vm.expectRevert( + abi.encodeWithSelector( + CampaignInfo.CampaignInfoPlatformAlreadyApproved.selector, + platformHash1 + ) + ); + campaignInfo.updateSelectedPlatform( + platformHash1, + false, + new bytes32[](0), + new bytes32[](0) + ); + vm.stopPrank(); + } + + function test_UpdateSelectedPlatform_SelectNewPlatform_WhenLocked_Success() public { + // Lock the campaign first + _lockCampaign(); + + // Selecting a new platform should still work when locked + vm.startPrank(campaignOwner); + bytes32[] memory dataKeys = new bytes32[](1); + dataKeys[0] = platformDataKey2; + bytes32[] memory dataValues = new bytes32[](1); + dataValues[0] = platformDataValue2; + + campaignInfo.updateSelectedPlatform( + platformHash2, + true, + dataKeys, + dataValues + ); + + // Verify platform is selected + assertTrue(campaignInfo.checkIfPlatformSelected(platformHash2)); + assertEq(campaignInfo.getPlatformFeePercent(platformHash2), 2000); // 20% fee + vm.stopPrank(); + } + + function test_TransferOwnership_WhenLocked_Success() public { + // Lock the campaign first + _lockCampaign(); + + // Transfer ownership should still work when locked + vm.startPrank(campaignOwner); + campaignInfo.transferOwnership(newOwner); + + assertEq(campaignInfo.owner(), newOwner); + vm.stopPrank(); + } + + function test_PauseCampaign_WhenLocked_Success() public { + // Lock the campaign first + _lockCampaign(); + + // Pausing should still work when locked + vm.startPrank(admin); + bytes32 message = keccak256("test pause"); + campaignInfo._pauseCampaign(message); + + assertTrue(campaignInfo.paused()); + vm.stopPrank(); + } + + function test_UnpauseCampaign_WhenLocked_Success() public { + // Lock the campaign first + _lockCampaign(); + + // First pause + vm.startPrank(admin); + campaignInfo._pauseCampaign(keccak256("test pause")); + vm.stopPrank(); + + // Then unpause - should still work when locked + vm.startPrank(admin); + bytes32 message = keccak256("test unpause"); + campaignInfo._unpauseCampaign(message); + + assertFalse(campaignInfo.paused()); + vm.stopPrank(); + } + + function test_CancelCampaign_ByAdmin_WhenLocked_Success() public { + // Lock the campaign first + _lockCampaign(); + + // Cancelling should still work when locked + vm.startPrank(admin); + bytes32 message = keccak256("test cancel"); + campaignInfo._cancelCampaign(message); + + assertTrue(campaignInfo.cancelled()); + vm.stopPrank(); + } + + function test_CancelCampaign_ByOwner_WhenLocked_Success() public { + // Lock the campaign first + _lockCampaign(); + + // Cancelling should still work when locked + vm.startPrank(campaignOwner); + bytes32 message = keccak256("test cancel"); + campaignInfo._cancelCampaign(message); + + assertTrue(campaignInfo.cancelled()); + vm.stopPrank(); + } + + function test_ViewFunctions_WhenLocked_StillWork() public { + // Lock the campaign first + _lockCampaign(); + + // All view functions should still work when locked + assertTrue(campaignInfo.isLocked()); + assertEq(campaignInfo.owner(), campaignOwner); + assertTrue(campaignInfo.getLaunchTime() > 0); + assertTrue(campaignInfo.getDeadline() > campaignInfo.getLaunchTime()); + assertEq(campaignInfo.getGoalAmount(), 1000 * 10**18); + assertEq(campaignInfo.getCampaignCurrency(), bytes32("USD")); + assertFalse(campaignInfo.paused()); + assertFalse(campaignInfo.cancelled()); + } + + function test_PlatformOperations_WhenLocked_StillWork() public { + // Lock the campaign first + _lockCampaign(); + + // Platform-related view functions should still work + assertFalse(campaignInfo.checkIfPlatformSelected(platformHash2)); + assertFalse(campaignInfo.checkIfPlatformApproved(platformHash2)); + + bytes32[] memory approvedPlatforms = campaignInfo.getApprovedPlatformHashes(); + assertEq(approvedPlatforms.length, 1); + assertEq(approvedPlatforms[0], platformHash1); + } + + function test_UpdateSelectedPlatform_AlreadyApproved_WhenLocked_Reverts() public { + // First select and approve a platform (this locks the campaign) + vm.startPrank(campaignOwner); + bytes32[] memory dataKeys = new bytes32[](1); + dataKeys[0] = platformDataKey1; + bytes32[] memory dataValues = new bytes32[](1); + dataValues[0] = platformDataValue1; + + campaignInfo.updateSelectedPlatform( + platformHash1, + true, + dataKeys, + dataValues + ); + vm.stopPrank(); + + // Approve the platform (this locks the campaign) + vm.startPrank(admin); + treasuryFactory.deploy( + platformHash1, + address(campaignInfo), + 1, // implementationId + "Test Treasury", + "TT" + ); + vm.stopPrank(); + + // Now try to deselect the already approved platform - should revert with already approved error + vm.startPrank(campaignOwner); + vm.expectRevert( + abi.encodeWithSelector( + CampaignInfo.CampaignInfoPlatformAlreadyApproved.selector, + platformHash1 + ) + ); + campaignInfo.updateSelectedPlatform( + platformHash1, + false, + new bytes32[](0), + new bytes32[](0) + ); + vm.stopPrank(); + } + + function test_UpdateSelectedPlatform_SelectApprovedPlatform_WhenLocked_Reverts() public { + // First select and approve a platform (this locks the campaign) + vm.startPrank(campaignOwner); + bytes32[] memory dataKeys = new bytes32[](1); + dataKeys[0] = platformDataKey1; + bytes32[] memory dataValues = new bytes32[](1); + dataValues[0] = platformDataValue1; + + campaignInfo.updateSelectedPlatform( + platformHash1, + true, + dataKeys, + dataValues + ); + vm.stopPrank(); + + // Approve the platform (this locks the campaign) + vm.startPrank(address(treasuryFactory)); + campaignInfo._setPlatformInfo(platformHash1, address(0x1234)); + vm.stopPrank(); + + // Now try to select the already approved platform again - should revert + vm.startPrank(campaignOwner); + vm.expectRevert(CampaignInfo.CampaignInfoInvalidInput.selector); + campaignInfo.updateSelectedPlatform( + platformHash1, + true, + dataKeys, + dataValues + ); + vm.stopPrank(); + } + + // Helper function to lock the campaign + function _lockCampaign() internal { + // First select a platform + vm.startPrank(campaignOwner); + bytes32[] memory dataKeys = new bytes32[](1); + dataKeys[0] = platformDataKey1; + bytes32[] memory dataValues = new bytes32[](1); + dataValues[0] = platformDataValue1; + + campaignInfo.updateSelectedPlatform( + platformHash1, + true, + dataKeys, + dataValues + ); + vm.stopPrank(); + + // Then deploy a treasury (this locks the campaign) + vm.startPrank(admin); + treasuryFactory.deploy( + platformHash1, + address(campaignInfo), + 1, // implementationId + "Test Treasury", + "TT" + ); + vm.stopPrank(); + } +} \ No newline at end of file From e398868476af7c2441c81f830bc9c09e0f30401f Mon Sep 17 00:00:00 2001 From: AdnanHKx Date: Wed, 12 Nov 2025 06:43:10 +0600 Subject: [PATCH 48/63] Add PledgeNFT module and integrate into treasuries (#39) * Add time constraints for campaign creation * Fix unauthorized caller issue in tests * Exclude cancelled treasuries from total raised amount sum * Add PledgeNFT module and integrate into treasuries * Include additional fields for NFT metadata * Migrate NFT functionality from treasuries to campaign * Add NFT integration for Payment treasuries, fix burn authorization and test setup issues * Streamline minting process and add reentrancy guard to pledge functions * Rename treasury role and remove duplicate modifiers from _pledgeWithoutAReward * Fix burn authorization issue during claimRefund * Update external function declaration in CampaignInfoFactory to override interface method * Make claimRefund transfer funds to NFT owner regardless of caller * Update CampaignInfo unit test to apply NFT additions --------- Co-authored-by: adnhq Co-authored-by: Mahabub Alahi --- docs/UPGRADES.md | 353 ------------------ src/CampaignInfo.sol | 74 +++- src/CampaignInfoFactory.sol | 27 +- src/GlobalParams.sol | 2 +- src/TreasuryFactory.sol | 10 +- src/interfaces/ICampaignInfo.sol | 43 ++- src/interfaces/ICampaignInfoFactory.sol | 12 +- src/interfaces/ICampaignPaymentTreasury.sol | 25 +- src/interfaces/ICampaignTreasury.sol | 6 + src/interfaces/ITreasuryFactory.sol | 6 +- src/treasuries/AllOrNothing.sol | 71 ++-- src/treasuries/KeepWhatsRaised.sol | 87 ++--- src/treasuries/PaymentTreasury.sol | 27 +- .../TimeConstrainedPaymentTreasury.sol | 28 +- src/utils/BasePaymentTreasury.sol | 115 ++++-- src/utils/BaseTreasury.sol | 8 + src/utils/PledgeNFT.sol | 271 ++++++++++++++ test/foundry/Base.t.sol | 5 + .../AllOrNothing/AllOrNothing.t.sol | 12 +- .../AllOrNothing/AllOrNothingFunction.t.sol | 15 +- .../KeepWhatsRaised/KeepWhatsRaised.t.sol | 12 +- .../KeepWhatsRaisedFunction.t.sol | 12 +- .../PaymentTreasury/PaymentTreasury.t.sol | 18 +- .../PaymentTreasuryBatchLimitTest.t.sol | 2 +- .../PaymentTreasuryFunction.t.sol | 148 +++++++- .../TimeConstrainedPaymentTreasury.t.sol | 10 +- ...meConstrainedPaymentTreasuryFunction.t.sol | 4 + test/foundry/unit/CampaignInfo.t.sol | 22 +- test/foundry/unit/CampaignInfoFactory.t.sol | 24 +- test/foundry/unit/KeepWhatsRaised.t.sol | 51 ++- test/foundry/unit/PaymentTreasury.t.sol | 114 +++--- test/foundry/unit/PledgeNFT.t.sol | 165 ++++++++ .../unit/TimeConstrainedPaymentTreasury.t.sol | 24 +- test/foundry/unit/TreasuryFactory.t.sol | 4 +- test/foundry/unit/Upgrades.t.sol | 24 +- 35 files changed, 1161 insertions(+), 670 deletions(-) delete mode 100644 docs/UPGRADES.md create mode 100644 src/utils/PledgeNFT.sol create mode 100644 test/foundry/unit/PledgeNFT.t.sol diff --git a/docs/UPGRADES.md b/docs/UPGRADES.md deleted file mode 100644 index ccf93f13..00000000 --- a/docs/UPGRADES.md +++ /dev/null @@ -1,353 +0,0 @@ -# UUPS Upgradeable Contracts Guide - -## Overview - -The core protocol contracts (`GlobalParams`, `TreasuryFactory`, and `CampaignInfoFactory`) have been converted to UUPS (Universal Upgradeable Proxy Standard) upgradeable contracts with ERC-7201 namespaced storage. This document provides a comprehensive guide on the implementation and usage. - -## Architecture - -### UUPS Pattern - -The UUPS proxy pattern was chosen for the following benefits: -- **Gas Efficiency**: Upgrade logic is in the implementation contract, reducing proxy contract complexity -- **Self-Contained**: Each implementation contains its own upgrade authorization logic -- **ERC-1967 Compatible**: Uses standardized storage slots for implementation addresses - -### ERC-7201 Namespaced Storage - -All upgradeable contracts use ERC-7201 namespaced storage to prevent storage collisions: -- Storage variables are grouped into structs -- Each contract has a unique storage namespace calculated using `keccak256` -- Storage slots are deterministically calculated to avoid collisions - -## Contracts Converted - -### 1. GlobalParams - -**Storage Namespace**: `ccprotocol.storage.GlobalParams` - -**Key Changes**: -- Converted from regular contract to UUPS upgradeable -- Constructor logic moved to `initialize()` function -- All state variables moved to `GlobalParamsStorage` struct -- Added `_authorizeUpgrade()` function restricted to owner - -**Upgrade Authorization**: Only the contract owner can upgrade - -### 2. TreasuryFactory - -**Storage Namespace**: `ccprotocol.storage.TreasuryFactory` - -**Key Changes**: -- Converted from regular contract to UUPS upgradeable -- Constructor logic moved to `initialize()` function -- All state variables moved to `TreasuryFactoryStorage` struct -- Added `_authorizeUpgrade()` function restricted to protocol admin - -**Upgrade Authorization**: Only the protocol admin can upgrade - -### 3. CampaignInfoFactory - -**Storage Namespace**: `ccprotocol.storage.CampaignInfoFactory` - -**Key Changes**: -- Converted from regular contract to UUPS upgradeable -- Constructor logic moved to `initialize()` function -- All state variables moved to `CampaignInfoFactoryStorage` struct -- Added `_authorizeUpgrade()` function restricted to owner -- Removed legacy `_initialize()` function - -**Upgrade Authorization**: Only the contract owner can upgrade - -### 4. AdminAccessChecker - -**Storage Namespace**: `ccprotocol.storage.AdminAccessChecker` - -**Key Changes**: -- Converted to use namespaced storage -- `GLOBAL_PARAMS` moved to `AdminAccessCheckerStorage` struct -- Compatible with upgradeable contracts inheriting from it - -## Security Considerations - -### Initialization Protection - -All upgradeable contracts implement the following security measures: - -1. **Constructor Disabling**: Implementation contracts call `_disableInitializers()` in their constructor to prevent direct initialization -2. **Single Initialization**: The `initializer` modifier ensures `initialize()` can only be called once -3. **Upgrade Authorization**: Each contract restricts upgrades to authorized addresses - -### Storage Safety - -1. **Namespaced Storage**: Prevents storage collisions between upgrades -2. **Storage Layout Preservation**: Existing storage variables maintain their positions -3. **Gap Variables**: Not used as namespaced storage makes them unnecessary - -### Upgrade Best Practices - -When creating new implementation versions: - -1. ✅ **DO**: - - Add new state variables to the storage struct - - Add new functions - - Fix bugs in existing functions - - Test thoroughly before upgrading - -2. ❌ **DON'T**: - - Change the order of existing storage variables - - Remove existing storage variables - - Change the namespace location constant - - Modify the inheritance hierarchy - -## Deployment - -### Initial Deployment - -1. Deploy the implementation contract -2. Deploy an ERC1967Proxy pointing to the implementation -3. Call the proxy with initialization data - -Example: -```solidity -// 1. Deploy implementation -GlobalParams implementation = new GlobalParams(); - -// 2. Prepare initialization data -bytes memory initData = abi.encodeWithSelector( - GlobalParams.initialize.selector, - protocolAdmin, - protocolFeePercent, - currencies, - tokensPerCurrency -); - -// 3. Deploy proxy -ERC1967Proxy proxy = new ERC1967Proxy(address(implementation), initData); - -// 4. Use proxy address as the contract address -GlobalParams globalParams = GlobalParams(address(proxy)); -``` - -### Upgrading - -To upgrade an existing proxy: - -```solidity -// 1. Deploy new implementation -GlobalParams newImplementation = new GlobalParams(); - -// 2. Call upgradeToAndCall on the proxy (through the current implementation) -GlobalParams(proxyAddress).upgradeToAndCall(address(newImplementation), ""); -``` - -## Scripts - -### Deployment Scripts - -- `DeployGlobalParams.s.sol` - Deploys GlobalParams with UUPS proxy -- `DeployTreasuryFactory.s.sol` - Deploys TreasuryFactory with UUPS proxy -- `DeployCampaignInfoFactory.s.sol` - Deploys CampaignInfoFactory with UUPS proxy -- `DeployAll.s.sol` - Deploys all contracts with proxies - -### Upgrade Scripts - -- `UpgradeGlobalParams.s.sol` - Upgrades GlobalParams implementation -- `UpgradeTreasuryFactory.s.sol` - Upgrades TreasuryFactory implementation -- `UpgradeCampaignInfoFactory.s.sol` - Upgrades CampaignInfoFactory implementation - -### Usage - -Deploy all contracts: -```bash -forge script script/DeployAll.s.sol:DeployAll --rpc-url $RPC_URL --broadcast -``` - -Upgrade GlobalParams: -```bash -forge script script/UpgradeGlobalParams.s.sol:UpgradeGlobalParams --rpc-url $RPC_URL --broadcast -``` - -## Testing - -### Unit Tests - -All existing unit tests have been updated to work with the proxy pattern: -- `GlobalParams.t.sol` - Tests GlobalParams functionality and upgrades -- `TreasuryFactory.t.sol` - Tests TreasuryFactory functionality and upgrades -- `CampaignInfoFactory.t.sol` - Tests CampaignInfoFactory functionality and upgrades - -### Upgrade Tests - -`Upgrades.t.sol` contains comprehensive upgrade scenarios: -- Basic upgrade functionality -- Authorization checks -- Storage slot integrity -- Cross-contract upgrades -- Storage collision prevention -- Double initialization prevention - -### Running Tests - -Run all tests: -```bash -forge test -``` - -Run only upgrade tests: -```bash -forge test --match-path test/foundry/unit/Upgrades.t.sol -``` - -Run with verbosity: -```bash -forge test -vvv -``` - -## Important Notes - -### Immutable Args Encoding - -`CampaignInfo` contracts are created using `clones-with-immutable-args` library, which requires **`abi.encodePacked`** encoding: - -```solidity -// CORRECT - in CampaignInfoFactory.sol -bytes memory args = abi.encodePacked( - treasuryFactoryAddress, // 20 bytes at offset 0 - protocolFeePercent, // 32 bytes at offset 20 - identifierHash // 32 bytes at offset 52 -); -address clone = ClonesWithImmutableArgs.clone(implementation, args); -``` - -```solidity -// CORRECT - in CampaignInfo.sol (reading) -function getCampaignConfig() public view returns (Config memory config) { - config.treasuryFactory = _getArgAddress(0); // Read 20 bytes at offset 0 - config.protocolFeePercent = _getArgUint256(20); // Read 32 bytes at offset 20 - config.identifierHash = bytes32(_getArgUint256(52)); // Read 32 bytes at offset 52 -} -``` - -⚠️ **Do NOT use `abi.encode`** - it adds padding that breaks the offset calculations! - -## Dependencies - -### OpenZeppelin Contracts - -The implementation uses OpenZeppelin's upgradeable contracts: -- `@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol` -- `@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol` -- `@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol` -- `@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol` - -### Installation - -The upgradeable contracts library is installed at: -``` -lib/openzeppelin-contracts-upgradeable/ -``` - -Remappings in `foundry.toml`: -```toml -remappings = [ - "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/", - "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/" -] -``` - -## Storage Layouts - -### GlobalParams Storage - -```solidity -struct GlobalParamsStorage { - address protocolAdminAddress; - uint256 protocolFeePercent; - mapping(bytes32 => bool) platformIsListed; - mapping(bytes32 => address) platformAdminAddress; - mapping(bytes32 => uint256) platformFeePercent; - mapping(bytes32 => bytes32) platformDataOwner; - mapping(bytes32 => bool) platformData; - mapping(bytes32 => bytes32) dataRegistry; - mapping(bytes32 => address[]) currencyToTokens; - Counters.Counter numberOfListedPlatforms; -} -``` - -Storage Location: `0x8c8b3f8e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e00` - -### TreasuryFactory Storage - -```solidity -struct TreasuryFactoryStorage { - mapping(bytes32 => mapping(uint256 => address)) implementationMap; - mapping(address => bool) approvedImplementations; -} -``` - -Storage Location: `0x9c9c4f9e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e4e00` - -### CampaignInfoFactory Storage - -```solidity -struct CampaignInfoFactoryStorage { - IGlobalParams globalParams; - address treasuryFactoryAddress; - address implementation; - mapping(address => bool) isValidCampaignInfo; - mapping(bytes32 => address) identifierToCampaignInfo; -} -``` - -Storage Location: `0xacac5f0e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e5e00` - -## Upgrade Checklist - -Before performing an upgrade in production: - -- [ ] New implementation contract deployed and verified -- [ ] All tests passing (including upgrade tests) -- [ ] Storage layout verified for compatibility -- [ ] Authorization requirements met -- [ ] Upgrade transaction prepared and reviewed -- [ ] Rollback plan in place -- [ ] Monitor contract state after upgrade - -## Common Issues and Solutions - -### Issue: Initialization Failed - -**Cause**: Trying to initialize an implementation contract directly - -**Solution**: Always initialize through the proxy, not the implementation - -### Issue: Unauthorized Upgrade - -**Cause**: Attempting upgrade from non-authorized address - -**Solution**: Ensure the caller is: -- GlobalParams: contract owner -- TreasuryFactory: protocol admin -- CampaignInfoFactory: contract owner - -### Issue: Storage Collision - -**Cause**: Modifying existing storage variables in upgrade - -**Solution**: Only add new variables, never modify or remove existing ones - -## References - -- [EIP-1967: Proxy Storage Slots](https://eips.ethereum.org/EIPS/eip-1967) -- [EIP-1822: Universal Upgradeable Proxy Standard (UUPS)](https://eips.ethereum.org/EIPS/eip-1822) -- [ERC-7201: Namespaced Storage Layout](https://eips.ethereum.org/EIPS/eip-7201) -- [OpenZeppelin UUPS Proxies](https://docs.openzeppelin.com/contracts/5.x/api/proxy#UUPSUpgradeable) - -## Support - -For questions or issues related to upgrades, please refer to: -- Project documentation -- OpenZeppelin Upgrades documentation -- Foundry documentation for testing upgradeable contracts - diff --git a/src/CampaignInfo.sol b/src/CampaignInfo.sol index 2acd3707..3240dc09 100644 --- a/src/CampaignInfo.sol +++ b/src/CampaignInfo.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.22; import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol"; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol"; +import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import {ICampaignInfo} from "./interfaces/ICampaignInfo.sol"; import {ICampaignData} from "./interfaces/ICampaignData.sol"; @@ -12,6 +13,8 @@ import {IGlobalParams} from "./interfaces/IGlobalParams.sol"; import {TimestampChecker} from "./utils/TimestampChecker.sol"; import {AdminAccessChecker} from "./utils/AdminAccessChecker.sol"; import {PausableCancellable} from "./utils/PausableCancellable.sol"; +import {PledgeNFT} from "./utils/PledgeNFT.sol"; +import {Counters} from "./utils/Counters.sol"; import {DataRegistryKeys} from "./constants/DataRegistryKeys.sol"; /** @@ -25,8 +28,11 @@ contract CampaignInfo is PausableCancellable, TimestampChecker, AdminAccessChecker, + PledgeNFT, Initializable { + using Counters for Counters.Counter; + CampaignData private s_campaignData; mapping(bytes32 => address) private s_platformTreasuryAddress; @@ -135,9 +141,6 @@ contract CampaignInfo is */ error CampaignInfoIsLocked(); - constructor() Ownable(_msgSender()) { - _disableInitializers(); - } /** * @dev Modifier that checks if the campaign is not locked. @@ -148,6 +151,13 @@ contract CampaignInfo is } _; } + + /** + * @notice Constructor passes empty strings to ERC721 + */ + constructor() Ownable(_msgSender()) ERC721("", "") { + _disableInitializers(); + } function initialize( address creator, @@ -156,7 +166,11 @@ contract CampaignInfo is bytes32[] calldata platformDataKey, bytes32[] calldata platformDataValue, CampaignData calldata campaignData, - address[] calldata acceptedTokens + address[] calldata acceptedTokens, + string calldata nftName, + string calldata nftSymbol, + string calldata nftImageURI, + string calldata nftContractURI ) external initializer { __AccessChecker_init(globalParams); _transferOwnership(creator); @@ -180,6 +194,9 @@ contract CampaignInfo is for (uint256 i = 0; i < len; ++i) { s_platformData[platformDataKey[i]] = platformDataValue[i]; } + + // Initialize NFT metadata + _initializeNFT(nftName, nftSymbol, nftImageURI, nftContractURI); } struct Config { @@ -246,7 +263,10 @@ contract CampaignInfo is address tempTreasury; for (uint256 i = 0; i < length; i++) { tempTreasury = s_platformTreasuryAddress[tempPlatforms[i]]; - amount += ICampaignTreasury(tempTreasury).getRaisedAmount(); + // Skip cancelled treasuries + if (!ICampaignTreasury(tempTreasury).cancelled()) { + amount += ICampaignTreasury(tempTreasury).getRaisedAmount(); + } } return amount; } @@ -538,7 +558,46 @@ contract CampaignInfo is } /** - * @dev Sets platform information for the campaign. + * @notice Sets the image URI for NFT metadata + * @dev Can only be updated before campaign launch + * @param newImageURI The new image URI + */ + function setImageURI( + string calldata newImageURI + ) external override(ICampaignInfo, PledgeNFT) onlyOwner currentTimeIsLess(getLaunchTime()) { + s_imageURI = newImageURI; + emit ImageURIUpdated(newImageURI); + } + + /** + * @notice Updates the contract-level metadata URI + * @dev Can only be updated before campaign launch + * @param newContractURI The new contract URI + */ + function updateContractURI( + string calldata newContractURI + ) external override(ICampaignInfo, PledgeNFT) onlyOwner currentTimeIsLess(getLaunchTime()) { + s_contractURI = newContractURI; + emit ContractURIUpdated(newContractURI); + } + + function mintNFTForPledge( + address backer, + bytes32 reward, + address tokenAddress, + uint256 amount, + uint256 shippingFee, + uint256 tipAmount + ) public override(ICampaignInfo, PledgeNFT) returns (uint256 tokenId) { + return super.mintNFTForPledge(backer, reward, tokenAddress, amount, shippingFee, tipAmount); + } + + function burn(uint256 tokenId) public override(ICampaignInfo, PledgeNFT) { + super.burn(tokenId); + } + + /** + * @dev Sets platform information for the campaign and grants treasury role. * @param platformHash The bytes32 identifier of the platform. * @param platformTreasuryAddress The address of the platform's treasury. */ @@ -561,6 +620,8 @@ contract CampaignInfo is s_approvedPlatformHashes.push(platformHash); s_isApprovedPlatform[platformHash] = true; + // Grant MINTER_ROLE to allow treasury to mint pledge NFTs + _grantRole(MINTER_ROLE, platformTreasuryAddress); // Lock the campaign after the first treasury deployment if (!s_isLocked) { s_isLocked = true; @@ -571,4 +632,5 @@ contract CampaignInfo is platformTreasuryAddress ); } + } diff --git a/src/CampaignInfoFactory.sol b/src/CampaignInfoFactory.sol index 90c016a4..76ae146c 100644 --- a/src/CampaignInfoFactory.sol +++ b/src/CampaignInfoFactory.sol @@ -84,6 +84,17 @@ contract CampaignInfoFactory is Initializable, ICampaignInfoFactory, OwnableUpgr /** * @inheritdoc ICampaignInfoFactory + * @notice Creates a new campaign with NFT + * @param creator The campaign creator address + * @param identifierHash The unique identifier hash for the campaign + * @param selectedPlatformHash Array of selected platform hashes + * @param platformDataKey Array of platform data keys + * @param platformDataValue Array of platform data values + * @param campaignData The campaign data + * @param nftName NFT collection name + * @param nftSymbol NFT collection symbol + * @param nftImageURI NFT image URI for individual tokens + * @param contractURI IPFS URI for contract-level metadata (constructed off-chain) */ function createCampaign( address creator, @@ -91,7 +102,11 @@ contract CampaignInfoFactory is Initializable, ICampaignInfoFactory, OwnableUpgr bytes32[] calldata selectedPlatformHash, bytes32[] calldata platformDataKey, bytes32[] calldata platformDataValue, - CampaignData calldata campaignData + CampaignData calldata campaignData, + string calldata nftName, + string calldata nftSymbol, + string calldata nftImageURI, + string calldata contractURI ) external override { if (creator == address(0)) { revert CampaignInfoFactoryInvalidInput(); @@ -158,16 +173,22 @@ contract CampaignInfoFactory is Initializable, ICampaignInfoFactory, OwnableUpgr identifierHash ); address clone = Clones.cloneWithImmutableArgs($.implementation, args); + + // Initialize with all parameters including NFT metadata (bool success, ) = clone.call( abi.encodeWithSignature( - "initialize(address,address,bytes32[],bytes32[],bytes32[],(uint256,uint256,uint256,bytes32),address[])", + "initialize(address,address,bytes32[],bytes32[],bytes32[],(uint256,uint256,uint256,bytes32),address[],string,string,string,string)", creator, address(globalParams), selectedPlatformHash, platformDataKey, platformDataValue, campaignData, - acceptedTokens + acceptedTokens, + nftName, + nftSymbol, + nftImageURI, + contractURI ) ); if (!success) { diff --git a/src/GlobalParams.sol b/src/GlobalParams.sol index bb0b3faf..db72ee41 100644 --- a/src/GlobalParams.sol +++ b/src/GlobalParams.sol @@ -570,7 +570,7 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU /** * @dev Internal function to check if the sender is the platform administrator for a specific platform. - * If the sender is not the platform admin, it reverts with AdminAccessCheckerUnauthorized error. + * If the sender is not the platform admin, it reverts with GlobalParamsUnauthorized error. * @param platformHash The unique identifier of the platform. */ function _onlyPlatformAdmin(bytes32 platformHash) private view { diff --git a/src/TreasuryFactory.sol b/src/TreasuryFactory.sol index 8f5a0f96..b96ff4bc 100644 --- a/src/TreasuryFactory.sol +++ b/src/TreasuryFactory.sol @@ -104,9 +104,7 @@ contract TreasuryFactory is Initializable, ITreasuryFactory, AdminAccessChecker, function deploy( bytes32 platformHash, address infoAddress, - uint256 implementationId, - string calldata name, - string calldata symbol + uint256 implementationId ) external override @@ -123,11 +121,9 @@ contract TreasuryFactory is Initializable, ITreasuryFactory, AdminAccessChecker, (bool success, ) = clone.call( abi.encodeWithSignature( - "initialize(bytes32,address,string,string)", + "initialize(bytes32,address)", platformHash, - infoAddress, - name, - symbol + infoAddress ) ); if (!success) { diff --git a/src/interfaces/ICampaignInfo.sol b/src/interfaces/ICampaignInfo.sol index 50c3ad07..c80bec3f 100644 --- a/src/interfaces/ICampaignInfo.sol +++ b/src/interfaces/ICampaignInfo.sol @@ -1,11 +1,14 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.22; +import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol"; + /** * @title ICampaignInfo * @notice An interface for managing campaign information in a crowdfunding system. + * @dev Inherits from IERC721 as CampaignInfo is an ERC721 NFT collection */ -interface ICampaignInfo { +interface ICampaignInfo is IERC721 { /** * @notice Returns the owner of the contract. * @return The address of the contract owner. @@ -171,6 +174,44 @@ interface ICampaignInfo { */ function getBufferTime() external view returns (uint256 bufferTime); + /** + * @notice Mints a pledge NFT for a backer + * @dev Can only be called by treasuries with MINTER_ROLE + * @param backer The backer address + * @param reward The reward identifier + * @param tokenAddress The address of the token used for the pledge + * @param amount The pledge amount + * @param shippingFee The shipping fee + * @param tipAmount The tip amount + * @return tokenId The minted token ID (pledge ID) + */ + function mintNFTForPledge( + address backer, + bytes32 reward, + address tokenAddress, + uint256 amount, + uint256 shippingFee, + uint256 tipAmount + ) external returns (uint256 tokenId); + + /** + * @notice Sets the image URI for NFT metadata + * @param newImageURI The new image URI + */ + function setImageURI(string calldata newImageURI) external; + + /** + * @notice Updates the contract-level metadata URI + * @param newContractURI The new contract URI + */ + function updateContractURI(string calldata newContractURI) external; + + /** + * @notice Burns a pledge NFT + * @param tokenId The token ID to burn + */ + function burn(uint256 tokenId) external; + /** * @dev Returns true if the campaign is locked (after treasury deployment), and false otherwise. */ diff --git a/src/interfaces/ICampaignInfoFactory.sol b/src/interfaces/ICampaignInfoFactory.sol index 7f1af5a7..e6b1a44a 100644 --- a/src/interfaces/ICampaignInfoFactory.sol +++ b/src/interfaces/ICampaignInfoFactory.sol @@ -24,7 +24,7 @@ interface ICampaignInfoFactory is ICampaignData { event CampaignInfoFactoryCampaignInitialized(); /** - * @notice Creates a new campaign information contract. + * @notice Creates a new campaign information contract with NFT. * @dev IMPORTANT: Protocol and platform fees are retrieved at execution time and locked * permanently in the campaign contract. Users should verify current fees before * calling this function or using intermediate contracts that check fees haven't @@ -36,6 +36,10 @@ interface ICampaignInfoFactory is ICampaignData { * @param platformDataKey An array of platform-specific data keys. * @param platformDataValue An array of platform-specific data values. * @param campaignData The struct containing campaign launch details (including currency). + * @param nftName NFT collection name + * @param nftSymbol NFT collection symbol + * @param nftImageURI NFT image URI for individual tokens + * @param contractURI IPFS URI for contract-level metadata */ function createCampaign( address creator, @@ -43,7 +47,11 @@ interface ICampaignInfoFactory is ICampaignData { bytes32[] calldata selectedPlatformHash, bytes32[] calldata platformDataKey, bytes32[] calldata platformDataValue, - CampaignData calldata campaignData + CampaignData calldata campaignData, + string calldata nftName, + string calldata nftSymbol, + string calldata nftImageURI, + string calldata contractURI ) external; /** diff --git a/src/interfaces/ICampaignPaymentTreasury.sol b/src/interfaces/ICampaignPaymentTreasury.sol index 3e222215..49106f7e 100644 --- a/src/interfaces/ICampaignPaymentTreasury.sol +++ b/src/interfaces/ICampaignPaymentTreasury.sol @@ -71,17 +71,21 @@ interface ICampaignPaymentTreasury { /** * @notice Confirms and finalizes the payment associated with the given payment ID. * @param paymentId The unique identifier of the payment to confirm. + * @param buyerAddress Optional buyer address to mint NFT to. Pass address(0) to skip NFT minting. */ function confirmPayment( - bytes32 paymentId + bytes32 paymentId, + address buyerAddress ) external; /** * @notice Confirms and finalizes multiple payments in a single transaction. * @param paymentIds An array of unique payment identifiers to be confirmed. + * @param buyerAddresses Array of buyer addresses to mint NFTs to. Must match paymentIds length. Pass address(0) to skip NFT minting for specific payments. */ function confirmPaymentBatch( - bytes32[] calldata paymentIds + bytes32[] calldata paymentIds, + address[] calldata buyerAddresses ) external; /** @@ -95,15 +99,18 @@ interface ICampaignPaymentTreasury { function withdraw() external; /** - * @notice Claims a refund for a specific payment ID. - * @param paymentId The unique identifier of the refundable payment. + * @notice Claims a refund for non-NFT payments (payments without minted NFTs). + * @dev Only callable by platform admin. Used for payments confirmed without a buyer address. + * @param paymentId The unique identifier of the refundable payment (must NOT have an NFT). * @param refundAddress The address where the refunded amount should be sent. */ function claimRefund(bytes32 paymentId, address refundAddress) external; /** - * @notice Allows buyers to claim refunds for crypto payments, or platform admin to process refunds on behalf of buyers. - * @param paymentId The unique identifier of the refundable payment. + * @notice Claims a refund for NFT payments (payments with minted NFTs). + * @dev Burns the NFT associated with the payment. Caller must have approved the treasury for the NFT. + * Used for processCryptoPayment and confirmPayment (with buyer address) transactions. + * @param paymentId The unique identifier of the refundable payment (must have an NFT). */ function claimRefund( bytes32 paymentId @@ -132,4 +139,10 @@ interface ICampaignPaymentTreasury { * @return The current available raised amount as a uint256 value. */ function getAvailableRaisedAmount() external view returns (uint256); + + /** + * @notice Checks if the treasury has been cancelled. + * @return True if the treasury is cancelled, false otherwise. + */ + function cancelled() external view returns (bool); } diff --git a/src/interfaces/ICampaignTreasury.sol b/src/interfaces/ICampaignTreasury.sol index 1f2f85c9..5224203e 100644 --- a/src/interfaces/ICampaignTreasury.sol +++ b/src/interfaces/ICampaignTreasury.sol @@ -39,4 +39,10 @@ interface ICampaignTreasury { * @return The total raised amount as a uint256 value. */ function getRaisedAmount() external view returns (uint256); + + /** + * @notice Checks if the treasury has been cancelled. + * @return True if the treasury is cancelled, false otherwise. + */ + function cancelled() external view returns (bool); } diff --git a/src/interfaces/ITreasuryFactory.sol b/src/interfaces/ITreasuryFactory.sol index 55b89b2a..3782d60c 100644 --- a/src/interfaces/ITreasuryFactory.sol +++ b/src/interfaces/ITreasuryFactory.sol @@ -66,15 +66,11 @@ interface ITreasuryFactory { * @param platformHash The platform identifier. * @param infoAddress The address of the campaign info contract. * @param implementationId The ID of the implementation to use. - * @param name The name of the treasury token. - * @param symbol The symbol of the treasury token. * @return clone The address of the deployed treasury contract. */ function deploy( bytes32 platformHash, address infoAddress, - uint256 implementationId, - string calldata name, - string calldata symbol + uint256 implementationId ) external returns (address clone); } diff --git a/src/treasuries/AllOrNothing.sol b/src/treasuries/AllOrNothing.sol index 43e37324..a8ad5f29 100644 --- a/src/treasuries/AllOrNothing.sol +++ b/src/treasuries/AllOrNothing.sol @@ -2,12 +2,12 @@ pragma solidity ^0.8.22; import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; -import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol"; -import {ERC721Burnable} from "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol"; +import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; import {Counters} from "../utils/Counters.sol"; import {TimestampChecker} from "../utils/TimestampChecker.sol"; import {ICampaignTreasury} from "../interfaces/ICampaignTreasury.sol"; +import {ICampaignInfo} from "../interfaces/ICampaignInfo.sol"; import {BaseTreasury} from "../utils/BaseTreasury.sol"; import {IReward} from "../interfaces/IReward.sol"; @@ -19,7 +19,7 @@ contract AllOrNothing is IReward, BaseTreasury, TimestampChecker, - ERC721Burnable + ReentrancyGuard { using Counters for Counters.Counter; using SafeERC20 for IERC20; @@ -30,16 +30,12 @@ contract AllOrNothing is mapping(uint256 => uint256) private s_tokenToPledgedAmount; // Mapping to store reward details by name mapping(bytes32 => Reward) private s_reward; - // Mapping to store the token used for each NFT + // Mapping to store the token used for each pledge mapping(uint256 => address) private s_tokenIdToPledgeToken; - // Counters for token IDs and rewards - Counters.Counter private s_tokenIdCounter; + // Counter for reward tiers Counters.Counter private s_rewardCounter; - string private s_name; - string private s_symbol; - /** * @dev Emitted when a backer makes a pledge. * @param backer The address of the backer making the pledge. @@ -128,25 +124,13 @@ contract AllOrNothing is /** * @dev Constructor for the AllOrNothing contract. */ - constructor() ERC721("", "") {} + constructor() {} function initialize( bytes32 _platformHash, - address _infoAddress, - string calldata _name, - string calldata _symbol + address _infoAddress ) external initializer { __BaseContract_init(_platformHash, _infoAddress); - s_name = _name; - s_symbol = _symbol; - } - - function name() public view override returns (string memory) { - return s_name; - } - - function symbol() public view override returns (string memory) { - return s_symbol; } /** @@ -271,13 +255,13 @@ contract AllOrNothing is bytes32[] calldata reward ) external + nonReentrant currentTimeIsWithinRange(INFO.getLaunchTime(), INFO.getDeadline()) whenCampaignNotPaused whenNotPaused whenCampaignNotCancelled whenNotCancelled { - uint256 tokenId = s_tokenIdCounter.current(); uint256 rewardLen = reward.length; Reward storage tempReward = s_reward[reward[0]]; if ( @@ -299,7 +283,7 @@ contract AllOrNothing is } pledgeAmount += tempReward.rewardValue; } - _pledge(backer, pledgeToken, reward[0], pledgeAmount, shippingFee, tokenId, reward); + _pledge(backer, pledgeToken, reward[0], pledgeAmount, shippingFee, reward); } /** @@ -314,16 +298,16 @@ contract AllOrNothing is uint256 pledgeAmount ) external + nonReentrant currentTimeIsWithinRange(INFO.getLaunchTime(), INFO.getDeadline()) whenCampaignNotPaused whenNotPaused whenCampaignNotCancelled whenNotCancelled { - uint256 tokenId = s_tokenIdCounter.current(); bytes32[] memory emptyByteArray = new bytes32[](0); - _pledge(backer, pledgeToken, ZERO_BYTES, pledgeAmount, 0, tokenId, emptyByteArray); + _pledge(backer, pledgeToken, ZERO_BYTES, pledgeAmount, 0, emptyByteArray); } /** @@ -341,6 +325,10 @@ contract AllOrNothing is if (block.timestamp >= INFO.getDeadline() && _checkSuccessCondition()) { revert AllOrNothingNotClaimable(tokenId); } + + // Get NFT owner before burning + address nftOwner = INFO.ownerOf(tokenId); + uint256 amountToRefund = s_tokenToTotalCollectedAmount[tokenId]; uint256 pledgedAmount = s_tokenToPledgedAmount[tokenId]; address pledgeToken = s_tokenIdToPledgeToken[tokenId]; @@ -354,9 +342,11 @@ contract AllOrNothing is s_tokenRaisedAmounts[pledgeToken] -= pledgedAmount; delete s_tokenIdToPledgeToken[tokenId]; - burn(tokenId); - IERC20(pledgeToken).safeTransfer(_msgSender(), amountToRefund); - emit RefundClaimed(tokenId, amountToRefund, _msgSender()); + // Burn the NFT (requires treasury approval from owner) + INFO.burn(tokenId); + + IERC20(pledgeToken).safeTransfer(nftOwner, amountToRefund); + emit RefundClaimed(tokenId, amountToRefund, nftOwner); } /** @@ -415,7 +405,6 @@ contract AllOrNothing is bytes32 reward, uint256 pledgeAmount, uint256 shippingFee, - uint256 tokenId, bytes32[] memory rewards ) private { // Validate token is accepted @@ -442,13 +431,21 @@ contract AllOrNothing is IERC20(pledgeToken).safeTransferFrom(backer, address(this), totalAmount); - s_tokenIdCounter.increment(); + s_tokenRaisedAmounts[pledgeToken] += pledgeAmountInTokenDecimals; + + uint256 tokenId = INFO.mintNFTForPledge( + backer, + reward, + pledgeToken, + pledgeAmountInTokenDecimals, + shippingFeeInTokenDecimals, + 0 + ); + s_tokenToPledgedAmount[tokenId] = pledgeAmountInTokenDecimals; s_tokenToTotalCollectedAmount[tokenId] = totalAmount; s_tokenIdToPledgeToken[tokenId] = pledgeToken; - s_tokenRaisedAmounts[pledgeToken] += pledgeAmountInTokenDecimals; - _safeMint(backer, tokenId, abi.encodePacked(backer, reward, rewards)); emit Receipt( backer, pledgeToken, @@ -460,10 +457,4 @@ contract AllOrNothing is ); } - // The following functions are overrides required by Solidity. - function supportsInterface( - bytes4 interfaceId - ) public view override returns (bool) { - return super.supportsInterface(interfaceId); - } } diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index 6f8fc9a8..38e590d1 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -3,13 +3,13 @@ pragma solidity ^0.8.22; import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; -import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol"; -import {ERC721Burnable} from "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol"; +import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; import {Counters} from "../utils/Counters.sol"; import {TimestampChecker} from "../utils/TimestampChecker.sol"; import {BaseTreasury} from "../utils/BaseTreasury.sol"; import {ICampaignTreasury} from "../interfaces/ICampaignTreasury.sol"; +import {ICampaignInfo} from "../interfaces/ICampaignInfo.sol"; import {IReward} from "../interfaces/IReward.sol"; import {ICampaignData} from "../interfaces/ICampaignData.sol"; @@ -21,8 +21,8 @@ contract KeepWhatsRaised is IReward, BaseTreasury, TimestampChecker, - ERC721Burnable, - ICampaignData + ICampaignData, + ReentrancyGuard { using Counters for Counters.Counter; using SafeERC20 for IERC20; @@ -43,14 +43,13 @@ contract KeepWhatsRaised is mapping(bytes32 => uint256) private s_feeValues; // Multi-token support - mapping(uint256 => address) private s_tokenIdToPledgeToken; // Token used for each NFT + mapping(uint256 => address) private s_tokenIdToPledgeToken; // Token used for each pledge mapping(address => uint256) private s_protocolFeePerToken; // Protocol fees per token mapping(address => uint256) private s_platformFeePerToken; // Platform fees per token mapping(address => uint256) private s_tipPerToken; // Tips per token mapping(address => uint256) private s_availablePerToken; // Available amount per token - // Counters for token IDs and rewards - Counters.Counter private s_tokenIdCounter; + // Counter for reward tiers Counters.Counter private s_rewardCounter; /** @@ -103,8 +102,6 @@ contract KeepWhatsRaised is bool isColombianCreator; } - string private s_name; - string private s_symbol; uint256 private s_cancellationTime; bool private s_isWithdrawalApproved; bool private s_tipClaimed; @@ -334,25 +331,13 @@ contract KeepWhatsRaised is /** * @dev Constructor for the KeepWhatsRaised contract. */ - constructor() ERC721("", "") {} + constructor() {} function initialize( bytes32 _platformHash, - address _infoAddress, - string calldata _name, - string calldata _symbol + address _infoAddress ) external initializer { __BaseContract_init(_platformHash, _infoAddress); - s_name = _name; - s_symbol = _symbol; - } - - function name() public view override returns (string memory) { - return s_name; - } - - function symbol() public view override returns (string memory) { - return s_symbol; } /** @@ -693,6 +678,7 @@ contract KeepWhatsRaised is bool isPledgeForAReward ) external + nonReentrant onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenNotPaused @@ -727,6 +713,7 @@ contract KeepWhatsRaised is bytes32[] calldata reward ) public + nonReentrant currentTimeIsWithinRange(getLaunchTime(), getDeadline()) whenCampaignNotPaused whenNotPaused @@ -758,11 +745,6 @@ contract KeepWhatsRaised is address tokenSource ) internal - currentTimeIsWithinRange(getLaunchTime(), getDeadline()) - whenCampaignNotPaused - whenNotPaused - whenCampaignNotCancelled - whenNotCancelled { bytes32 internalPledgeId = keccak256(abi.encodePacked(pledgeId, _msgSender())); @@ -771,7 +753,6 @@ contract KeepWhatsRaised is } s_processedPledges[internalPledgeId] = true; - uint256 tokenId = s_tokenIdCounter.current(); uint256 rewardLen = reward.length; Reward memory tempReward = s_reward[reward[0]]; if ( @@ -793,7 +774,7 @@ contract KeepWhatsRaised is } pledgeAmount += tempReward.rewardValue; } - _pledge(pledgeId, backer, pledgeToken, reward[0], pledgeAmount, tip, tokenId, reward, tokenSource); + _pledge(pledgeId, backer, pledgeToken, reward[0], pledgeAmount, tip, reward, tokenSource); } /** @@ -812,6 +793,7 @@ contract KeepWhatsRaised is uint256 tip ) public + nonReentrant currentTimeIsWithinRange(getLaunchTime(), getDeadline()) whenCampaignNotPaused whenNotPaused @@ -841,11 +823,6 @@ contract KeepWhatsRaised is address tokenSource ) internal - currentTimeIsWithinRange(getLaunchTime(), getDeadline()) - whenCampaignNotPaused - whenNotPaused - whenCampaignNotCancelled - whenNotCancelled { bytes32 internalPledgeId = keccak256(abi.encodePacked(pledgeId, _msgSender())); @@ -854,10 +831,9 @@ contract KeepWhatsRaised is } s_processedPledges[internalPledgeId] = true; - uint256 tokenId = s_tokenIdCounter.current(); bytes32[] memory emptyByteArray = new bytes32[](0); - _pledge(pledgeId, backer, pledgeToken, ZERO_BYTES, pledgeAmount, tip, tokenId, emptyByteArray, tokenSource); + _pledge(pledgeId, backer, pledgeToken, ZERO_BYTES, pledgeAmount, tip, emptyByteArray, tokenSource); } /** @@ -1001,6 +977,9 @@ contract KeepWhatsRaised is revert KeepWhatsRaisedNotClaimable(tokenId); } + // Get NFT owner before burning + address nftOwner = INFO.ownerOf(tokenId); + address pledgeToken = s_tokenIdToPledgeToken[tokenId]; uint256 amountToRefund = s_tokenToPledgedAmount[tokenId]; uint256 paymentFee = s_tokenToPaymentFee[tokenId]; @@ -1015,9 +994,11 @@ contract KeepWhatsRaised is s_availablePerToken[pledgeToken] -= netRefundAmount; s_tokenToPaymentFee[tokenId] = 0; - burn(tokenId); - IERC20(pledgeToken).safeTransfer(_msgSender(), netRefundAmount); - emit RefundClaimed(tokenId, netRefundAmount, _msgSender()); + // Burn the NFT (requires treasury approval from owner) + INFO.burn(tokenId); + + IERC20(pledgeToken).safeTransfer(nftOwner, netRefundAmount); + emit RefundClaimed(tokenId, netRefundAmount, nftOwner); } /** @@ -1165,7 +1146,6 @@ contract KeepWhatsRaised is bytes32 reward, uint256 pledgeAmount, uint256 tip, - uint256 tokenId, bytes32[] memory rewards, address tokenSource ) private { @@ -1186,24 +1166,29 @@ contract KeepWhatsRaised is pledgeAmountInTokenDecimals = pledgeAmount; } - // Tip is already in token's decimals, no denormalization needed uint256 totalAmount = pledgeAmountInTokenDecimals + tip; - // Transfer tokens from tokenSource (either admin or backer) IERC20(pledgeToken).safeTransferFrom(tokenSource, address(this), totalAmount); - s_tokenIdCounter.increment(); + s_tipPerToken[pledgeToken] += tip; + s_tokenRaisedAmounts[pledgeToken] += pledgeAmountInTokenDecimals; + + uint256 tokenId = INFO.mintNFTForPledge( + backer, + reward, + pledgeToken, + pledgeAmountInTokenDecimals, + 0, + tip + ); + s_tokenToPledgedAmount[tokenId] = pledgeAmountInTokenDecimals; s_tokenToTippedAmount[tokenId] = tip; s_tokenIdToPledgeToken[tokenId] = pledgeToken; - s_tipPerToken[pledgeToken] += tip; - s_tokenRaisedAmounts[pledgeToken] += pledgeAmountInTokenDecimals; - //Fee Calculation (uses token decimals) uint256 netAvailable = _calculateNetAvailable(pledgeId, pledgeToken, tokenId, pledgeAmountInTokenDecimals); s_availablePerToken[pledgeToken] += netAvailable; - _safeMint(backer, tokenId, abi.encodePacked(backer, reward)); emit Receipt( backer, pledgeToken, @@ -1299,10 +1284,4 @@ contract KeepWhatsRaised is } } - // The following functions are overrides required by Solidity. - function supportsInterface( - bytes4 interfaceId - ) public view override returns (bool) { - return super.supportsInterface(interfaceId); - } } diff --git a/src/treasuries/PaymentTreasury.sol b/src/treasuries/PaymentTreasury.sol index fe62cf3d..05eb0bc2 100644 --- a/src/treasuries/PaymentTreasury.sol +++ b/src/treasuries/PaymentTreasury.sol @@ -11,9 +11,6 @@ contract PaymentTreasury is { using SafeERC20 for IERC20; - string private s_name; - string private s_symbol; - /** * @dev Emitted when an unauthorized action is attempted. */ @@ -26,21 +23,9 @@ contract PaymentTreasury is function initialize( bytes32 _platformHash, - address _infoAddress, - string calldata _name, - string calldata _symbol + address _infoAddress ) external initializer { __BaseContract_init(_platformHash, _infoAddress); - s_name = _name; - s_symbol = _symbol; - } - - function name() public view returns (string memory) { - return s_name; - } - - function symbol() public view returns (string memory) { - return s_symbol; } /** @@ -97,18 +82,20 @@ contract PaymentTreasury is * @inheritdoc ICampaignPaymentTreasury */ function confirmPayment( - bytes32 paymentId + bytes32 paymentId, + address buyerAddress ) public override whenNotPaused whenNotCancelled { - super.confirmPayment(paymentId); + super.confirmPayment(paymentId, buyerAddress); } /** * @inheritdoc ICampaignPaymentTreasury */ function confirmPaymentBatch( - bytes32[] calldata paymentIds + bytes32[] calldata paymentIds, + address[] calldata buyerAddresses ) public override whenNotPaused whenNotCancelled { - super.confirmPaymentBatch(paymentIds); + super.confirmPaymentBatch(paymentIds, buyerAddresses); } /** diff --git a/src/treasuries/TimeConstrainedPaymentTreasury.sol b/src/treasuries/TimeConstrainedPaymentTreasury.sol index 3d663e99..f3258f99 100644 --- a/src/treasuries/TimeConstrainedPaymentTreasury.sol +++ b/src/treasuries/TimeConstrainedPaymentTreasury.sol @@ -13,10 +13,6 @@ contract TimeConstrainedPaymentTreasury is { using SafeERC20 for IERC20; - string private s_name; - string private s_symbol; - - /** * @dev Emitted when an unauthorized action is attempted. */ @@ -29,21 +25,9 @@ contract TimeConstrainedPaymentTreasury is function initialize( bytes32 _platformHash, - address _infoAddress, - string calldata _name, - string calldata _symbol + address _infoAddress ) external initializer { __BaseContract_init(_platformHash, _infoAddress); - s_name = _name; - s_symbol = _symbol; - } - - function name() public view returns (string memory) { - return s_name; - } - - function symbol() public view returns (string memory) { - return s_symbol; } /** @@ -122,20 +106,22 @@ contract TimeConstrainedPaymentTreasury is * @inheritdoc ICampaignPaymentTreasury */ function confirmPayment( - bytes32 paymentId + bytes32 paymentId, + address buyerAddress ) public override whenCampaignNotPaused whenCampaignNotCancelled { _checkTimeWithinRange(); - super.confirmPayment(paymentId); + super.confirmPayment(paymentId, buyerAddress); } /** * @inheritdoc ICampaignPaymentTreasury */ function confirmPaymentBatch( - bytes32[] calldata paymentIds + bytes32[] calldata paymentIds, + address[] calldata buyerAddresses ) public override whenCampaignNotPaused whenCampaignNotCancelled { _checkTimeWithinRange(); - super.confirmPaymentBatch(paymentIds); + super.confirmPaymentBatch(paymentIds, buyerAddresses); } /** diff --git a/src/utils/BasePaymentTreasury.sol b/src/utils/BasePaymentTreasury.sol index 49902645..6f8ed8d4 100644 --- a/src/utils/BasePaymentTreasury.sol +++ b/src/utils/BasePaymentTreasury.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.22; import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol"; +import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; import {ICampaignPaymentTreasury} from "../interfaces/ICampaignPaymentTreasury.sol"; import {CampaignAccessChecker} from "./CampaignAccessChecker.sol"; @@ -13,7 +14,8 @@ abstract contract BasePaymentTreasury is Initializable, ICampaignPaymentTreasury, CampaignAccessChecker, - PausableCancellable + PausableCancellable, + ReentrancyGuard { using SafeERC20 for IERC20; @@ -29,6 +31,7 @@ abstract contract BasePaymentTreasury is mapping(bytes32 => address) internal s_paymentIdToToken; // Track token used for each payment mapping(address => uint256) internal s_platformFeePerToken; // Platform fees per token mapping(address => uint256) internal s_protocolFeePerToken; // Protocol fees per token + mapping(bytes32 => uint256) internal s_paymentIdToTokenId; // Track NFT token ID for each payment (0 means no NFT) /** * @dev Stores information about a payment in the treasury. @@ -238,23 +241,6 @@ abstract contract BasePaymentTreasury is _; } - /** - * @notice Ensures that the caller is either the payment's buyer or the platform admin. - * @param paymentId The unique identifier of the payment to validate access for. - */ - modifier onlyBuyerOrPlatformAdmin(bytes32 paymentId) { - PaymentInfo memory payment = s_payment[paymentId]; - address buyerAddress = payment.buyerAddress; - - if ( - _msgSender() != buyerAddress && - _msgSender() != INFO.getPlatformAdminAddress(PLATFORM_HASH) - ) { - revert PaymentTreasuryPaymentNotClaimable(paymentId); - } - _; - } - /** * @inheritdoc ICampaignPaymentTreasury */ @@ -477,7 +463,7 @@ abstract contract BasePaymentTreasury is address buyerAddress, address paymentToken, uint256 amount - ) public override virtual whenCampaignNotPaused whenCampaignNotCancelled { + ) public override virtual nonReentrant whenCampaignNotPaused whenCampaignNotCancelled { if(buyerAddress == address(0) || amount == 0 || @@ -513,6 +499,17 @@ abstract contract BasePaymentTreasury is s_confirmedPaymentPerToken[paymentToken] += amount; s_availableConfirmedPerToken[paymentToken] += amount; + // Mint NFT for crypto payment + uint256 tokenId = INFO.mintNFTForPledge( + buyerAddress, + itemId, // Using itemId as the reward identifier + paymentToken, + amount, + 0, // shippingFee (0 for payment treasuries) + 0 // tipAmount (0 for payment treasuries) + ); + s_paymentIdToTokenId[paymentId] = tokenId; + emit PaymentCreated( buyerAddress, paymentId, @@ -539,6 +536,7 @@ abstract contract BasePaymentTreasury is delete s_payment[paymentId]; delete s_paymentIdToToken[paymentId]; + delete s_paymentIdToTokenId[paymentId]; s_pendingPaymentPerToken[paymentToken] -= amount; @@ -549,8 +547,9 @@ abstract contract BasePaymentTreasury is * @inheritdoc ICampaignPaymentTreasury */ function confirmPayment( - bytes32 paymentId - ) public override virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { + bytes32 paymentId, + address buyerAddress + ) public override virtual nonReentrant onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { _validatePaymentForAction(paymentId); address paymentToken = s_paymentIdToToken[paymentId]; @@ -575,6 +574,21 @@ abstract contract BasePaymentTreasury is s_confirmedPaymentPerToken[paymentToken] += paymentAmount; s_availableConfirmedPerToken[paymentToken] += paymentAmount; + // Mint NFT if buyerAddress is provided + if (buyerAddress != address(0)) { + s_payment[paymentId].buyerAddress = buyerAddress; + bytes32 itemId = s_payment[paymentId].itemId; + uint256 tokenId = INFO.mintNFTForPledge( + buyerAddress, + itemId, // Using itemId as the reward identifier + paymentToken, + paymentAmount, + 0, // shippingFee (0 for payment treasuries) + 0 // tipAmount (0 for payment treasuries) + ); + s_paymentIdToTokenId[paymentId] = tokenId; + } + emit PaymentConfirmed(paymentId); } @@ -582,8 +596,14 @@ abstract contract BasePaymentTreasury is * @inheritdoc ICampaignPaymentTreasury */ function confirmPaymentBatch( - bytes32[] calldata paymentIds - ) public override virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { + bytes32[] calldata paymentIds, + address[] calldata buyerAddresses + ) public override virtual nonReentrant onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { + + // Validate array lengths must match + if (buyerAddresses.length != paymentIds.length) { + revert PaymentTreasuryInvalidInput(); + } bytes32 currentPaymentId; address currentToken; @@ -614,6 +634,22 @@ abstract contract BasePaymentTreasury is s_confirmedPaymentPerToken[currentToken] += amount; s_availableConfirmedPerToken[currentToken] += amount; + // Mint NFT if buyer address provided for this payment + if (buyerAddresses[i] != address(0)) { + address buyerAddress = buyerAddresses[i]; + s_payment[currentPaymentId].buyerAddress = buyerAddress; + bytes32 itemId = s_payment[currentPaymentId].itemId; + uint256 tokenId = INFO.mintNFTForPledge( + buyerAddress, + itemId, // Using itemId as the reward identifier + currentToken, + amount, + 0, // shippingFee (0 for payment treasuries) + 0 // tipAmount (0 for payment treasuries) + ); + s_paymentIdToTokenId[currentPaymentId] = tokenId; + } + unchecked { ++i; } @@ -624,6 +660,7 @@ abstract contract BasePaymentTreasury is /** * @inheritdoc ICampaignPaymentTreasury + * @dev For non-NFT payments only. Verifies that no NFT exists for this payment. */ function claimRefund( bytes32 paymentId, @@ -637,6 +674,7 @@ abstract contract BasePaymentTreasury is address paymentToken = s_paymentIdToToken[paymentId]; uint256 amountToRefund = payment.amount; uint256 availablePaymentAmount = s_availableConfirmedPerToken[paymentToken]; + uint256 tokenId = s_paymentIdToTokenId[paymentId]; if (payment.buyerId == ZERO_BYTES) { revert PaymentTreasuryPaymentNotExist(paymentId); @@ -647,6 +685,10 @@ abstract contract BasePaymentTreasury is if (amountToRefund == 0 || availablePaymentAmount < amountToRefund) { revert PaymentTreasuryPaymentNotClaimable(paymentId); } + // This function is for non-NFT payments only + if (tokenId != 0) { + revert PaymentTreasuryCryptoPayment(paymentId); + } delete s_payment[paymentId]; delete s_paymentIdToToken[paymentId]; @@ -660,16 +702,18 @@ abstract contract BasePaymentTreasury is /** * @inheritdoc ICampaignPaymentTreasury + * @dev For NFT payments only. Requires an NFT exists and burns it. Refund is sent to current NFT owner. */ function claimRefund( bytes32 paymentId - ) public override virtual onlyBuyerOrPlatformAdmin(paymentId) whenCampaignNotPaused whenCampaignNotCancelled + ) public override virtual whenCampaignNotPaused whenCampaignNotCancelled { PaymentInfo memory payment = s_payment[paymentId]; address paymentToken = s_paymentIdToToken[paymentId]; address buyerAddress = payment.buyerAddress; uint256 amountToRefund = payment.amount; uint256 availablePaymentAmount = s_availableConfirmedPerToken[paymentToken]; + uint256 tokenId = s_paymentIdToTokenId[paymentId]; if (buyerAddress == address(0)) { revert PaymentTreasuryPaymentNotExist(paymentId); @@ -677,15 +721,26 @@ abstract contract BasePaymentTreasury is if (amountToRefund == 0 || availablePaymentAmount < amountToRefund) { revert PaymentTreasuryPaymentNotClaimable(paymentId); } + // This function is for NFT payments only - NFT must exist + if (tokenId == 0) { + revert PaymentTreasuryPaymentNotClaimable(paymentId); + } + + // Get NFT owner before burning + address nftOwner = INFO.ownerOf(tokenId); delete s_payment[paymentId]; delete s_paymentIdToToken[paymentId]; + delete s_paymentIdToTokenId[paymentId]; s_confirmedPaymentPerToken[paymentToken] -= amountToRefund; s_availableConfirmedPerToken[paymentToken] -= amountToRefund; - IERC20(paymentToken).safeTransfer(buyerAddress, amountToRefund); - emit RefundClaimed(paymentId, amountToRefund, buyerAddress); + // Burn NFT (requires treasury approval from owner) + INFO.burn(tokenId); + + IERC20(paymentToken).safeTransfer(nftOwner, amountToRefund); + emit RefundClaimed(paymentId, amountToRefund, nftOwner); } /** @@ -807,6 +862,14 @@ abstract contract BasePaymentTreasury is _cancel(message); } + /** + * @notice Returns true if the treasury has been cancelled. + * @return True if cancelled, false otherwise. + */ + function cancelled() public view virtual override(ICampaignPaymentTreasury, PausableCancellable) returns (bool) { + return super.cancelled(); + } + /** * @dev Internal function to check if the campaign is paused. * If the campaign is paused, it reverts with PaymentTreasuryCampaignInfoIsPaused error. diff --git a/src/utils/BaseTreasury.sol b/src/utils/BaseTreasury.sol index 74516cb8..fef3ba6c 100644 --- a/src/utils/BaseTreasury.sol +++ b/src/utils/BaseTreasury.sol @@ -258,6 +258,14 @@ abstract contract BaseTreasury is _cancel(message); } + /** + * @notice Returns true if the treasury has been cancelled. + * @return True if cancelled, false otherwise. + */ + function cancelled() public view virtual override(ICampaignTreasury, PausableCancellable) returns (bool) { + return super.cancelled(); + } + /** * @dev Internal function to check if the campaign is paused. * If the campaign is paused, it reverts with TreasuryCampaignInfoIsPaused error. diff --git a/src/utils/PledgeNFT.sol b/src/utils/PledgeNFT.sol new file mode 100644 index 00000000..edad3c38 --- /dev/null +++ b/src/utils/PledgeNFT.sol @@ -0,0 +1,271 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.22; + +import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol"; +import {ERC721Burnable} from "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol"; +import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol"; +import {Strings} from "@openzeppelin/contracts/utils/Strings.sol"; +import {Base64} from "@openzeppelin/contracts/utils/Base64.sol"; +import {Counters} from "./Counters.sol"; + +/** + * @title PledgeNFT + * @notice Abstract contract for NFTs representing pledges with on-chain metadata + * @dev Contains counter logic and NFT metadata storage + */ +abstract contract PledgeNFT is ERC721Burnable, AccessControl { + using Strings for uint256; + using Strings for address; + using Counters for Counters.Counter; + + bytes32 public constant MINTER_ROLE = 0x9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6; + + /** + * @dev Struct to store pledge data for each token + */ + struct PledgeData { + address backer; + bytes32 reward; + address treasury; + address tokenAddress; + uint256 amount; + uint256 shippingFee; + uint256 tipAmount; + } + + // NFT metadata storage + string internal s_nftName; + string internal s_nftSymbol; + string internal s_imageURI; + string internal s_contractURI; + + // Token ID counter (also serves as pledge ID counter) + Counters.Counter internal s_tokenIdCounter; + + // Mapping from token ID to pledge data + mapping(uint256 => PledgeData) internal s_pledgeData; + + /** + * @dev Emitted when the image URI is updated + * @param newImageURI The new image URI + */ + event ImageURIUpdated(string newImageURI); + + /** + * @dev Emitted when the contract URI is updated + * @param newContractURI The new contract URI + */ + event ContractURIUpdated(string newContractURI); + + /** + * @dev Emitted when a pledge NFT is minted + * @param tokenId The token ID + * @param backer The backer address + * @param treasury The treasury address + * @param reward The reward identifier + */ + event PledgeNFTMinted( + uint256 indexed tokenId, + address indexed backer, + address indexed treasury, + bytes32 reward + ); + + /** + * @dev Emitted when unauthorized access is attempted + */ + error PledgeNFTUnAuthorized(); + + /** + * @notice Initialize NFT metadata + * @dev Called by CampaignInfo during initialization + * @param _nftName NFT collection name + * @param _nftSymbol NFT collection symbol + * @param _imageURI NFT image URI for individual tokens + * @param _contractURI IPFS URI for contract-level metadata + */ + function _initializeNFT( + string calldata _nftName, + string calldata _nftSymbol, + string calldata _imageURI, + string calldata _contractURI + ) internal { + s_nftName = _nftName; + s_nftSymbol = _nftSymbol; + s_imageURI = _imageURI; + s_contractURI = _contractURI; + } + + /** + * @notice Mints a pledge NFT (auto-increments counter) + * @dev Called by treasuries - returns the new token ID to use as pledge ID + * @param backer The backer address + * @param reward The reward identifier + * @param tokenAddress The address of the token used for the pledge + * @param amount The pledge amount + * @param shippingFee The shipping fee + * @param tipAmount The tip amount + * @return tokenId The minted token ID (to be used as pledge ID in treasury) + */ + function mintNFTForPledge( + address backer, + bytes32 reward, + address tokenAddress, + uint256 amount, + uint256 shippingFee, + uint256 tipAmount + ) public virtual onlyRole(MINTER_ROLE) returns (uint256 tokenId) { + // Increment counter and get new token ID + s_tokenIdCounter.increment(); + tokenId = s_tokenIdCounter.current(); + + // Set pledge data + s_pledgeData[tokenId] = PledgeData({ + backer: backer, + reward: reward, + treasury: _msgSender(), + tokenAddress: tokenAddress, + amount: amount, + shippingFee: shippingFee, + tipAmount: tipAmount + }); + + // Mint NFT + _safeMint(backer, tokenId); + + emit PledgeNFTMinted(tokenId, backer, msg.sender, reward); + + return tokenId; + } + + /** + * @notice Burns a pledge NFT + * @param tokenId The token ID to burn + */ + function burn(uint256 tokenId) public virtual override { + delete s_pledgeData[tokenId]; + super.burn(tokenId); + } + + /** + * @notice Override name to return initialized name + * @return The NFT collection name + */ + function name() public view virtual override returns (string memory) { + return s_nftName; + } + + /** + * @notice Override symbol to return initialized symbol + * @return The NFT collection symbol + */ + function symbol() public view virtual override returns (string memory) { + return s_nftSymbol; + } + + /** + * @notice Sets the image URI for all NFTs + * @dev Must be overridden by inheriting contracts to implement access control + * @param newImageURI The new image URI + */ + function setImageURI(string calldata newImageURI) external virtual; + + /** + * @notice Returns contract-level metadata URI + * @return The contract URI + */ + function contractURI() external view virtual returns (string memory) { + return s_contractURI; + } + + /** + * @notice Update contract-level metadata URI + * @dev Must be overridden by inheriting contracts to implement access control + * @param newContractURI The new contract URI + */ + function updateContractURI(string calldata newContractURI) external virtual; + + /** + * @notice Gets current total number of pledges + * @return The current pledge count + */ + function getPledgeCount() external view virtual returns (uint256) { + return s_tokenIdCounter.current(); + } + + /** + * @notice Returns the token URI with on-chain metadata + * @param tokenId The token ID + * @return The base64 encoded JSON metadata + */ + function tokenURI( + uint256 tokenId + ) public view virtual override returns (string memory) { + _requireOwned(tokenId); + + PledgeData memory data = s_pledgeData[tokenId]; + + string memory json = string( + abi.encodePacked( + '{"name":"', name(), " #", tokenId.toString(), + '","image":"', s_imageURI, + '","attributes":[', + '{"trait_type":"Backer","value":"', Strings.toHexString(uint160(data.backer), 20), '"},', + '{"trait_type":"Reward","value":"', Strings.toHexString(uint256(data.reward), 32), '"},', + '{"trait_type":"Treasury","value":"', Strings.toHexString(uint160(data.treasury), 20), '"},', + '{"trait_type":"Campaign","value":"', Strings.toHexString(uint160(address(this)), 20), '"},', + '{"trait_type":"PledgeToken","value":"', Strings.toHexString(uint160(data.tokenAddress), 20), '"},', + '{"trait_type":"PledgeAmount","value":"', data.amount.toString(), '"},', + '{"trait_type":"ShippingFee","value":"', data.shippingFee.toString(), '"},', + '{"trait_type":"TipAmount","value":"', data.tipAmount.toString(), '"}', + "]}" + ) + ); + + return string(abi.encodePacked("data:application/json;base64,", Base64.encode(bytes(json)))); + } + + /** + * @notice Gets the image URI + * @return The current image URI + */ + function getImageURI() external view returns (string memory) { + return s_imageURI; + } + + /** + * @notice Gets the pledge data for a token + * @param tokenId The token ID + * @return The pledge data + */ + function getPledgeData(uint256 tokenId) external view returns (PledgeData memory) { + return s_pledgeData[tokenId]; + } + + /** + * @dev Internal function to set pledge data for a token + * @param tokenId The token ID + * @param backer The backer address + * @param reward The reward identifier + * @param tokenAddress The address of the token used for the pledge + * @param amount The pledge amount + * @param shippingFee The shipping fee + * @param tipAmount The tip amount + */ + + /** + * @notice Override supportsInterface for multiple inheritance + * @param interfaceId The interface ID + * @return True if the interface is supported + */ + function supportsInterface(bytes4 interfaceId) + public + view + virtual + override(ERC721, AccessControl) + returns (bool) + { + return super.supportsInterface(interfaceId); + } +} + diff --git a/test/foundry/Base.t.sol b/test/foundry/Base.t.sol index 5d06f3ca..108ec397 100644 --- a/test/foundry/Base.t.sol +++ b/test/foundry/Base.t.sol @@ -189,4 +189,9 @@ abstract contract Base_Test is Test, Defaults { } return baseAmount; // 18 decimals (cUSD) } + + /// @dev Helper to create an array filled with address(0) + function _createZeroAddressArray(uint256 length) internal pure returns (address[] memory) { + return new address[](length); + } } \ No newline at end of file diff --git a/test/foundry/integration/AllOrNothing/AllOrNothing.t.sol b/test/foundry/integration/AllOrNothing/AllOrNothing.t.sol index 5e9e9964..e5fc1907 100644 --- a/test/foundry/integration/AllOrNothing/AllOrNothing.t.sol +++ b/test/foundry/integration/AllOrNothing/AllOrNothing.t.sol @@ -96,7 +96,11 @@ abstract contract AllOrNothing_Integration_Shared_Test is selectedPlatformHash, platformDataKey, platformDataValue, - CAMPAIGN_DATA + CAMPAIGN_DATA, + "Campaign Pledge NFT", + "PLEDGE", + "ipfs://QmExampleImageURI", + "ipfs://QmExampleContractURI" ); Vm.Log[] memory entries = vm.getRecordedLogs(); @@ -121,7 +125,7 @@ abstract contract AllOrNothing_Integration_Shared_Test is vm.recordLogs(); // Deploy the treasury contract - treasuryFactory.deploy(platformHash, campaignAddress, 0, NAME, SYMBOL); + treasuryFactory.deploy(platformHash, campaignAddress, 0); Vm.Log[] memory entries = vm.getRecordedLogs(); vm.stopPrank(); @@ -264,6 +268,10 @@ abstract contract AllOrNothing_Integration_Shared_Test is { vm.warp(warpTime); vm.startPrank(caller); + + // Approve treasury to burn NFT + CampaignInfo(campaignAddress).approve(allOrNothingAddress, tokenId); + vm.recordLogs(); AllOrNothing(allOrNothingAddress).claimRefund(tokenId); diff --git a/test/foundry/integration/AllOrNothing/AllOrNothingFunction.t.sol b/test/foundry/integration/AllOrNothing/AllOrNothingFunction.t.sol index 7089b5e4..43f0c5f7 100644 --- a/test/foundry/integration/AllOrNothing/AllOrNothingFunction.t.sol +++ b/test/foundry/integration/AllOrNothing/AllOrNothingFunction.t.sol @@ -74,8 +74,8 @@ contract AllOrNothingFunction_Integration_Shared_Test is uint256 backerBalance = testToken.balanceOf(users.backer1Address); uint256 treasuryBalance = testToken.balanceOf(address(allOrNothing)); - uint256 backerNftBalance = allOrNothing.balanceOf(users.backer1Address); - address nftOwnerAddress = allOrNothing.ownerOf(pledgeForARewardTokenId); + uint256 backerNftBalance = CampaignInfo(campaignAddress).balanceOf(users.backer1Address); + address nftOwnerAddress = CampaignInfo(campaignAddress).ownerOf(tokenId); assertEq(users.backer1Address, nftOwnerAddress); assertEq(PLEDGE_AMOUNT + SHIPPING_FEE, treasuryBalance); @@ -459,7 +459,7 @@ contract AllOrNothingFunction_Integration_Shared_Test is address(usdcToken), usdcAmount ); - uint256 usdcTokenId = 0; + uint256 usdcTokenId = 1; // First pledge vm.stopPrank(); // Backer2 pledges with cUSD @@ -470,7 +470,7 @@ contract AllOrNothingFunction_Integration_Shared_Test is address(cUSDToken), PLEDGE_AMOUNT ); - uint256 cUSDTokenId = 1; + uint256 cUSDTokenId = 2; // Second pledge vm.stopPrank(); uint256 backer1USDCBefore = usdcToken.balanceOf(users.backer1Address); @@ -479,9 +479,16 @@ contract AllOrNothingFunction_Integration_Shared_Test is // Claim refunds vm.warp(LAUNCH_TIME + 1 days); + // Approve treasury to burn NFTs + vm.prank(users.backer1Address); + CampaignInfo(campaignAddress).approve(address(allOrNothing), usdcTokenId); + vm.prank(users.backer1Address); allOrNothing.claimRefund(usdcTokenId); + vm.prank(users.backer2Address); + CampaignInfo(campaignAddress).approve(address(allOrNothing), cUSDTokenId); + vm.prank(users.backer2Address); allOrNothing.claimRefund(cUSDTokenId); diff --git a/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaised.t.sol b/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaised.t.sol index 33b7a37d..32cdf74c 100644 --- a/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaised.t.sol +++ b/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaised.t.sol @@ -118,7 +118,11 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder selectedPlatformHash, platformDataKey, platformDataValue, - CAMPAIGN_DATA + CAMPAIGN_DATA, + "Campaign Pledge NFT", + "PLEDGE", + "ipfs://QmExampleImageURI", + "ipfs://QmExampleContractURI" ); Vm.Log[] memory entries = vm.getRecordedLogs(); @@ -141,7 +145,7 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder vm.recordLogs(); // Deploy the treasury contract - treasuryFactory.deploy(platformHash, campaignAddress, 1, NAME, SYMBOL); + treasuryFactory.deploy(platformHash, campaignAddress, 1); Vm.Log[] memory entries = vm.getRecordedLogs(); vm.stopPrank(); @@ -389,6 +393,10 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder returns (Vm.Log[] memory logs, uint256 refundedTokenId, uint256 refundAmount, address claimer) { vm.startPrank(caller); + + // Approve treasury to burn NFT + CampaignInfo(campaignAddress).approve(keepWhatsRaisedAddress, tokenId); + vm.recordLogs(); KeepWhatsRaised(keepWhatsRaisedAddress).claimRefund(tokenId); diff --git a/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaisedFunction.t.sol b/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaisedFunction.t.sol index cd7fe0c6..81cd5dd2 100644 --- a/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaisedFunction.t.sol +++ b/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaisedFunction.t.sol @@ -78,8 +78,8 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte uint256 backerBalance = testToken.balanceOf(users.backer1Address); uint256 treasuryBalance = testToken.balanceOf(address(keepWhatsRaised)); - uint256 backerNftBalance = keepWhatsRaised.balanceOf(users.backer1Address); - address nftOwnerAddress = keepWhatsRaised.ownerOf(tokenId); + uint256 backerNftBalance = CampaignInfo(campaignAddress).balanceOf(users.backer1Address); + address nftOwnerAddress = CampaignInfo(campaignAddress).ownerOf(tokenId); assertEq(users.backer1Address, nftOwnerAddress); assertEq(PLEDGE_AMOUNT + TIP_AMOUNT, treasuryBalance); @@ -101,8 +101,8 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte ); uint256 treasuryBalance = testToken.balanceOf(address(keepWhatsRaised)); - uint256 backerNftBalance = keepWhatsRaised.balanceOf(users.backer1Address); - address nftOwnerAddress = keepWhatsRaised.ownerOf(tokenId); + uint256 backerNftBalance = CampaignInfo(campaignAddress).balanceOf(users.backer1Address); + address nftOwnerAddress = CampaignInfo(campaignAddress).ownerOf(tokenId); assertEq(users.backer1Address, nftOwnerAddress); assertEq(PLEDGE_AMOUNT + TIP_AMOUNT, treasuryBalance); @@ -137,7 +137,7 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte assertEq(keepWhatsRaised.getPaymentGatewayFee(TEST_PLEDGE_ID_1), PAYMENT_GATEWAY_FEE); // Verify pledge was made - tokens come from admin not backer - address nftOwnerAddress = keepWhatsRaised.ownerOf(tokenId); + address nftOwnerAddress = CampaignInfo(campaignAddress).ownerOf(tokenId); assertEq(users.backer1Address, nftOwnerAddress); } @@ -162,7 +162,7 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte assertEq(keepWhatsRaised.getPaymentGatewayFee(TEST_PLEDGE_ID_1), PAYMENT_GATEWAY_FEE); // Verify pledge was made - tokens come from admin not backer - address nftOwnerAddress = keepWhatsRaised.ownerOf(tokenId); + address nftOwnerAddress = CampaignInfo(campaignAddress).ownerOf(tokenId); assertEq(users.backer1Address, nftOwnerAddress); } diff --git a/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol b/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol index 55636f00..0316699d 100644 --- a/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol +++ b/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol @@ -97,7 +97,11 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te selectedPlatformHash, platformDataKey, platformDataValue, - CAMPAIGN_DATA + CAMPAIGN_DATA, + "Campaign Pledge NFT", + "PLEDGE", + "ipfs://QmExampleImageURI", + "ipfs://QmExampleContractURI" ); Vm.Log[] memory entries = vm.getRecordedLogs(); @@ -120,7 +124,7 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te vm.recordLogs(); // Deploy the treasury contract with implementation ID 2 for PaymentTreasury - treasuryFactory.deploy(platformHash, campaignAddress, 2, NAME, SYMBOL); + treasuryFactory.deploy(platformHash, campaignAddress, 2); Vm.Log[] memory entries = vm.getRecordedLogs(); vm.stopPrank(); @@ -179,7 +183,7 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te */ function confirmPayment(address caller, bytes32 paymentId) internal { vm.prank(caller); - paymentTreasury.confirmPayment(paymentId); + paymentTreasury.confirmPayment(paymentId, address(0)); } /** @@ -187,7 +191,7 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te */ function confirmPaymentBatch(address caller, bytes32[] memory paymentIds) internal { vm.prank(caller); - paymentTreasury.confirmPaymentBatch(paymentIds); + paymentTreasury.confirmPaymentBatch(paymentIds, _createZeroAddressArray(paymentIds.length)); } /** @@ -216,11 +220,15 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te /** * @notice Claims a refund (buyer-initiated) */ - function claimRefund(address caller, bytes32 paymentId) + function claimRefund(address caller, bytes32 paymentId, uint256 tokenId) internal returns (uint256 refundAmount) { vm.startPrank(caller); + + // Approve treasury to burn NFT + CampaignInfo(campaignAddress).approve(treasuryAddress, tokenId); + vm.recordLogs(); paymentTreasury.claimRefund(paymentId); diff --git a/test/foundry/integration/PaymentTreasury/PaymentTreasuryBatchLimitTest.t.sol b/test/foundry/integration/PaymentTreasury/PaymentTreasuryBatchLimitTest.t.sol index 7e90e55b..6bcf873d 100644 --- a/test/foundry/integration/PaymentTreasury/PaymentTreasuryBatchLimitTest.t.sol +++ b/test/foundry/integration/PaymentTreasury/PaymentTreasuryBatchLimitTest.t.sol @@ -67,7 +67,7 @@ contract PaymentTreasuryBatchLimit_Test is PaymentTreasury_Integration_Shared_Te vm.prank(users.platform1AdminAddress); uint256 gasStart = gasleft(); - try paymentTreasury.confirmPaymentBatch(paymentIds) { + try paymentTreasury.confirmPaymentBatch(paymentIds, _createZeroAddressArray(paymentIds.length)) { uint256 gasUsed = gasStart - gasleft(); uint256 percentOfBlock = (gasUsed * 100) / CELO_BLOCK_GAS_LIMIT; diff --git a/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol b/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol index 7944559e..95612cff 100644 --- a/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol +++ b/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol @@ -126,7 +126,7 @@ contract PaymentTreasuryFunction_Integration_Test is _createAndProcessCryptoPayment(PAYMENT_ID_1, ITEM_ID_1, amount, users.backer1Address); uint256 buyerBalanceBefore = testToken.balanceOf(users.backer1Address); - uint256 refundAmount = claimRefund(users.backer1Address, PAYMENT_ID_1); + uint256 refundAmount = claimRefund(users.backer1Address, PAYMENT_ID_1, 1); // tokenId 1 assertEq(refundAmount, amount, "Refund amount should match payment"); assertEq( @@ -436,8 +436,8 @@ contract PaymentTreasuryFunction_Integration_Test is uint256 backer2CUSDBefore = cUSDToken.balanceOf(users.backer2Address); // Buyers claim their own refunds - uint256 refund1 = claimRefund(users.backer1Address, PAYMENT_ID_1); - uint256 refund2 = claimRefund(users.backer2Address, PAYMENT_ID_2); + uint256 refund1 = claimRefund(users.backer1Address, PAYMENT_ID_1, 1); // tokenId 1 + uint256 refund2 = claimRefund(users.backer2Address, PAYMENT_ID_2, 2); // tokenId 2 assertEq(refund1, usdcAmount, "Should refund USDC amount"); assertEq(refund2, cUSDAmount, "Should refund cUSD amount"); @@ -712,4 +712,146 @@ contract PaymentTreasuryFunction_Integration_Test is "cUSD should be unchanged" ); } + + /** + * @notice Tests that cancelled treasuries are excluded from getTotalRaisedAmount. + */ + function test_getTotalRaisedAmountExcludesCancelledTreasuries() public { + // Setup: Create a campaign with 2 platforms + bytes32 identifierHash = keccak256(abi.encodePacked("multi-platform-campaign")); + bytes32[] memory selectedPlatforms = new bytes32[](2); + selectedPlatforms[0] = PLATFORM_1_HASH; + selectedPlatforms[1] = PLATFORM_2_HASH; + + // Enlist second platform + vm.startPrank(users.protocolAdminAddress); + globalParams.enlistPlatform(PLATFORM_2_HASH, users.platform2AdminAddress, PLATFORM_FEE_PERCENT); + vm.stopPrank(); + + // Register and approve treasury for platform 2 + PaymentTreasury platform2Implementation = new PaymentTreasury(); + vm.startPrank(users.platform2AdminAddress); + treasuryFactory.registerTreasuryImplementation(PLATFORM_2_HASH, 2, address(platform2Implementation)); + vm.stopPrank(); + + vm.startPrank(users.protocolAdminAddress); + treasuryFactory.approveTreasuryImplementation(PLATFORM_2_HASH, 2); + vm.stopPrank(); + + bytes32[] memory platformDataKey = new bytes32[](0); + bytes32[] memory platformDataValue = new bytes32[](0); + + // Create multi-platform campaign + vm.startPrank(users.creator1Address); + vm.recordLogs(); + campaignInfoFactory.createCampaign( + users.creator1Address, + identifierHash, + selectedPlatforms, + platformDataKey, + platformDataValue, + CAMPAIGN_DATA, + "Campaign Pledge NFT", + "PLEDGE", + "ipfs://QmExampleImageURI", + "ipfs://QmExampleContractURI" + ); + Vm.Log[] memory entries = vm.getRecordedLogs(); + vm.stopPrank(); + + (bytes32[] memory topics,) = decodeTopicsAndData( + entries, "CampaignInfoFactoryCampaignCreated(bytes32,address)", address(campaignInfoFactory) + ); + address multiPlatformCampaign = address(uint160(uint256(topics[2]))); + CampaignInfo campaignInfo = CampaignInfo(multiPlatformCampaign); + + // Deploy treasury for platform 1 + vm.startPrank(users.platform1AdminAddress); + vm.recordLogs(); + treasuryFactory.deploy(PLATFORM_1_HASH, multiPlatformCampaign, 2); + Vm.Log[] memory entries1 = vm.getRecordedLogs(); + vm.stopPrank(); + + (bytes32[] memory topics1, bytes memory data1) = decodeTopicsAndData( + entries1, "TreasuryFactoryTreasuryDeployed(bytes32,uint256,address,address)", address(treasuryFactory) + ); + address treasury1 = abi.decode(data1, (address)); + + // Deploy treasury for platform 2 + vm.startPrank(users.platform2AdminAddress); + vm.recordLogs(); + treasuryFactory.deploy(PLATFORM_2_HASH, multiPlatformCampaign, 2); + Vm.Log[] memory entries2 = vm.getRecordedLogs(); + vm.stopPrank(); + + (bytes32[] memory topics2, bytes memory data2) = decodeTopicsAndData( + entries2, "TreasuryFactoryTreasuryDeployed(bytes32,uint256,address,address)", address(treasuryFactory) + ); + address treasury2 = abi.decode(data2, (address)); + + PaymentTreasury paymentTreasury1 = PaymentTreasury(treasury1); + PaymentTreasury paymentTreasury2 = PaymentTreasury(treasury2); + + // Add payments to both treasuries + uint256 amount1 = 1000e18; + uint256 amount2 = 2000e18; + + // Treasury 1: Create, fund, and confirm payment + vm.prank(users.platform1AdminAddress); + paymentTreasury1.createPayment( + keccak256("payment-p1"), + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + amount1, + block.timestamp + PAYMENT_EXPIRATION + ); + + // Fund backer and transfer to treasury + deal(address(testToken), users.backer1Address, amount1); + vm.prank(users.backer1Address); + testToken.transfer(treasury1, amount1); + + vm.prank(users.platform1AdminAddress); + paymentTreasury1.confirmPayment(keccak256("payment-p1"), address(0)); + + // Treasury 2: Create, fund, and confirm payment + vm.prank(users.platform2AdminAddress); + paymentTreasury2.createPayment( + keccak256("payment-p2"), + BUYER_ID_2, + ITEM_ID_2, + address(testToken), + amount2, + block.timestamp + PAYMENT_EXPIRATION + ); + + // Fund backer and transfer to treasury + deal(address(testToken), users.backer2Address, amount2); + vm.prank(users.backer2Address); + testToken.transfer(treasury2, amount2); + + vm.prank(users.platform2AdminAddress); + paymentTreasury2.confirmPayment(keccak256("payment-p2"), address(0)); + + // Verify both treasuries have raised amounts + assertEq(paymentTreasury1.getRaisedAmount(), amount1, "Treasury 1 should have raised amount"); + assertEq(paymentTreasury2.getRaisedAmount(), amount2, "Treasury 2 should have raised amount"); + + // Verify total includes both treasuries + uint256 totalBefore = campaignInfo.getTotalRaisedAmount(); + assertEq(totalBefore, amount1 + amount2, "Total should include both treasuries"); + + // Cancel treasury 1 + vm.prank(users.platform1AdminAddress); + paymentTreasury1.cancelTreasury(keccak256("test-cancellation")); + + // Verify treasury 1 is cancelled + assertTrue(paymentTreasury1.cancelled(), "Treasury 1 should be cancelled"); + assertFalse(paymentTreasury2.cancelled(), "Treasury 2 should not be cancelled"); + + // Verify total now excludes cancelled treasury + uint256 totalAfter = campaignInfo.getTotalRaisedAmount(); + assertEq(totalAfter, amount2, "Total should only include non-cancelled treasury"); + } } \ No newline at end of file diff --git a/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasury.t.sol b/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasury.t.sol index bc45221b..c2bde023 100644 --- a/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasury.t.sol +++ b/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasury.t.sol @@ -115,7 +115,11 @@ abstract contract TimeConstrainedPaymentTreasury_Integration_Shared_Test is LogD selectedPlatformHash, platformDataKey, platformDataValue, - CAMPAIGN_DATA + CAMPAIGN_DATA, + "Campaign Pledge NFT", + "PLEDGE", + "ipfs://QmExampleImageURI", + "ipfs://QmExampleContractURI" ); campaignAddress = campaignInfoFactory.identifierToCampaignInfo(identifierHash); @@ -141,9 +145,7 @@ abstract contract TimeConstrainedPaymentTreasury_Integration_Shared_Test is LogD treasuryAddress = treasuryFactory.deploy( platformHash, campaignAddress, - 3, // TimeConstrainedPaymentTreasury type - "TimeConstrainedPaymentTreasury", - "TCPT" + 3 // TimeConstrainedPaymentTreasury type ); timeConstrainedPaymentTreasury = TimeConstrainedPaymentTreasury(treasuryAddress); diff --git a/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasuryFunction.t.sol b/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasuryFunction.t.sol index 22d28a09..3047b0d8 100644 --- a/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasuryFunction.t.sol +++ b/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasuryFunction.t.sol @@ -211,6 +211,10 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC // Advance to after launch to be able to claim refund advanceToAfterLaunch(); + // Approve treasury to burn NFT + vm.prank(users.backer1Address); + CampaignInfo(campaignAddress).approve(address(timeConstrainedPaymentTreasury), 1); // tokenId 1 + // Then claim refund (use the overload without refundAddress since processCryptoPayment uses buyerAddress) vm.prank(users.backer1Address); timeConstrainedPaymentTreasury.claimRefund(uniquePaymentId); diff --git a/test/foundry/unit/CampaignInfo.t.sol b/test/foundry/unit/CampaignInfo.t.sol index e5872a78..c954a509 100644 --- a/test/foundry/unit/CampaignInfo.t.sol +++ b/test/foundry/unit/CampaignInfo.t.sol @@ -123,7 +123,11 @@ contract CampaignInfo_UnitTest is Test, Defaults { selectedPlatformHashes, platformDataKeys, platformDataValues, - campaignData + campaignData, + "Test Campaign NFT", + "TCNFT", + "ipfs://QmTest123", + "ipfs://QmContractTest123" ); vm.stopPrank(); @@ -643,9 +647,7 @@ contract CampaignInfo_UnitTest is Test, Defaults { address treasury = treasuryFactory.deploy( platformHash1, address(campaignInfo), - 1, // implementationId - "Test Treasury", - "TT" + 1 // implementationId ); vm.stopPrank(); @@ -711,9 +713,7 @@ contract CampaignInfo_UnitTest is Test, Defaults { treasuryFactory.deploy( platformHash1, address(campaignInfo), - 1, // implementationId - "Test Treasury", - "TT" + 1 // implementationId ); vm.stopPrank(); @@ -876,9 +876,7 @@ contract CampaignInfo_UnitTest is Test, Defaults { treasuryFactory.deploy( platformHash1, address(campaignInfo), - 1, // implementationId - "Test Treasury", - "TT" + 1 // implementationId ); vm.stopPrank(); @@ -954,9 +952,7 @@ contract CampaignInfo_UnitTest is Test, Defaults { treasuryFactory.deploy( platformHash1, address(campaignInfo), - 1, // implementationId - "Test Treasury", - "TT" + 1 // implementationId ); vm.stopPrank(); } diff --git a/test/foundry/unit/CampaignInfoFactory.t.sol b/test/foundry/unit/CampaignInfoFactory.t.sol index fde49b8b..1df4063e 100644 --- a/test/foundry/unit/CampaignInfoFactory.t.sol +++ b/test/foundry/unit/CampaignInfoFactory.t.sol @@ -115,7 +115,11 @@ contract CampaignInfoFactory_UnitTest is Test, Defaults { platforms, keys, values, - CAMPAIGN_DATA + CAMPAIGN_DATA, + "Campaign Pledge NFT", + "PLEDGE", + "ipfs://QmExampleImageURI", + "ipfs://QmExampleContractURI" ); Vm.Log[] memory logs = vm.getRecordedLogs(); @@ -179,7 +183,11 @@ contract CampaignInfoFactory_UnitTest is Test, Defaults { platforms, keys, values, - CAMPAIGN_DATA + CAMPAIGN_DATA, + "Campaign Pledge NFT", + "PLEDGE", + "ipfs://QmExampleImageURI", + "ipfs://QmExampleContractURI" ); } @@ -229,7 +237,11 @@ contract CampaignInfoFactory_UnitTest is Test, Defaults { platforms, keys, values, - campaignData + campaignData, + "Campaign Pledge NFT", + "PLEDGE", + "ipfs://QmExampleImageURI", + "ipfs://QmExampleContractURI" ); } @@ -258,7 +270,11 @@ contract CampaignInfoFactory_UnitTest is Test, Defaults { platforms, keys, values, - campaignData + campaignData, + "Campaign Pledge NFT", + "PLEDGE", + "ipfs://QmExampleImageURI", + "ipfs://QmExampleContractURI" ); } } diff --git a/test/foundry/unit/KeepWhatsRaised.t.sol b/test/foundry/unit/KeepWhatsRaised.t.sol index 3147ad3f..c8dc940c 100644 --- a/test/foundry/unit/KeepWhatsRaised.t.sol +++ b/test/foundry/unit/KeepWhatsRaised.t.sol @@ -57,7 +57,11 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te selectedPlatformHash, platformDataKey, // Empty array platformDataValue, // Empty array - CAMPAIGN_DATA + CAMPAIGN_DATA, + "Campaign Pledge NFT", + "PLEDGE", + "ipfs://QmExampleImageURI", + "ipfs://QmExampleContractURI" ); address newCampaignAddress = campaignInfoFactory.identifierToCampaignInfo(newIdentifierHash); @@ -67,15 +71,15 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te address newTreasury = treasuryFactory.deploy( PLATFORM_2_HASH, newCampaignAddress, - 1, - "NewCampaign", - "NC" + 1 ); KeepWhatsRaised newContract = KeepWhatsRaised(newTreasury); + CampaignInfo newCampaignInfo = CampaignInfo(newCampaignAddress); - assertEq(newContract.name(), "NewCampaign"); - assertEq(newContract.symbol(), "NC"); + // NFT name and symbol are now on CampaignInfo, not treasury + assertEq(newCampaignInfo.name(), "Campaign Pledge NFT"); + assertEq(newCampaignInfo.symbol(), "PLEDGE"); } /*////////////////////////////////////////////////////////////// @@ -458,7 +462,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te assertEq(testToken.balanceOf(users.backer1Address), balanceBefore - TEST_PLEDGE_AMOUNT - TEST_TIP_AMOUNT); assertEq(keepWhatsRaised.getRaisedAmount(), TEST_PLEDGE_AMOUNT); assertTrue(keepWhatsRaised.getAvailableRaisedAmount() < TEST_PLEDGE_AMOUNT); // Less due to fees - assertEq(keepWhatsRaised.balanceOf(users.backer1Address), 1); + assertEq(CampaignInfo(campaignAddress).balanceOf(users.backer1Address), 1); } function testPledgeForARewardRevertWhenDuplicatePledgeId() public { @@ -523,7 +527,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te assertEq(testToken.balanceOf(users.backer1Address), balanceBefore - pledgeAmount - TEST_TIP_AMOUNT); assertEq(keepWhatsRaised.getRaisedAmount(), pledgeAmount); assertTrue(keepWhatsRaised.getAvailableRaisedAmount() < pledgeAmount); // Less due to fees - assertEq(keepWhatsRaised.balanceOf(users.backer1Address), 1); + assertEq(CampaignInfo(campaignAddress).balanceOf(users.backer1Address), 1); } function testPledgeWithoutARewardRevertWhenDuplicatePledgeId() public { @@ -607,7 +611,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te // Verify pledge was made assertEq(keepWhatsRaised.getRaisedAmount(), TEST_PLEDGE_AMOUNT); - assertEq(keepWhatsRaised.balanceOf(users.backer1Address), 1); + assertEq(CampaignInfo(campaignAddress).balanceOf(users.backer1Address), 1); } /*////////////////////////////////////////////////////////////// @@ -809,13 +813,18 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); - uint256 tokenId = 0; + uint256 tokenId = 1; // First token ID after pledge vm.stopPrank(); uint256 balanceBefore = testToken.balanceOf(users.backer1Address); // Claim refund within refund window vm.warp(DEADLINE + 1 days); + + // Approve treasury to burn NFT + vm.prank(users.backer1Address); + CampaignInfo(campaignAddress).approve(address(keepWhatsRaised), tokenId); + vm.prank(users.backer1Address); keepWhatsRaised.claimRefund(tokenId); @@ -828,7 +837,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te // Verify refund amount is pledge minus fees assertEq(testToken.balanceOf(users.backer1Address), balanceBefore + expectedRefund); vm.expectRevert(); - keepWhatsRaised.ownerOf(tokenId); // Token should be burned + campaignInfo.ownerOf(tokenId); // Token should be burned } function testClaimRefundRevertWhenOutsideRefundWindow() public { @@ -839,7 +848,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); - uint256 tokenId = 0; + uint256 tokenId = 1; // First token ID after pledge vm.stopPrank(); // Try to claim after refund window @@ -857,7 +866,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); - uint256 tokenId = 0; + uint256 tokenId = 1; // First token ID after pledge vm.stopPrank(); // Cancel campaign @@ -868,6 +877,11 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te // Claim refund vm.warp(block.timestamp + 1); + + // Approve treasury to burn NFT + vm.prank(users.backer1Address); + CampaignInfo(campaignAddress).approve(address(keepWhatsRaised), tokenId); + vm.prank(users.backer1Address); keepWhatsRaised.claimRefund(tokenId); @@ -1607,7 +1621,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.startPrank(users.backer1Address); usdcToken.approve(address(keepWhatsRaised), usdcAmount); keepWhatsRaised.pledgeWithoutAReward(keccak256("usdc_pledge"), users.backer1Address, address(usdcToken), usdcAmount, 0); - uint256 usdcTokenId = 0; + uint256 usdcTokenId = 1; // First pledge vm.stopPrank(); // Backer2 pledges with cUSD @@ -1616,7 +1630,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.startPrank(users.backer2Address); cUSDToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); keepWhatsRaised.pledgeWithoutAReward(keccak256("cusd_pledge"), users.backer2Address, address(cUSDToken), TEST_PLEDGE_AMOUNT, 0); - uint256 cUSDTokenId = 1; + uint256 cUSDTokenId = 2; // Second pledge vm.stopPrank(); uint256 backer1USDCBefore = usdcToken.balanceOf(users.backer1Address); @@ -1625,9 +1639,16 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te // Claim refunds after deadline vm.warp(DEADLINE + 1); + // Approve treasury to burn NFTs + vm.prank(users.backer1Address); + CampaignInfo(campaignAddress).approve(address(keepWhatsRaised), usdcTokenId); + vm.prank(users.backer1Address); keepWhatsRaised.claimRefund(usdcTokenId); + vm.prank(users.backer2Address); + CampaignInfo(campaignAddress).approve(address(keepWhatsRaised), cUSDTokenId); + vm.prank(users.backer2Address); keepWhatsRaised.claimRefund(cUSDTokenId); diff --git a/test/foundry/unit/PaymentTreasury.t.sol b/test/foundry/unit/PaymentTreasury.t.sol index 42ec0db5..ebb135ab 100644 --- a/test/foundry/unit/PaymentTreasury.t.sol +++ b/test/foundry/unit/PaymentTreasury.t.sol @@ -52,7 +52,11 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te selectedPlatformHash, platformDataKey, platformDataValue, - CAMPAIGN_DATA + CAMPAIGN_DATA, + "Campaign Pledge NFT", + "PLEDGE", + "ipfs://QmExampleImageURI", + "ipfs://QmExampleContractURI" ); address newCampaignAddress = campaignInfoFactory.identifierToCampaignInfo(newIdentifierHash); @@ -61,14 +65,14 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te address newTreasury = treasuryFactory.deploy( PLATFORM_1_HASH, newCampaignAddress, - 2, - "NewPaymentTreasury", - "NPT" + 2 ); PaymentTreasury newContract = PaymentTreasury(newTreasury); + CampaignInfo newCampaignInfo = CampaignInfo(newCampaignAddress); - assertEq(newContract.name(), "NewPaymentTreasury"); - assertEq(newContract.symbol(), "NPT"); + // NFT name and symbol are now on CampaignInfo, not treasury + assertEq(newCampaignInfo.name(), "Campaign Pledge NFT"); + assertEq(newCampaignInfo.symbol(), "PLEDGE"); assertEq(newContract.getplatformHash(), PLATFORM_1_HASH); assertEq(newContract.getplatformFeePercent(), PLATFORM_FEE_PERCENT); } @@ -341,7 +345,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testCancelPaymentRevertWhenAlreadyConfirmed() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter vm.expectRevert(); vm.prank(users.platform1AdminAddress); @@ -383,7 +387,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testConfirmPayment() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter assertEq(paymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1); assertEq(paymentTreasury.getAvailableRaisedAmount(), PAYMENT_AMOUNT_1); @@ -400,7 +404,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te paymentIds[2] = PAYMENT_ID_3; vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPaymentBatch(paymentIds); // Removed token array + paymentTreasury.confirmPaymentBatch(paymentIds, _createZeroAddressArray(paymentIds.length)); // Removed token array uint256 totalAmount = PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2 + 500e18; assertEq(paymentTreasury.getRaisedAmount(), totalAmount); @@ -410,16 +414,16 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testConfirmPaymentRevertWhenNotExists() public { vm.expectRevert(); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter } function testConfirmPaymentRevertWhenAlreadyConfirmed() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.startPrank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter vm.expectRevert(); - paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter vm.stopPrank(); } @@ -429,7 +433,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.expectRevert(); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter } /*////////////////////////////////////////////////////////////// @@ -439,7 +443,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testClaimRefund() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter uint256 balanceBefore = testToken.balanceOf(users.backer1Address); @@ -459,6 +463,10 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te uint256 balanceBefore = testToken.balanceOf(users.backer1Address); + // Approve treasury to burn NFT + vm.prank(users.backer1Address); + CampaignInfo(campaignAddress).approve(address(paymentTreasury), 1); + vm.prank(users.backer1Address); paymentTreasury.claimRefund(PAYMENT_ID_1); @@ -475,6 +483,10 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te uint256 balanceBefore = testToken.balanceOf(users.backer1Address); + // Approve treasury to burn NFT + vm.prank(users.backer1Address); + CampaignInfo(campaignAddress).approve(address(paymentTreasury), 1); + vm.prank(users.platform1AdminAddress); paymentTreasury.claimRefund(PAYMENT_ID_1); @@ -509,7 +521,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testClaimRefundRevertWhenPaused() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter // Pause treasury vm.prank(users.platform1AdminAddress); @@ -536,7 +548,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testDisburseFees() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter // Withdraw first to calculate fees paymentTreasury.withdraw(); @@ -557,14 +569,14 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te _createAndFundPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, PAYMENT_AMOUNT_2, users.backer2Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter // First withdrawal and disbursement paymentTreasury.withdraw(); paymentTreasury.disburseFees(); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_2); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_2, address(0)); // Removed token parameter // Second withdrawal and disbursement paymentTreasury.withdraw(); @@ -574,7 +586,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testDisburseFeesRevertWhenPaused() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter paymentTreasury.withdraw(); @@ -593,7 +605,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testWithdraw() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter address owner = CampaignInfo(campaignAddress).owner(); uint256 ownerBalanceBefore = testToken.balanceOf(owner); @@ -613,7 +625,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testWithdrawRevertWhenAlreadyWithdrawn() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter paymentTreasury.withdraw(); paymentTreasury.disburseFees(); @@ -625,7 +637,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testWithdrawRevertWhenPaused() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter // Pause treasury vm.prank(users.platform1AdminAddress); @@ -643,7 +655,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te // First create and confirm a payment to test functions that require it _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter // Pause the treasury vm.prank(users.platform1AdminAddress); @@ -695,7 +707,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testCancelTreasuryByPlatformAdmin() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter vm.prank(users.platform1AdminAddress); paymentTreasury.cancelTreasury(keccak256("Cancel")); @@ -719,7 +731,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testCancelTreasuryByCampaignOwner() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter address owner = CampaignInfo(campaignAddress).owner(); vm.prank(owner); @@ -764,7 +776,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te paymentIds[2] = PAYMENT_ID_3; vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPaymentBatch(paymentIds); // Removed token array + paymentTreasury.confirmPaymentBatch(paymentIds, _createZeroAddressArray(paymentIds.length)); // Removed token array uint256 totalAmount = PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2 + 500e18; assertEq(paymentTreasury.getRaisedAmount(), totalAmount); @@ -787,8 +799,8 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te _createAndFundPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, PAYMENT_AMOUNT_2, users.backer2Address); vm.startPrank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter - paymentTreasury.confirmPayment(PAYMENT_ID_2); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_2, address(0)); // Removed token parameter // Refund all payments paymentTreasury.claimRefund(PAYMENT_ID_1, users.backer1Address); @@ -835,7 +847,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te testToken.transfer(treasuryAddress, PAYMENT_AMOUNT_2); // Confirm first payment before expiration vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter // Warp past first expiration but before second vm.warp(shortExpiration + 1); // Cannot cancel or confirm expired payment @@ -844,7 +856,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te paymentTreasury.cancelPayment(PAYMENT_ID_1); // Can still confirm non-expired payment vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_2); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_2, address(0)); // Removed token parameter assertEq(paymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2); } @@ -856,7 +868,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te // Confirm regular payment vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter // Both should contribute to raised amount uint256 totalAmount = PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2; @@ -886,7 +898,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te // Try to confirm without any tokens - should revert vm.expectRevert(); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Send the tokens deal(address(testToken), users.backer1Address, 1000e18); @@ -895,7 +907,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te // Now confirmation works vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); assertEq(paymentTreasury.getRaisedAmount(), 1000e18); } @@ -915,12 +927,12 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te // Can confirm one payment vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter // Cannot confirm second payment - total would exceed balance vm.expectRevert(); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_2); // Removed token parameter + paymentTreasury.confirmPayment(PAYMENT_ID_2, address(0)); // Removed token parameter assertEq(paymentTreasury.getRaisedAmount(), 500e18); } @@ -945,7 +957,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.expectRevert(); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPaymentBatch(paymentIds); // Removed token array + paymentTreasury.confirmPaymentBatch(paymentIds, _createZeroAddressArray(paymentIds.length)); // Removed token array } /*////////////////////////////////////////////////////////////// @@ -979,8 +991,8 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te // Confirm without specifying token vm.startPrank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); - paymentTreasury.confirmPayment(PAYMENT_ID_2); + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); + paymentTreasury.confirmPayment(PAYMENT_ID_2, address(0)); vm.stopPrank(); uint256 expectedTotal = 500e18 + 700e18; @@ -1040,7 +1052,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te paymentIds[2] = PAYMENT_ID_3; vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPaymentBatch(paymentIds); + paymentTreasury.confirmPaymentBatch(paymentIds, _createZeroAddressArray(paymentIds.length)); uint256 expectedTotal = 500e18 + 600e18 + 700e18; assertEq(paymentTreasury.getRaisedAmount(), expectedTotal); @@ -1059,7 +1071,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te ); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); uint256 usdtBefore = usdtToken.balanceOf(users.backer1Address); uint256 cUSDBefore = cUSDToken.balanceOf(users.backer1Address); @@ -1103,8 +1115,8 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te ); vm.startPrank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); - paymentTreasury.confirmPayment(PAYMENT_ID_2); + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); + paymentTreasury.confirmPayment(PAYMENT_ID_2, address(0)); vm.stopPrank(); address owner = CampaignInfo(campaignAddress).owner(); @@ -1141,8 +1153,8 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te ); vm.startPrank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); - paymentTreasury.confirmPayment(PAYMENT_ID_2); + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); + paymentTreasury.confirmPayment(PAYMENT_ID_2, address(0)); vm.stopPrank(); paymentTreasury.withdraw(); @@ -1189,7 +1201,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te ); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); uint256 raisedAfterUSDT = paymentTreasury.getRaisedAmount(); assertEq(raisedAfterUSDT, baseAmount, "1000 USDT should equal 1000e18 normalized"); @@ -1204,7 +1216,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te ); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_2); + paymentTreasury.confirmPayment(PAYMENT_ID_2, address(0)); uint256 totalRaised = paymentTreasury.getRaisedAmount(); assertEq(totalRaised, baseAmount * 2, "Both should contribute equally"); @@ -1231,12 +1243,12 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te // Can confirm first vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Cannot confirm second - insufficient USDT balance vm.expectRevert(); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_2); + paymentTreasury.confirmPayment(PAYMENT_ID_2, address(0)); } function testMixedTokenRefundsAfterPartialWithdraw() public { @@ -1263,8 +1275,8 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te ); vm.startPrank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); - paymentTreasury.confirmPayment(PAYMENT_ID_2); + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); + paymentTreasury.confirmPayment(PAYMENT_ID_2, address(0)); vm.stopPrank(); // Withdraw (takes fees) @@ -1290,7 +1302,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te ); vm.prank(users.platform1AdminAddress); - paymentTreasury.confirmPayment(PAYMENT_ID_1); + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Withdraw should handle zero-balance tokens (USDC, cUSD) gracefully paymentTreasury.withdraw(); diff --git a/test/foundry/unit/PledgeNFT.t.sol b/test/foundry/unit/PledgeNFT.t.sol new file mode 100644 index 00000000..45b1eb8c --- /dev/null +++ b/test/foundry/unit/PledgeNFT.t.sol @@ -0,0 +1,165 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.22; + +import "../Base.t.sol"; + +contract PledgeNFT_Test is Base_Test { + CampaignInfo public campaign; + KeepWhatsRaised public treasury; + + bytes32 public constant PLATFORM_HASH = keccak256("PLATFORM_1"); + bytes32 public constant TREASURY_ROLE = keccak256("TREASURY_ROLE"); + + function setUp() public override { + super.setUp(); + + // Enlist platform + vm.prank(users.protocolAdminAddress); + globalParams.enlistPlatform(PLATFORM_HASH, users.platform1AdminAddress, PLATFORM_FEE_PERCENT); + + // Register treasury implementation + vm.startPrank(users.platform1AdminAddress); + treasuryFactory.registerTreasuryImplementation(PLATFORM_HASH, 1, address(keepWhatsRaisedImplementation)); + vm.stopPrank(); + + vm.prank(users.protocolAdminAddress); + treasuryFactory.approveTreasuryImplementation(PLATFORM_HASH, 1); + + // Create a campaign + bytes32 identifierHash = keccak256("TEST_CAMPAIGN"); + bytes32[] memory selectedPlatforms = new bytes32[](1); + selectedPlatforms[0] = PLATFORM_HASH; + bytes32[] memory keys = new bytes32[](0); + bytes32[] memory values = new bytes32[](0); + + vm.prank(users.creator1Address); + campaignInfoFactory.createCampaign( + users.creator1Address, + identifierHash, + selectedPlatforms, + keys, + values, + CAMPAIGN_DATA, + "Test Campaign NFT", + "TCNFT", + "ipfs://QmTestImage", + "ipfs://QmTestContract" + ); + + address campaignAddress = campaignInfoFactory.identifierToCampaignInfo(identifierHash); + campaign = CampaignInfo(campaignAddress); + + // Deploy treasury + vm.prank(users.platform1AdminAddress); + address treasuryAddress = treasuryFactory.deploy( + PLATFORM_HASH, + campaignAddress, + 1 + ); + treasury = KeepWhatsRaised(treasuryAddress); + } + + function test_OnlyTreasuryCanMintNFT() public { + // Try to mint without TREASURY_ROLE - should revert + vm.expectRevert(); + vm.prank(users.backer1Address); + campaign.mintNFTForPledge( + users.backer1Address, + bytes32(0), + address(testToken), + 100e18, + 0, + 0 + ); + } + + function test_TreasuryCanMintNFT() public { + // Treasury has TREASURY_ROLE, should be able to mint + vm.prank(address(treasury)); + uint256 tokenId = campaign.mintNFTForPledge( + users.backer1Address, + bytes32(0), + address(testToken), + 100e18, + 0, + 0 + ); + + // Verify NFT was minted + assertEq(tokenId, 1, "First token ID should be 1"); + assertEq(campaign.balanceOf(users.backer1Address), 1, "Backer should have 1 NFT"); + assertEq(campaign.ownerOf(tokenId), users.backer1Address, "Backer should own the NFT"); + } + + function test_TokenIdIncrementsAndNeverReuses() public { + // Mint first NFT + vm.prank(address(treasury)); + uint256 tokenId1 = campaign.mintNFTForPledge( + users.backer1Address, + bytes32(0), + address(testToken), + 100e18, + 0, + 0 + ); + assertEq(tokenId1, 1, "First token ID should be 1"); + + // Mint second NFT + vm.prank(address(treasury)); + uint256 tokenId2 = campaign.mintNFTForPledge( + users.backer1Address, + bytes32(0), + address(testToken), + 100e18, + 0, + 0 + ); + assertEq(tokenId2, 2, "Second token ID should be 2"); + + // Burn first NFT + vm.prank(users.backer1Address); + campaign.burn(tokenId1); + + // Mint third NFT - should be 3, NOT reusing 1 + vm.prank(address(treasury)); + uint256 tokenId3 = campaign.mintNFTForPledge( + users.backer1Address, + bytes32(0), + address(testToken), + 100e18, + 0, + 0 + ); + assertEq(tokenId3, 3, "Third token ID should be 3, not reusing burned ID 1"); + + // Verify balances + assertEq(campaign.balanceOf(users.backer1Address), 2, "Backer should have 2 NFTs after burn"); + } + + function test_BurnRemovesNFT() public { + // Mint NFT + vm.prank(address(treasury)); + uint256 tokenId = campaign.mintNFTForPledge( + users.backer1Address, + bytes32(0), + address(testToken), + 100e18, + 0, + 0 + ); + + assertEq(campaign.balanceOf(users.backer1Address), 1, "Backer should have 1 NFT"); + + // Burn NFT + vm.prank(users.backer1Address); + campaign.burn(tokenId); + + // Verify NFT was burned + assertEq(campaign.balanceOf(users.backer1Address), 0, "Backer should have 0 NFTs after burn"); + + // Trying to query owner of burned token should revert + vm.expectRevert(); + campaign.ownerOf(tokenId); + } +} + diff --git a/test/foundry/unit/TimeConstrainedPaymentTreasury.t.sol b/test/foundry/unit/TimeConstrainedPaymentTreasury.t.sol index b279dc6e..9f37b562 100644 --- a/test/foundry/unit/TimeConstrainedPaymentTreasury.t.sol +++ b/test/foundry/unit/TimeConstrainedPaymentTreasury.t.sol @@ -53,7 +53,11 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment selectedPlatformHash, platformDataKey, platformDataValue, - CAMPAIGN_DATA + CAMPAIGN_DATA, + "Campaign Pledge NFT", + "PLEDGE", + "ipfs://QmExampleImageURI", + "ipfs://QmExampleContractURI" ); address newCampaignAddress = campaignInfoFactory.identifierToCampaignInfo(newIdentifierHash); @@ -62,14 +66,14 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment address newTreasury = treasuryFactory.deploy( PLATFORM_1_HASH, newCampaignAddress, - 3, // TimeConstrainedPaymentTreasury type - "NewTimeConstrainedPaymentTreasury", - "NTCPT" + 3 // TimeConstrainedPaymentTreasury type ); TimeConstrainedPaymentTreasury newContract = TimeConstrainedPaymentTreasury(newTreasury); + CampaignInfo newCampaignInfo = CampaignInfo(newCampaignAddress); - assertEq(newContract.name(), "NewTimeConstrainedPaymentTreasury"); - assertEq(newContract.symbol(), "NTCPT"); + // NFT name and symbol are now on CampaignInfo, not treasury + assertEq(newCampaignInfo.name(), "Campaign Pledge NFT"); + assertEq(newCampaignInfo.symbol(), "PLEDGE"); assertEq(newContract.getplatformHash(), PLATFORM_1_HASH); assertEq(newContract.getplatformFeePercent(), PLATFORM_FEE_PERCENT); } @@ -290,7 +294,7 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment vm.expectRevert(); vm.prank(users.platform1AdminAddress); - timeConstrainedPaymentTreasury.confirmPayment(PAYMENT_ID_1); + timeConstrainedPaymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); } function testConfirmPaymentBatchWithinTimeRange() public { @@ -333,7 +337,7 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment vm.expectRevert(); vm.prank(users.platform1AdminAddress); - timeConstrainedPaymentTreasury.confirmPaymentBatch(paymentIds); + timeConstrainedPaymentTreasury.confirmPaymentBatch(paymentIds, _createZeroAddressArray(paymentIds.length)); } /*////////////////////////////////////////////////////////////// @@ -360,6 +364,10 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment // Advance to after launch to be able to claim refund advanceToAfterLaunch(); + // Approve treasury to burn NFT + vm.prank(users.backer1Address); + CampaignInfo(campaignAddress).approve(address(timeConstrainedPaymentTreasury), 1); // tokenId 1 + // Then claim refund (use the overload without refundAddress since processCryptoPayment uses buyerAddress) vm.prank(users.backer1Address); timeConstrainedPaymentTreasury.claimRefund(PAYMENT_ID_1); diff --git a/test/foundry/unit/TreasuryFactory.t.sol b/test/foundry/unit/TreasuryFactory.t.sol index 489a0fe7..c3680d0e 100644 --- a/test/foundry/unit/TreasuryFactory.t.sol +++ b/test/foundry/unit/TreasuryFactory.t.sol @@ -161,9 +161,7 @@ contract TreasuryFactory_UpdatedUnitTest is Test, Defaults { factory.deploy( platformHash, address(0x1234), - implementationId, - "Test", - "TST" + implementationId ); vm.stopPrank(); } diff --git a/test/foundry/unit/Upgrades.t.sol b/test/foundry/unit/Upgrades.t.sol index 9c594ef0..30bbc6dc 100644 --- a/test/foundry/unit/Upgrades.t.sol +++ b/test/foundry/unit/Upgrades.t.sol @@ -220,7 +220,11 @@ contract Upgrades_Test is Test, Defaults { platforms, keys, values, - CAMPAIGN_DATA + CAMPAIGN_DATA, + "Campaign Pledge NFT", + "PLEDGE", + "ipfs://QmExampleImageURI", + "ipfs://QmExampleContractURI" ); address campaignBefore = campaignFactory.identifierToCampaignInfo(CAMPAIGN_1_IDENTIFIER_HASH); @@ -265,7 +269,11 @@ contract Upgrades_Test is Test, Defaults { platforms, keys, values, - CAMPAIGN_DATA + CAMPAIGN_DATA, + "Campaign Pledge NFT", + "PLEDGE", + "ipfs://QmExampleImageURI", + "ipfs://QmExampleContractURI" ); campaignFactory.createCampaign( @@ -274,7 +282,11 @@ contract Upgrades_Test is Test, Defaults { platforms, keys, values, - CAMPAIGN_DATA + CAMPAIGN_DATA, + "Campaign Pledge NFT", + "PLEDGE", + "ipfs://QmExampleImageURI", + "ipfs://QmExampleContractURI" ); vm.stopPrank(); @@ -337,7 +349,11 @@ contract Upgrades_Test is Test, Defaults { platforms, keys, values, - CAMPAIGN_DATA + CAMPAIGN_DATA, + "Campaign Pledge NFT", + "PLEDGE", + "ipfs://QmExampleImageURI", + "ipfs://QmExampleContractURI" ); } From 43b9948d1eca1d931a6ad929f867126087d29905 Mon Sep 17 00:00:00 2001 From: AdnanHKx Date: Wed, 12 Nov 2025 11:14:54 +0600 Subject: [PATCH 49/63] Refactor/campaign raised amount getters (#41) * Add time constraints for campaign creation * Fix unauthorized caller issue in tests * Exclude cancelled treasuries from total raised amount sum * Add total lifetime raised and refund claimed view functions * Add scenario specific raised amount getters --- src/CampaignInfo.sol | 84 +++++++++++++++++++++ src/interfaces/ICampaignInfo.sol | 47 +++++++++++- src/interfaces/ICampaignPaymentTreasury.sol | 19 +++++ src/interfaces/ICampaignTreasury.sol | 12 +++ src/treasuries/AllOrNothing.sol | 40 ++++++++++ src/treasuries/KeepWhatsRaised.sol | 41 ++++++++++ src/utils/BasePaymentTreasury.sol | 62 ++++++++++++++- src/utils/BaseTreasury.sol | 3 +- 8 files changed, 305 insertions(+), 3 deletions(-) diff --git a/src/CampaignInfo.sol b/src/CampaignInfo.sol index 3240dc09..536288b5 100644 --- a/src/CampaignInfo.sol +++ b/src/CampaignInfo.sol @@ -9,6 +9,7 @@ import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import {ICampaignInfo} from "./interfaces/ICampaignInfo.sol"; import {ICampaignData} from "./interfaces/ICampaignData.sol"; import {ICampaignTreasury} from "./interfaces/ICampaignTreasury.sol"; +import {ICampaignPaymentTreasury} from "./interfaces/ICampaignPaymentTreasury.sol"; import {IGlobalParams} from "./interfaces/IGlobalParams.sol"; import {TimestampChecker} from "./utils/TimestampChecker.sol"; import {AdminAccessChecker} from "./utils/AdminAccessChecker.sol"; @@ -271,6 +272,89 @@ contract CampaignInfo is return amount; } + /** + * @inheritdoc ICampaignInfo + */ + function getTotalLifetimeRaisedAmount() external view returns (uint256) { + bytes32[] memory tempPlatforms = s_approvedPlatformHashes; + uint256 length = s_approvedPlatformHashes.length; + uint256 amount; + address tempTreasury; + for (uint256 i = 0; i < length; i++) { + tempTreasury = s_platformTreasuryAddress[tempPlatforms[i]]; + amount += ICampaignTreasury(tempTreasury).getLifetimeRaisedAmount(); + } + return amount; + } + + /** + * @inheritdoc ICampaignInfo + */ + function getTotalRefundedAmount() external view returns (uint256) { + bytes32[] memory tempPlatforms = s_approvedPlatformHashes; + uint256 length = s_approvedPlatformHashes.length; + uint256 amount; + address tempTreasury; + for (uint256 i = 0; i < length; i++) { + tempTreasury = s_platformTreasuryAddress[tempPlatforms[i]]; + amount += ICampaignTreasury(tempTreasury).getRefundedAmount(); + } + return amount; + } + + /** + * @inheritdoc ICampaignInfo + */ + function getTotalAvailableRaisedAmount() external view returns (uint256) { + bytes32[] memory tempPlatforms = s_approvedPlatformHashes; + uint256 length = s_approvedPlatformHashes.length; + uint256 amount; + address tempTreasury; + for (uint256 i = 0; i < length; i++) { + tempTreasury = s_platformTreasuryAddress[tempPlatforms[i]]; + amount += ICampaignTreasury(tempTreasury).getRaisedAmount(); + } + return amount; + } + + /** + * @inheritdoc ICampaignInfo + */ + function getTotalCancelledAmount() external view returns (uint256) { + bytes32[] memory tempPlatforms = s_approvedPlatformHashes; + uint256 length = s_approvedPlatformHashes.length; + uint256 amount; + address tempTreasury; + for (uint256 i = 0; i < length; i++) { + tempTreasury = s_platformTreasuryAddress[tempPlatforms[i]]; + // Only include cancelled treasuries + if (ICampaignTreasury(tempTreasury).cancelled()) { + amount += ICampaignTreasury(tempTreasury).getRaisedAmount(); + } + } + return amount; + } + + /** + * @inheritdoc ICampaignInfo + */ + function getTotalExpectedAmount() external view returns (uint256) { + bytes32[] memory tempPlatforms = s_approvedPlatformHashes; + uint256 length = s_approvedPlatformHashes.length; + uint256 amount; + address tempTreasury; + for (uint256 i = 0; i < length; i++) { + tempTreasury = s_platformTreasuryAddress[tempPlatforms[i]]; + // Try to call getExpectedAmount - will only work for payment treasuries + try ICampaignPaymentTreasury(tempTreasury).getExpectedAmount() returns (uint256 expectedAmount) { + amount += expectedAmount; + } catch { + // Not a payment treasury or call failed, skip + } + } + return amount; + } + /** * @inheritdoc ICampaignInfo */ diff --git a/src/interfaces/ICampaignInfo.sol b/src/interfaces/ICampaignInfo.sol index c80bec3f..741e9d86 100644 --- a/src/interfaces/ICampaignInfo.sol +++ b/src/interfaces/ICampaignInfo.sol @@ -25,11 +25,56 @@ interface ICampaignInfo is IERC721 { ) external view returns (bool); /** - * @notice Retrieves the total amount raised in the campaign. + * @notice Retrieves the total amount raised across non-cancelled treasuries. + * @dev This excludes cancelled treasuries and is affected by refunds. * @return The total amount raised in the campaign. */ function getTotalRaisedAmount() external view returns (uint256); + /** + * @notice Retrieves the total lifetime raised amount across all treasuries. + * @dev This amount never decreases even when refunds are processed. + * It represents the sum of all pledges/payments ever made to the campaign, + * regardless of cancellations or refunds. + * @return The total lifetime raised amount as a uint256 value. + */ + function getTotalLifetimeRaisedAmount() external view returns (uint256); + + /** + * @notice Retrieves the total refunded amount across all treasuries. + * @dev This is calculated as the difference between lifetime raised amount + * and current raised amount. It represents the sum of all refunds + * that have been processed across all treasuries. + * @return The total refunded amount as a uint256 value. + */ + function getTotalRefundedAmount() external view returns (uint256); + + /** + * @notice Retrieves the total available raised amount across all treasuries. + * @dev This includes funds from both active and cancelled treasuries, + * and is affected by refunds. It represents the actual current + * balance of funds across all treasuries. + * @return The total available raised amount as a uint256 value. + */ + function getTotalAvailableRaisedAmount() external view returns (uint256); + + /** + * @notice Retrieves the total raised amount from cancelled treasuries only. + * @dev This is the opposite of getTotalRaisedAmount(), which only includes + * non-cancelled treasuries. This function only sums up raised amounts + * from treasuries that have been cancelled. + * @return The total raised amount from cancelled treasuries as a uint256 value. + */ + function getTotalCancelledAmount() external view returns (uint256); + + /** + * @notice Retrieves the total expected (pending) amount across payment treasuries. + * @dev This only applies to payment treasuries and represents payments that + * have been created but not yet confirmed. Regular treasuries are skipped. + * @return The total expected amount as a uint256 value. + */ + function getTotalExpectedAmount() external view returns (uint256); + /** * @notice Retrieves the address of the protocol administrator. * @return The address of the protocol administrator. diff --git a/src/interfaces/ICampaignPaymentTreasury.sol b/src/interfaces/ICampaignPaymentTreasury.sol index 49106f7e..f85cc926 100644 --- a/src/interfaces/ICampaignPaymentTreasury.sol +++ b/src/interfaces/ICampaignPaymentTreasury.sol @@ -140,6 +140,25 @@ interface ICampaignPaymentTreasury { */ function getAvailableRaisedAmount() external view returns (uint256); + /** + * @notice Retrieves the lifetime raised amount in the treasury (never decreases with refunds). + * @return The lifetime raised amount as a uint256 value. + */ + function getLifetimeRaisedAmount() external view returns (uint256); + + /** + * @notice Retrieves the total refunded amount in the treasury. + * @return The total refunded amount as a uint256 value. + */ + function getRefundedAmount() external view returns (uint256); + + /** + * @notice Retrieves the total expected (pending) amount in the treasury. + * @dev This represents payments that have been created but not yet confirmed. + * @return The total expected amount as a uint256 value. + */ + function getExpectedAmount() external view returns (uint256); + /** * @notice Checks if the treasury has been cancelled. * @return True if the treasury is cancelled, false otherwise. diff --git a/src/interfaces/ICampaignTreasury.sol b/src/interfaces/ICampaignTreasury.sol index 5224203e..853c8dc9 100644 --- a/src/interfaces/ICampaignTreasury.sol +++ b/src/interfaces/ICampaignTreasury.sol @@ -40,6 +40,18 @@ interface ICampaignTreasury { */ function getRaisedAmount() external view returns (uint256); + /** + * @notice Retrieves the lifetime raised amount in the treasury (never decreases with refunds). + * @return The lifetime raised amount as a uint256 value. + */ + function getLifetimeRaisedAmount() external view returns (uint256); + + /** + * @notice Retrieves the total refunded amount in the treasury. + * @return The total refunded amount as a uint256 value. + */ + function getRefundedAmount() external view returns (uint256); + /** * @notice Checks if the treasury has been cancelled. * @return True if the treasury is cancelled, false otherwise. diff --git a/src/treasuries/AllOrNothing.sol b/src/treasuries/AllOrNothing.sol index a8ad5f29..2769ce0b 100644 --- a/src/treasuries/AllOrNothing.sol +++ b/src/treasuries/AllOrNothing.sol @@ -165,6 +165,44 @@ contract AllOrNothing is return totalNormalized; } + /** + * @inheritdoc ICampaignTreasury + */ + function getLifetimeRaisedAmount() external view override returns (uint256) { + address[] memory acceptedTokens = INFO.getAcceptedTokens(); + uint256 totalNormalized = 0; + + for (uint256 i = 0; i < acceptedTokens.length; i++) { + address token = acceptedTokens[i]; + uint256 amount = s_tokenLifetimeRaisedAmounts[token]; + if (amount > 0) { + totalNormalized += _normalizeAmount(token, amount); + } + } + + return totalNormalized; + } + + /** + * @inheritdoc ICampaignTreasury + */ + function getRefundedAmount() external view override returns (uint256) { + address[] memory acceptedTokens = INFO.getAcceptedTokens(); + uint256 totalNormalized = 0; + + for (uint256 i = 0; i < acceptedTokens.length; i++) { + address token = acceptedTokens[i]; + uint256 lifetimeAmount = s_tokenLifetimeRaisedAmounts[token]; + uint256 currentAmount = s_tokenRaisedAmounts[token]; + uint256 refundedAmount = lifetimeAmount - currentAmount; + if (refundedAmount > 0) { + totalNormalized += _normalizeAmount(token, refundedAmount); + } + } + + return totalNormalized; + } + /** * @notice Adds multiple rewards in a batch. * @dev This function allows for both reward tiers and non-reward tiers. @@ -445,6 +483,8 @@ contract AllOrNothing is s_tokenToPledgedAmount[tokenId] = pledgeAmountInTokenDecimals; s_tokenToTotalCollectedAmount[tokenId] = totalAmount; s_tokenIdToPledgeToken[tokenId] = pledgeToken; + s_tokenRaisedAmounts[pledgeToken] += pledgeAmountInTokenDecimals; + s_tokenLifetimeRaisedAmounts[pledgeToken] += pledgeAmountInTokenDecimals; emit Receipt( backer, diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index 38e590d1..a2880bbb 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -379,6 +379,44 @@ contract KeepWhatsRaised is return totalNormalized; } + /** + * @inheritdoc ICampaignTreasury + */ + function getLifetimeRaisedAmount() external view override returns (uint256) { + address[] memory acceptedTokens = INFO.getAcceptedTokens(); + uint256 totalNormalized = 0; + + for (uint256 i = 0; i < acceptedTokens.length; i++) { + address token = acceptedTokens[i]; + uint256 amount = s_tokenLifetimeRaisedAmounts[token]; + if (amount > 0) { + totalNormalized += _normalizeAmount(token, amount); + } + } + + return totalNormalized; + } + + /** + * @inheritdoc ICampaignTreasury + */ + function getRefundedAmount() external view override returns (uint256) { + address[] memory acceptedTokens = INFO.getAcceptedTokens(); + uint256 totalNormalized = 0; + + for (uint256 i = 0; i < acceptedTokens.length; i++) { + address token = acceptedTokens[i]; + uint256 lifetimeAmount = s_tokenLifetimeRaisedAmounts[token]; + uint256 currentAmount = s_tokenRaisedAmounts[token]; + uint256 refundedAmount = lifetimeAmount - currentAmount; + if (refundedAmount > 0) { + totalNormalized += _normalizeAmount(token, refundedAmount); + } + } + + return totalNormalized; + } + /** * @notice Retrieves the currently available raised amount in the treasury. * @return The current available raised amount as a uint256 value. @@ -1185,6 +1223,9 @@ contract KeepWhatsRaised is s_tokenToPledgedAmount[tokenId] = pledgeAmountInTokenDecimals; s_tokenToTippedAmount[tokenId] = tip; s_tokenIdToPledgeToken[tokenId] = pledgeToken; + s_tipPerToken[pledgeToken] += tip; + s_tokenRaisedAmounts[pledgeToken] += pledgeAmountInTokenDecimals; + s_tokenLifetimeRaisedAmounts[pledgeToken] += pledgeAmountInTokenDecimals; uint256 netAvailable = _calculateNetAvailable(pledgeId, pledgeToken, tokenId, pledgeAmountInTokenDecimals); s_availablePerToken[pledgeToken] += netAvailable; diff --git a/src/utils/BasePaymentTreasury.sol b/src/utils/BasePaymentTreasury.sol index 6f8ed8d4..28b7f4a6 100644 --- a/src/utils/BasePaymentTreasury.sol +++ b/src/utils/BasePaymentTreasury.sol @@ -57,7 +57,8 @@ abstract contract BasePaymentTreasury is // Multi-token balances (all in token's native decimals) mapping(address => uint256) internal s_pendingPaymentPerToken; // Pending payment amounts per token - mapping(address => uint256) internal s_confirmedPaymentPerToken; // Confirmed payment amounts per token + mapping(address => uint256) internal s_confirmedPaymentPerToken; // Confirmed payment amounts per token (decreases on refunds) + mapping(address => uint256) internal s_lifetimeConfirmedPaymentPerToken; // Lifetime confirmed payment amounts per token (never decreases) mapping(address => uint256) internal s_availableConfirmedPerToken; // Available confirmed amounts per token /** @@ -290,6 +291,62 @@ abstract contract BasePaymentTreasury is return totalNormalized; } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function getLifetimeRaisedAmount() external view returns (uint256) { + address[] memory acceptedTokens = INFO.getAcceptedTokens(); + uint256 totalNormalized = 0; + + for (uint256 i = 0; i < acceptedTokens.length; i++) { + address token = acceptedTokens[i]; + uint256 amount = s_lifetimeConfirmedPaymentPerToken[token]; + if (amount > 0) { + totalNormalized += _normalizeAmount(token, amount); + } + } + + return totalNormalized; + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function getRefundedAmount() external view returns (uint256) { + address[] memory acceptedTokens = INFO.getAcceptedTokens(); + uint256 totalNormalized = 0; + + for (uint256 i = 0; i < acceptedTokens.length; i++) { + address token = acceptedTokens[i]; + uint256 lifetimeAmount = s_lifetimeConfirmedPaymentPerToken[token]; + uint256 currentAmount = s_confirmedPaymentPerToken[token]; + uint256 refundedAmount = lifetimeAmount - currentAmount; + if (refundedAmount > 0) { + totalNormalized += _normalizeAmount(token, refundedAmount); + } + } + + return totalNormalized; + } + + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function getExpectedAmount() external view returns (uint256) { + address[] memory acceptedTokens = INFO.getAcceptedTokens(); + uint256 totalNormalized = 0; + + for (uint256 i = 0; i < acceptedTokens.length; i++) { + address token = acceptedTokens[i]; + uint256 amount = s_pendingPaymentPerToken[token]; + if (amount > 0) { + totalNormalized += _normalizeAmount(token, amount); + } + } + + return totalNormalized; + } /** * @dev Normalizes token amounts to 18 decimals for consistent comparisons. @@ -497,6 +554,7 @@ abstract contract BasePaymentTreasury is s_paymentIdToToken[paymentId] = paymentToken; s_confirmedPaymentPerToken[paymentToken] += amount; + s_lifetimeConfirmedPaymentPerToken[paymentToken] += amount; s_availableConfirmedPerToken[paymentToken] += amount; // Mint NFT for crypto payment @@ -572,6 +630,7 @@ abstract contract BasePaymentTreasury is s_pendingPaymentPerToken[paymentToken] -= paymentAmount; s_confirmedPaymentPerToken[paymentToken] += paymentAmount; + s_lifetimeConfirmedPaymentPerToken[paymentToken] += paymentAmount; s_availableConfirmedPerToken[paymentToken] += paymentAmount; // Mint NFT if buyerAddress is provided @@ -632,6 +691,7 @@ abstract contract BasePaymentTreasury is s_payment[currentPaymentId].isConfirmed = true; s_pendingPaymentPerToken[currentToken] -= amount; s_confirmedPaymentPerToken[currentToken] += amount; + s_lifetimeConfirmedPaymentPerToken[currentToken] += amount; s_availableConfirmedPerToken[currentToken] += amount; // Mint NFT if buyer address provided for this payment diff --git a/src/utils/BaseTreasury.sol b/src/utils/BaseTreasury.sol index fef3ba6c..5b9029f2 100644 --- a/src/utils/BaseTreasury.sol +++ b/src/utils/BaseTreasury.sol @@ -34,7 +34,8 @@ abstract contract BaseTreasury is bool internal s_feesDisbursed; // Multi-token support - mapping(address => uint256) internal s_tokenRaisedAmounts; // Amount raised per token + mapping(address => uint256) internal s_tokenRaisedAmounts; // Amount raised per token (decreases on refunds) + mapping(address => uint256) internal s_tokenLifetimeRaisedAmounts; // Lifetime raised amount per token (never decreases) /** * @notice Emitted when fees are successfully disbursed for a specific token. From fbdbad195ebe6c636608bb8168723963b1f37dd9 Mon Sep 17 00:00:00 2001 From: mahabubAlahi <32974385+mahabubAlahi@users.noreply.github.com> Date: Wed, 12 Nov 2025 13:13:52 +0600 Subject: [PATCH 50/63] Add Line Item Support, External Fees Data, Claim Expire Funds Functionality and Payment Expiration Management to PaymentTreasury (#42) * Add platform-specific line item type management to GlobalParams - Introduced events for setting and removing platform line item types. - Added functions to set, remove, and retrieve platform-specific line item type configurations. - Implemented validation constraints for line item types to ensure correct configurations. - Updated GlobalParamsStorage to include a mapping for platform line item types. - Enhanced IGlobalParams interface with new methods for line item type management. * Add getLineItemType function to ICampaignInfo and CampaignInfo - Implemented the getLineItemType function in both ICampaignInfo and CampaignInfo contracts. - This function retrieves platform-specific line item type configurations from GlobalParams, enhancing the contract's functionality and providing necessary details for line item management. * Add line item support to PaymentTreasury and related contracts - Introduced a new LineItem struct in ICampaignPaymentTreasury to represent individual payment line items, including typeId and amount. - Updated createPayment, createPaymentBatch, and processCryptoPayment functions to accept line items as parameters. - Enhanced PaymentTreasury, TimeConstrainedPaymentTreasury, and BasePaymentTreasury to handle line items in payment processing, validation, and tracking. - Implemented logic for managing non-goal line items, including claiming and refunding functionalities. - Added necessary mappings and events to track line items associated with payments, improving overall payment management capabilities. * Add max payment expiration handling to BasePaymentTreasury - Introduced MAX_PAYMENT_EXPIRATION constant in DataRegistryKeys for managing maximum payment expiration duration. - Implemented _getMaxExpirationDuration function in BasePaymentTreasury to retrieve platform-specific or global max expiration settings. - Added error handling for cases where payment expiration exceeds the allowed maximum. - Updated payment validation logic to ensure compliance with the new expiration constraints. * Enhance PaymentTreasury tests with LineItem and expiration check support - Updated PaymentTreasury integration tests to include line items in createPayment and processCryptoPayment functions. - Introduced empty line items in various test scenarios to ensure compatibility with the new line item structure. - Added comprehensive tests for creating payments with multiple line items and validating their handling in PaymentTreasury. - Enhanced unit tests to cover line item scenarios, ensuring robust payment processing and validation. * Refactor refund calculation logic in BasePaymentTreasury - Enhanced the refund process by caching line item type configurations and protocol fee percentages to ensure consistency during calculations. - Separated the handling of goal and non-goal line items, allowing for accurate refund amounts based on their respective conditions. - Improved checks for available balances before modifying state, ensuring that refunds are only processed when sufficient funds are available. - Updated state management to reflect changes in confirmed and claimable amounts for both goal and non-goal line items, maintaining accurate tracking post-refund. * Add snapshot mechanism for countsTowardGoal in BasePaymentTreasury - Introduced a new mapping to store snapshots of countsTowardGoal flags for line items at payment creation, ensuring consistency even if configurations change later. - Updated payment processing logic to utilize the snapshot for accurate pending amount calculations, preventing discrepancies due to configuration changes. - Cleaned up snapshots after payment confirmation to maintain state integrity and avoid unnecessary storage usage. * Refactor line item configuration handling in BasePaymentTreasury - Introduced a new struct, LineItemConfigSnapshot, to encapsulate all relevant line item configuration flags at payment creation time, enhancing efficiency and scalability. - Updated mappings and logic to utilize the new struct for consistent processing of line items during payment confirmation, cancellation, and refunds. - Cleaned up snapshots after processing to maintain state integrity and optimize storage usage. * Enhance line item processing in BasePaymentTreasury - Added a new boolean flag, canRefund, to the line item configuration, allowing for more granular control over refund capabilities. - Updated logic to utilize snapshots of line item configurations, ensuring consistency during payment processing, refunds, and state updates. - Implemented checks to validate the length of line items against their corresponding configuration snapshots, preventing invalid inputs and enhancing error handling. * Remove redundant snapshot cleanup in BasePaymentTreasury payment confirmation logic. * Fix protocol fee handling during claimRefund * Refactor line item handling in BasePaymentTreasury - Consolidated line item storage by introducing a new struct, StoredLineItem, which encapsulates line item details and configuration flags. - Updated mappings and logic to utilize the new struct, enhancing efficiency and consistency during payment processing, refunds, and state updates. - Removed redundant snapshot handling for line item configurations, streamlining the code and improving maintainability. * Add external fees support to payment processing - Introduced a new ExternalFees struct in ICampaignPaymentTreasury to represent external fees associated with payments, including fee type and amount. - Updated createPayment and createPaymentBatch functions across PaymentTreasury, TimeConstrainedPaymentTreasury, and BasePaymentTreasury to accept external fees as parameters. - Enhanced internal mappings to store external fees per payment ID, ensuring proper tracking and management during payment processing and refunds. - Implemented logic to validate and store external fees, improving the overall payment handling capabilities. * Enhance payment treasury tests to include external fees - Updated createPayment and createPaymentBatch functions across PaymentTreasury and TimeConstrainedPaymentTreasury to accept external fees as parameters. - Modified integration and unit tests to accommodate the new external fees structure, ensuring comprehensive coverage for payment scenarios. - Ensured compatibility with existing line item handling while improving overall payment processing capabilities. * Add payment data getter function and update crypto payment function - Introduced PaymentLineItem and PaymentData structs in ICampaignPaymentTreasury to encapsulate detailed payment information and line item configurations. - Updated processCryptoPayment function across PaymentTreasury and TimeConstrainedPaymentTreasury to accept external fees as parameters. - Implemented getPaymentData function to retrieve comprehensive payment details, including line items and external fees, improving data accessibility and usability. * Update payment processing to include external fees in tests - Modified processCryptoPayment function across various test files to accept external fees as parameters, ensuring comprehensive testing of payment scenarios. - Enhanced unit and integration tests to validate the handling of external fees, improving coverage and reliability of payment processing functionalities. - Added new test cases to verify the correct storage and retrieval of external fees within payment data, ensuring accurate fee management. * Refactor line item handling in BasePaymentTreasury to use ICampaignPaymentTreasury types - Updated function signatures in BasePaymentTreasury to utilize ICampaignPaymentTreasury.LineItem for line item handling, enhancing type safety and consistency. - Adjusted related logic to accommodate the new struct, ensuring proper validation and processing of line items. - Modified external fees handling in payment data retrieval to improve memory management and maintainability. * Add platform claim delay functionality to CampaignInfo and GlobalParams - Implemented getPlatformClaimDelay function in both CampaignInfo and GlobalParams contracts to retrieve the claim delay for specific platforms. - Added updatePlatformClaimDelay function in GlobalParams to allow platform admins to modify the claim delay, with appropriate access control and event emission. - Updated ICampaignInfo and IGlobalParams interfaces to include the new functions, ensuring consistency across the contracts. - Enhanced GlobalParamsStorage to store platform-specific claim delays, improving data management for platform configurations. * Add refundable fee type and related tests for payment processing - Introduced a new line item type, REFUNDABLE_FEE_WITH_PROTOCOL_TYPE_ID, to support refundable fees with protocol fees in the PaymentTreasury. - Updated the setUp function to register the new line item type in the GlobalParams contract. - Added a test case to validate the processing of crypto payments with refundable fees, ensuring correct refund calculations and fee distributions. - Enhanced unit tests for GlobalParams to verify the correct setup and constraints for the new line item type, including checks for refundability and protocol fee application. * Remove unused state updates for pledge amounts in AllOrNothing and KeepWhatsRaised contracts * Add line item totals struct and refactor payment confirmation logic - Introduced a new `LineItemTotals` struct to encapsulate calculation totals for line items, reducing stack depth and improving readability. - Refactored the payment confirmation process to utilize the new struct, enhancing clarity and maintainability. - Updated internal functions to calculate line item totals and check balances more efficiently, ensuring accurate payment processing. - Streamlined state updates for line items during payment confirmation, improving overall gas efficiency. * Enhance payment creation and confirmation logic with line items and external fees - Updated the createPayment function to accept an array of line items and external fees, improving flexibility in payment processing. - Modified the confirmPayment function to include an address parameter, ensuring compatibility with the new payment structure. - Added tests to validate the handling of line items and external fees during payment confirmation, enhancing overall test coverage. * Update lifetime confirmed payment tracking in BasePaymentTreasury --- src/CampaignInfo.sol | 31 + src/GlobalParams.sol | 193 ++++ src/constants/DataRegistryKeys.sol | 11 + src/interfaces/ICampaignInfo.sol | 35 + src/interfaces/ICampaignPaymentTreasury.sol | 98 +- src/interfaces/IGlobalParams.sol | 72 ++ src/storage/GlobalParamsStorage.sol | 21 + src/treasuries/AllOrNothing.sol | 2 - src/treasuries/KeepWhatsRaised.sol | 3 - src/treasuries/PaymentTreasury.sol | 25 +- .../TimeConstrainedPaymentTreasury.sol | 26 +- src/utils/BasePaymentTreasury.sol | 886 +++++++++++++++++- .../PaymentTreasury/PaymentTreasury.t.sol | 26 +- .../PaymentTreasuryBatchLimitTest.t.sol | 5 +- .../PaymentTreasuryFunction.t.sol | 23 +- .../PaymentTreasuryLineItems.t.sol | 716 ++++++++++++++ ...meConstrainedPaymentTreasuryFunction.t.sol | 110 ++- test/foundry/unit/GlobalParams.t.sol | 123 +++ test/foundry/unit/PaymentTreasury.t.sol | 355 ++++++- .../unit/TimeConstrainedPaymentTreasury.t.sol | 124 ++- 20 files changed, 2693 insertions(+), 192 deletions(-) create mode 100644 test/foundry/integration/PaymentTreasury/PaymentTreasuryLineItems.t.sol diff --git a/src/CampaignInfo.sol b/src/CampaignInfo.sol index 536288b5..93114444 100644 --- a/src/CampaignInfo.sol +++ b/src/CampaignInfo.sol @@ -447,6 +447,15 @@ contract CampaignInfo is return s_platformFeePercent[platformHash]; } + /** + * @inheritdoc ICampaignInfo + */ + function getPlatformClaimDelay( + bytes32 platformHash + ) external view override returns (uint256) { + return _getGlobalParams().getPlatformClaimDelay(platformHash); + } + /** * @inheritdoc ICampaignInfo */ @@ -483,6 +492,28 @@ contract CampaignInfo is bufferTime = uint256(valueBytes); } + /** + * @inheritdoc ICampaignInfo + */ + function getLineItemType( + bytes32 platformHash, + bytes32 typeId + ) + external + view + override + returns ( + bool exists, + string memory label, + bool countsTowardGoal, + bool applyProtocolFee, + bool canRefund, + bool instantTransfer + ) + { + return _getGlobalParams().getPlatformLineItemType(platformHash, typeId); + } + /** * @inheritdoc Ownable */ diff --git a/src/GlobalParams.sol b/src/GlobalParams.sol index db72ee41..2dae5d11 100644 --- a/src/GlobalParams.sol +++ b/src/GlobalParams.sol @@ -101,6 +101,34 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU */ event DataAddedToRegistry(bytes32 indexed key, bytes32 value); + /** + * @dev Emitted when a platform-specific line item type is set or updated. + * @param platformHash The identifier of the platform. + * @param typeId The identifier of the line item type. + * @param label The label of the line item type. + * @param countsTowardGoal Whether this line item counts toward the campaign goal. + * @param applyProtocolFee Whether this line item is included in protocol fee calculation. + * @param canRefund Whether this line item can be refunded. + * @param instantTransfer Whether this line item amount can be instantly transferred to platform admin after payment confirmation. + */ + event PlatformLineItemTypeSet( + bytes32 indexed platformHash, + bytes32 indexed typeId, + string label, + bool countsTowardGoal, + bool applyProtocolFee, + bool canRefund, + bool instantTransfer + ); + event PlatformClaimDelayUpdated(bytes32 indexed platformHash, uint256 claimDelay); + + /** + * @dev Emitted when a platform-specific line item type is removed. + * @param platformHash The identifier of the platform. + * @param typeId The identifier of the removed line item type. + */ + event PlatformLineItemTypeRemoved(bytes32 indexed platformHash, bytes32 indexed typeId); + /** * @dev Throws when the input address is zero. */ @@ -168,6 +196,13 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU * @param token The token address. */ error GlobalParamsTokenNotInCurrency(bytes32 currency, address token); + + /** + * @dev Throws when a platform-specific line item type is not found. + * @param platformHash The identifier of the platform. + * @param typeId The identifier of the line item type. + */ + error GlobalParamsPlatformLineItemTypeNotFound(bytes32 platformHash, bytes32 typeId); /** * @dev Reverts if the input address is zero. @@ -348,6 +383,22 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU platformFeePercent = $.platformFeePercent[platformHash]; } + /** + * @inheritdoc IGlobalParams + */ + function getPlatformClaimDelay( + bytes32 platformHash + ) + external + view + override + platformIsListed(platformHash) + returns (uint256 claimDelay) + { + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + claimDelay = $.platformClaimDelay[platformHash]; + } + /** * @inheritdoc IGlobalParams */ @@ -506,6 +557,23 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU emit PlatformAdminAddressUpdated(platformHash, platformAdminAddress); } + /** + * @inheritdoc IGlobalParams + */ + function updatePlatformClaimDelay( + bytes32 platformHash, + uint256 claimDelay + ) + external + override + platformIsListed(platformHash) + onlyPlatformAdmin(platformHash) + { + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + $.platformClaimDelay[platformHash] = claimDelay; + emit PlatformClaimDelayUpdated(platformHash, claimDelay); + } + /** * @inheritdoc IGlobalParams */ @@ -559,6 +627,131 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU return $.currencyToTokens[currency]; } + /** + * @notice Sets or updates a platform-specific line item type configuration. + * @dev Only callable by the platform admin. + * @param platformHash The identifier of the platform. + * @param typeId The identifier of the line item type. + * @param label The label identifier for the line item type. + * @param countsTowardGoal Whether this line item counts toward the campaign goal. + * @param applyProtocolFee Whether this line item is included in protocol fee calculation. + * @param canRefund Whether this line item can be refunded. + * @param instantTransfer Whether this line item amount can be instantly transferred. + * + * Constraints: + * - If countsTowardGoal is true, then applyProtocolFee must be false, canRefund must be true, and instantTransfer must be false. + * - Non-goal instant transfer items cannot be refundable. + */ + function setPlatformLineItemType( + bytes32 platformHash, + bytes32 typeId, + string calldata label, + bool countsTowardGoal, + bool applyProtocolFee, + bool canRefund, + bool instantTransfer + ) external platformIsListed(platformHash) onlyPlatformAdmin(platformHash) { + if (typeId == ZERO_BYTES) { + revert GlobalParamsInvalidInput(); + } + + // Validation constraint 1: If countsTowardGoal is true, then applyProtocolFee must be false, canRefund must be true, and instantTransfer must be false + if (countsTowardGoal) { + if (applyProtocolFee) { + revert GlobalParamsInvalidInput(); + } + if (!canRefund) { + revert GlobalParamsInvalidInput(); + } + if (instantTransfer) { + revert GlobalParamsInvalidInput(); + } + } + + // Validation constraint 2: Non-goal instant transfer items cannot be refundable + if (!countsTowardGoal && instantTransfer && canRefund) { + revert GlobalParamsInvalidInput(); + } + + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + $.platformLineItemTypes[platformHash][typeId] = GlobalParamsStorage.LineItemType({ + exists: true, + label: label, + countsTowardGoal: countsTowardGoal, + applyProtocolFee: applyProtocolFee, + canRefund: canRefund, + instantTransfer: instantTransfer + }); + emit PlatformLineItemTypeSet( + platformHash, + typeId, + label, + countsTowardGoal, + applyProtocolFee, + canRefund, + instantTransfer + ); + } + + /** + * @notice Removes a platform-specific line item type by setting its exists flag to false. + * @dev Only callable by the platform admin. This prevents the type from being used in new pledges. + * @param platformHash The identifier of the platform. + * @param typeId The identifier of the line item type to remove. + */ + function removePlatformLineItemType( + bytes32 platformHash, + bytes32 typeId + ) external platformIsListed(platformHash) onlyPlatformAdmin(platformHash) { + if (typeId == ZERO_BYTES) { + revert GlobalParamsInvalidInput(); + } + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + if (!$.platformLineItemTypes[platformHash][typeId].exists) { + revert GlobalParamsPlatformLineItemTypeNotFound(platformHash, typeId); + } + $.platformLineItemTypes[platformHash][typeId].exists = false; + emit PlatformLineItemTypeRemoved(platformHash, typeId); + } + + /** + * @notice Retrieves a platform-specific line item type configuration. + * @param platformHash The identifier of the platform. + * @param typeId The identifier of the line item type. + * @return exists Whether this line item type exists and is active. + * @return label The label identifier for the line item type. + * @return countsTowardGoal Whether this line item counts toward the campaign goal. + * @return applyProtocolFee Whether this line item is included in protocol fee calculation. + * @return canRefund Whether this line item can be refunded. + * @return instantTransfer Whether this line item amount can be instantly transferred to platform admin after payment confirmation. + */ + function getPlatformLineItemType( + bytes32 platformHash, + bytes32 typeId + ) + external + view + returns ( + bool exists, + string memory label, + bool countsTowardGoal, + bool applyProtocolFee, + bool canRefund, + bool instantTransfer + ) + { + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + GlobalParamsStorage.LineItemType storage lineItemType = $.platformLineItemTypes[platformHash][typeId]; + return ( + lineItemType.exists, + lineItemType.label, + lineItemType.countsTowardGoal, + lineItemType.applyProtocolFee, + lineItemType.canRefund, + lineItemType.instantTransfer + ); + } + /** * @dev Reverts if the input address is zero. */ diff --git a/src/constants/DataRegistryKeys.sol b/src/constants/DataRegistryKeys.sol index 80bf4771..f3dbe571 100644 --- a/src/constants/DataRegistryKeys.sol +++ b/src/constants/DataRegistryKeys.sol @@ -10,6 +10,17 @@ pragma solidity ^0.8.22; library DataRegistryKeys { // Time-related keys bytes32 public constant BUFFER_TIME = keccak256("bufferTime"); + bytes32 public constant MAX_PAYMENT_EXPIRATION = keccak256("maxPaymentExpiration"); bytes32 public constant CAMPAIGN_LAUNCH_BUFFER = keccak256("campaignLaunchBuffer"); bytes32 public constant MINIMUM_CAMPAIGN_DURATION = keccak256("minimumCampaignDuration"); + + /** + * @notice Generates a namespaced registry key scoped to a specific platform. + * @param baseKey The base registry key. + * @param platformHash The identifier of the platform. + * @return platformKey The platform-scoped registry key. + */ + function scopedToPlatform(bytes32 baseKey, bytes32 platformHash) internal pure returns (bytes32 platformKey) { + platformKey = keccak256(abi.encode(baseKey, platformHash)); + } } diff --git a/src/interfaces/ICampaignInfo.sol b/src/interfaces/ICampaignInfo.sol index 741e9d86..a24a7962 100644 --- a/src/interfaces/ICampaignInfo.sol +++ b/src/interfaces/ICampaignInfo.sol @@ -142,6 +142,15 @@ interface ICampaignInfo is IERC721 { bytes32 platformHash ) external view returns (uint256); + /** + * @notice Retrieves the claim delay (in seconds) configured for the given platform. + * @param platformHash The identifier of the platform. + * @return The claim delay in seconds. + */ + function getPlatformClaimDelay( + bytes32 platformHash + ) external view returns (uint256); + /** * @notice Retrieves platform-specific data for the campaign. * @param platformDataKey The bytes32 identifier of the platform-specific data. @@ -219,6 +228,32 @@ interface ICampaignInfo is IERC721 { */ function getBufferTime() external view returns (uint256 bufferTime); + /** + * @notice Retrieves a platform-specific line item type configuration from GlobalParams. + * @param platformHash The identifier of the platform. + * @param typeId The identifier of the line item type. + * @return exists Whether this line item type exists and is active. + * @return label The label identifier for the line item type. + * @return countsTowardGoal Whether this line item counts toward the campaign goal. + * @return applyProtocolFee Whether this line item is included in protocol fee calculation. + * @return canRefund Whether this line item can be refunded. + * @return instantTransfer Whether this line item amount can be instantly transferred. + */ + function getLineItemType( + bytes32 platformHash, + bytes32 typeId + ) + external + view + returns ( + bool exists, + string memory label, + bool countsTowardGoal, + bool applyProtocolFee, + bool canRefund, + bool instantTransfer + ); + /** * @notice Mints a pledge NFT for a backer * @dev Can only be called by treasuries with MINTER_ROLE diff --git a/src/interfaces/ICampaignPaymentTreasury.sol b/src/interfaces/ICampaignPaymentTreasury.sol index f85cc926..ee40d404 100644 --- a/src/interfaces/ICampaignPaymentTreasury.sol +++ b/src/interfaces/ICampaignPaymentTreasury.sol @@ -7,6 +7,74 @@ pragma solidity ^0.8.22; */ interface ICampaignPaymentTreasury { + /** + * @notice Represents a stored line item with its configuration snapshot. + * @param typeId The type identifier of the line item. + * @param amount The amount of the line item. + * @param label The human-readable label of the line item type. + * @param countsTowardGoal Whether this line item counts toward the campaign goal. + * @param applyProtocolFee Whether protocol fee applies to this line item. + * @param canRefund Whether this line item can be refunded. + * @param instantTransfer Whether this line item is transferred instantly. + */ + struct PaymentLineItem { + bytes32 typeId; + uint256 amount; + string label; + bool countsTowardGoal; + bool applyProtocolFee; + bool canRefund; + bool instantTransfer; + } + + /** + * @notice Comprehensive payment data structure containing all payment information. + * @param buyerAddress The address of the buyer who made the payment. + * @param buyerId The ID of the buyer. + * @param itemId The identifier of the item being purchased. + * @param amount The amount to be paid for the item (in token's native decimals). + * @param expiration The timestamp after which the payment expires. + * @param isConfirmed Boolean indicating whether the payment has been confirmed. + * @param isCryptoPayment Boolean indicating whether the payment is made using direct crypto payment. + * @param lineItemCount The number of line items associated with this payment. + * @param paymentToken The token address used for this payment. + * @param lineItems Array of stored line items with their configuration snapshots. + * @param externalFees Array of external fees associated with this payment. + */ + struct PaymentData { + address buyerAddress; + bytes32 buyerId; + bytes32 itemId; + uint256 amount; + uint256 expiration; + bool isConfirmed; + bool isCryptoPayment; + uint256 lineItemCount; + address paymentToken; + PaymentLineItem[] lineItems; + ExternalFees[] externalFees; + } + + /** + * @notice Represents a line item in a payment. + * @param typeId The type identifier of the line item (must exist in GlobalParams). + * @param amount The amount of the line item (denominated in pledge token). + */ + struct LineItem { + bytes32 typeId; + uint256 amount; + } + + /** + * @notice Represents external fees associated with a payment. + * @param feeType The type identifier of the external fee. + * @param feeAmount The amount of the external fee. + */ + struct ExternalFees { + bytes32 feeType; + uint256 feeAmount; + } + /** * @notice Creates a new payment entry with the specified details. * @param paymentId A unique identifier for the payment. @@ -15,6 +83,8 @@ interface ICampaignPaymentTreasury { * @param paymentToken The token to use for the payment. * @param amount The amount to be paid for the item. * @param expiration The timestamp after which the payment expires. + * @param lineItems Array of line items associated with this payment. + * @param externalFees Array of external fees associated with this payment. */ function createPayment( bytes32 paymentId, @@ -22,7 +92,9 @@ interface ICampaignPaymentTreasury { bytes32 itemId, address paymentToken, uint256 amount, - uint256 expiration + uint256 expiration, + LineItem[] calldata lineItems, + ExternalFees[] calldata externalFees ) external; /** @@ -33,6 +105,8 @@ interface ICampaignPaymentTreasury { * @param paymentTokens An array of tokens corresponding to each payment. * @param amounts An array of amounts corresponding to each payment. * @param expirations An array of expiration timestamps corresponding to each payment. + * @param lineItemsArray An array of line item arrays, one for each payment. + * @param externalFeesArray An array of external fees arrays, one for each payment. */ function createPaymentBatch( bytes32[] calldata paymentIds, @@ -40,7 +114,9 @@ interface ICampaignPaymentTreasury { bytes32[] calldata itemIds, address[] calldata paymentTokens, uint256[] calldata amounts, - uint256[] calldata expirations + uint256[] calldata expirations, + LineItem[][] calldata lineItemsArray, + ExternalFees[][] calldata externalFeesArray ) external; /** @@ -51,13 +127,17 @@ interface ICampaignPaymentTreasury { * @param buyerAddress The address of the buyer making the payment. * @param paymentToken The token to use for the payment. * @param amount The amount to be paid for the item. + * @param lineItems Array of line items associated with this payment. + * @param externalFees Array of external fees associated with this payment. */ function processCryptoPayment( bytes32 paymentId, bytes32 itemId, address buyerAddress, address paymentToken, - uint256 amount + uint256 amount, + LineItem[] calldata lineItems, + ExternalFees[] calldata externalFees ) external; /** @@ -116,6 +196,11 @@ interface ICampaignPaymentTreasury { bytes32 paymentId ) external; + /** + * @notice Allows platform admin to claim all remaining funds once the claim window has opened. + */ + function claimExpiredFunds() external; + /** * @notice Retrieves the platform identifier associated with the treasury. * @return The platform identifier as a bytes32 value. @@ -140,6 +225,13 @@ interface ICampaignPaymentTreasury { */ function getAvailableRaisedAmount() external view returns (uint256); + /** + * @notice Retrieves comprehensive payment data including payment info, token, line items, and external fees. + * @param paymentId The unique identifier of the payment. + * @return A PaymentData struct containing all payment information. + */ + function getPaymentData(bytes32 paymentId) external view returns (PaymentData memory); + /** * @notice Retrieves the lifetime raised amount in the treasury (never decreases with refunds). * @return The lifetime raised amount as a uint256 value. diff --git a/src/interfaces/IGlobalParams.sol b/src/interfaces/IGlobalParams.sol index d02f2460..60d3461a 100644 --- a/src/interfaces/IGlobalParams.sol +++ b/src/interfaces/IGlobalParams.sol @@ -60,6 +60,15 @@ interface IGlobalParams { bytes32 platformHash ) external view returns (uint256); + /** + * @notice Retrieves the claim delay (in seconds) for a specific platform. + * @param platformHash The unique identifier of the platform. + * @return The claim delay in seconds. + */ + function getPlatformClaimDelay( + bytes32 platformHash + ) external view returns (uint256); + /** * @notice Checks if a platform-specific data key is valid. * @param platformDataKey The key of the platform-specific data. @@ -91,6 +100,16 @@ interface IGlobalParams { address _platformAdminAddress ) external; + /** + * @notice Updates the claim delay for a specific platform. + * @param platformHash The unique identifier of the platform. + * @param claimDelay The claim delay in seconds. + */ + function updatePlatformClaimDelay( + bytes32 platformHash, + uint256 claimDelay + ) external; + /** * @notice Adds a token to a currency. * @param currency The currency identifier. @@ -120,4 +139,57 @@ interface IGlobalParams { * @return value The registry value. */ function getFromRegistry(bytes32 key) external view returns (bytes32 value); + + /** + * @notice Sets or updates a platform-specific line item type configuration. + * @param platformHash The identifier of the platform. + * @param typeId The identifier of the line item type. + * @param label The label identifier for the line item type. + * @param countsTowardGoal Whether this line item counts toward the campaign goal. + * @param applyProtocolFee Whether this line item is included in protocol fee calculation. + * @param canRefund Whether this line item can be refunded. + * @param instantTransfer Whether this line item amount can be instantly transferred. + */ + function setPlatformLineItemType( + bytes32 platformHash, + bytes32 typeId, + string calldata label, + bool countsTowardGoal, + bool applyProtocolFee, + bool canRefund, + bool instantTransfer + ) external; + + /** + * @notice Removes a platform-specific line item type by setting its exists flag to false. + * @param platformHash The identifier of the platform. + * @param typeId The identifier of the line item type to remove. + */ + function removePlatformLineItemType(bytes32 platformHash, bytes32 typeId) external; + + /** + * @notice Retrieves a platform-specific line item type configuration. + * @param platformHash The identifier of the platform. + * @param typeId The identifier of the line item type. + * @return exists Whether this line item type exists and is active. + * @return label The label identifier for the line item type. + * @return countsTowardGoal Whether this line item counts toward the campaign goal. + * @return applyProtocolFee Whether this line item is included in protocol fee calculation. + * @return canRefund Whether this line item can be refunded. + * @return instantTransfer Whether this line item amount can be instantly transferred. + */ + function getPlatformLineItemType( + bytes32 platformHash, + bytes32 typeId + ) + external + view + returns ( + bool exists, + string memory label, + bool countsTowardGoal, + bool applyProtocolFee, + bool canRefund, + bool instantTransfer + ); } diff --git a/src/storage/GlobalParamsStorage.sol b/src/storage/GlobalParamsStorage.sol index 401eff25..3d8232ee 100644 --- a/src/storage/GlobalParamsStorage.sol +++ b/src/storage/GlobalParamsStorage.sol @@ -11,6 +11,24 @@ import {Counters} from "../utils/Counters.sol"; library GlobalParamsStorage { using Counters for Counters.Counter; + /** + * @notice Line item type configuration + * @param exists Whether this line item type exists and is active + * @param label The label identifier for the line item type (e.g., "shipping_fee") + * @param countsTowardGoal Whether this line item counts toward the campaign goal + * @param applyProtocolFee Whether this line item is included in protocol fee calculation + * @param canRefund Whether this line item can be refunded + * @param instantTransfer Whether this line item amount can be instantly transferred + */ + struct LineItemType { + bool exists; + string label; + bool countsTowardGoal; + bool applyProtocolFee; + bool canRefund; + bool instantTransfer; + } + /// @custom:storage-location erc7201:ccprotocol.storage.GlobalParams struct Storage { address protocolAdminAddress; @@ -22,6 +40,9 @@ library GlobalParamsStorage { mapping(bytes32 => bool) platformData; mapping(bytes32 => bytes32) dataRegistry; mapping(bytes32 => address[]) currencyToTokens; + // Platform-specific line item types: mapping(platformHash => mapping(typeId => LineItemType)) + mapping(bytes32 => mapping(bytes32 => LineItemType)) platformLineItemTypes; + mapping(bytes32 => uint256) platformClaimDelay; Counters.Counter numberOfListedPlatforms; } diff --git a/src/treasuries/AllOrNothing.sol b/src/treasuries/AllOrNothing.sol index 2769ce0b..c8fa304d 100644 --- a/src/treasuries/AllOrNothing.sol +++ b/src/treasuries/AllOrNothing.sol @@ -469,8 +469,6 @@ contract AllOrNothing is IERC20(pledgeToken).safeTransferFrom(backer, address(this), totalAmount); - s_tokenRaisedAmounts[pledgeToken] += pledgeAmountInTokenDecimals; - uint256 tokenId = INFO.mintNFTForPledge( backer, reward, diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index a2880bbb..d4b61b23 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -1208,9 +1208,6 @@ contract KeepWhatsRaised is IERC20(pledgeToken).safeTransferFrom(tokenSource, address(this), totalAmount); - s_tipPerToken[pledgeToken] += tip; - s_tokenRaisedAmounts[pledgeToken] += pledgeAmountInTokenDecimals; - uint256 tokenId = INFO.mintNFTForPledge( backer, reward, diff --git a/src/treasuries/PaymentTreasury.sol b/src/treasuries/PaymentTreasury.sol index 05eb0bc2..d7179b01 100644 --- a/src/treasuries/PaymentTreasury.sol +++ b/src/treasuries/PaymentTreasury.sol @@ -37,9 +37,11 @@ contract PaymentTreasury is bytes32 itemId, address paymentToken, uint256 amount, - uint256 expiration + uint256 expiration, + ICampaignPaymentTreasury.LineItem[] calldata lineItems, + ICampaignPaymentTreasury.ExternalFees[] calldata externalFees ) public override whenNotPaused whenNotCancelled { - super.createPayment(paymentId, buyerId, itemId, paymentToken, amount, expiration); + super.createPayment(paymentId, buyerId, itemId, paymentToken, amount, expiration, lineItems, externalFees); } /** @@ -51,9 +53,11 @@ contract PaymentTreasury is bytes32[] calldata itemIds, address[] calldata paymentTokens, uint256[] calldata amounts, - uint256[] calldata expirations + uint256[] calldata expirations, + ICampaignPaymentTreasury.LineItem[][] calldata lineItemsArray, + ICampaignPaymentTreasury.ExternalFees[][] calldata externalFeesArray ) public override whenNotPaused whenNotCancelled { - super.createPaymentBatch(paymentIds, buyerIds, itemIds, paymentTokens, amounts, expirations); + super.createPaymentBatch(paymentIds, buyerIds, itemIds, paymentTokens, amounts, expirations, lineItemsArray, externalFeesArray); } /** @@ -64,9 +68,11 @@ contract PaymentTreasury is bytes32 itemId, address buyerAddress, address paymentToken, - uint256 amount + uint256 amount, + ICampaignPaymentTreasury.LineItem[] calldata lineItems, + ICampaignPaymentTreasury.ExternalFees[] calldata externalFees ) public override whenNotPaused whenNotCancelled { - super.processCryptoPayment(paymentId, itemId, buyerAddress, paymentToken, amount); + super.processCryptoPayment(paymentId, itemId, buyerAddress, paymentToken, amount, lineItems, externalFees); } /** @@ -117,6 +123,13 @@ contract PaymentTreasury is super.claimRefund(paymentId); } + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function claimExpiredFunds() public override whenNotPaused whenNotCancelled { + super.claimExpiredFunds(); + } + /** * @inheritdoc ICampaignPaymentTreasury */ diff --git a/src/treasuries/TimeConstrainedPaymentTreasury.sol b/src/treasuries/TimeConstrainedPaymentTreasury.sol index f3258f99..49cf3ec7 100644 --- a/src/treasuries/TimeConstrainedPaymentTreasury.sol +++ b/src/treasuries/TimeConstrainedPaymentTreasury.sol @@ -57,10 +57,12 @@ contract TimeConstrainedPaymentTreasury is bytes32 itemId, address paymentToken, uint256 amount, - uint256 expiration + uint256 expiration, + ICampaignPaymentTreasury.LineItem[] calldata lineItems, + ICampaignPaymentTreasury.ExternalFees[] calldata externalFees ) public override whenCampaignNotPaused whenCampaignNotCancelled { _checkTimeWithinRange(); - super.createPayment(paymentId, buyerId, itemId, paymentToken, amount, expiration); + super.createPayment(paymentId, buyerId, itemId, paymentToken, amount, expiration, lineItems, externalFees); } /** @@ -72,10 +74,12 @@ contract TimeConstrainedPaymentTreasury is bytes32[] calldata itemIds, address[] calldata paymentTokens, uint256[] calldata amounts, - uint256[] calldata expirations + uint256[] calldata expirations, + ICampaignPaymentTreasury.LineItem[][] calldata lineItemsArray, + ICampaignPaymentTreasury.ExternalFees[][] calldata externalFeesArray ) public override whenCampaignNotPaused whenCampaignNotCancelled { _checkTimeWithinRange(); - super.createPaymentBatch(paymentIds, buyerIds, itemIds, paymentTokens, amounts, expirations); + super.createPaymentBatch(paymentIds, buyerIds, itemIds, paymentTokens, amounts, expirations, lineItemsArray, externalFeesArray); } /** @@ -86,10 +90,12 @@ contract TimeConstrainedPaymentTreasury is bytes32 itemId, address buyerAddress, address paymentToken, - uint256 amount + uint256 amount, + ICampaignPaymentTreasury.LineItem[] calldata lineItems, + ICampaignPaymentTreasury.ExternalFees[] calldata externalFees ) public override whenCampaignNotPaused whenCampaignNotCancelled { _checkTimeWithinRange(); - super.processCryptoPayment(paymentId, itemId, buyerAddress, paymentToken, amount); + super.processCryptoPayment(paymentId, itemId, buyerAddress, paymentToken, amount, lineItems, externalFees); } /** @@ -145,6 +151,14 @@ contract TimeConstrainedPaymentTreasury is super.claimRefund(paymentId); } + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function claimExpiredFunds() public override whenCampaignNotPaused whenCampaignNotCancelled { + _checkTimeIsGreater(); + super.claimExpiredFunds(); + } + /** * @inheritdoc ICampaignPaymentTreasury */ diff --git a/src/utils/BasePaymentTreasury.sol b/src/utils/BasePaymentTreasury.sol index 28b7f4a6..6124cc85 100644 --- a/src/utils/BasePaymentTreasury.sol +++ b/src/utils/BasePaymentTreasury.sol @@ -9,6 +9,7 @@ import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol import {ICampaignPaymentTreasury} from "../interfaces/ICampaignPaymentTreasury.sol"; import {CampaignAccessChecker} from "./CampaignAccessChecker.sol"; import {PausableCancellable} from "./PausableCancellable.sol"; +import {DataRegistryKeys} from "../constants/DataRegistryKeys.sol"; abstract contract BasePaymentTreasury is Initializable, @@ -42,6 +43,7 @@ abstract contract BasePaymentTreasury is * @param expiration The timestamp after which the payment expires. * @param isConfirmed Boolean indicating whether the payment has been confirmed. * @param isCryptoPayment Boolean indicating whether the payment is made using direct crypto payment. + * @param lineItemCount The number of line items associated with this payment. */ struct PaymentInfo { address buyerAddress; @@ -51,15 +53,28 @@ abstract contract BasePaymentTreasury is uint256 expiration; bool isConfirmed; bool isCryptoPayment; + uint256 lineItemCount; } mapping (bytes32 => PaymentInfo) internal s_payment; + // Combined line items with their configuration snapshots per payment ID + mapping (bytes32 => ICampaignPaymentTreasury.PaymentLineItem[]) internal s_paymentLineItems; // paymentId => array of stored line items + + // External fees per payment ID + mapping (bytes32 => ICampaignPaymentTreasury.ExternalFees[]) internal s_paymentExternalFees; // paymentId => array of external fees + // Multi-token balances (all in token's native decimals) mapping(address => uint256) internal s_pendingPaymentPerToken; // Pending payment amounts per token mapping(address => uint256) internal s_confirmedPaymentPerToken; // Confirmed payment amounts per token (decreases on refunds) mapping(address => uint256) internal s_lifetimeConfirmedPaymentPerToken; // Lifetime confirmed payment amounts per token (never decreases) mapping(address => uint256) internal s_availableConfirmedPerToken; // Available confirmed amounts per token + + // Tracking for non-goal line items (countTowardsGoal = False) per token + mapping(address => uint256) internal s_nonGoalLineItemPendingPerToken; // Pending non-goal line items per token + mapping(address => uint256) internal s_nonGoalLineItemConfirmedPerToken; // Confirmed non-goal line items per token + mapping(address => uint256) internal s_nonGoalLineItemClaimablePerToken; // Claimable non-goal line items per token (after fees) + mapping(address => uint256) internal s_refundableNonGoalLineItemPerToken; // Refundable non-goal line items per token (after fees) /** * @dev Emitted when a new payment is created. @@ -140,6 +155,22 @@ abstract contract BasePaymentTreasury is */ event RefundClaimed(bytes32 indexed paymentId, uint256 refundAmount, address indexed claimer); + /** + * @dev Emitted when non-goal line items are claimed by the platform admin. + * @param token The token that was claimed. + * @param amount The amount claimed. + * @param platformAdmin The address of the platform admin who claimed. + */ + event NonGoalLineItemsClaimed(address indexed token, uint256 amount, address indexed platformAdmin); + + /** + * @dev Emitted when expired funds are claimed by the platform and protocol admins. + * @param token The token that was claimed. + * @param platformAmount The amount sent to the platform admin. + * @param protocolAmount The amount sent to the protocol admin. + */ + event ExpiredFundsClaimed(address indexed token, uint256 platformAmount, uint256 protocolAmount); + /** * @dev Reverts when one or more provided inputs to the payment treasury are invalid. */ @@ -220,6 +251,55 @@ abstract contract BasePaymentTreasury is */ error PaymentTreasuryInsufficientBalance(uint256 required, uint256 available); + /** + * @dev Throws an error indicating that the payment expiration exceeds the maximum allowed expiration time. + * @param expiration The requested expiration timestamp. + * @param maxExpiration The maximum allowed expiration timestamp. + */ + error PaymentTreasuryExpirationExceedsMax(uint256 expiration, uint256 maxExpiration); + + /** + * @dev Throws when attempting to claim expired funds before the claim window opens. + * @param claimableAt The timestamp when the claim window opens. + */ + error PaymentTreasuryClaimWindowNotReached(uint256 claimableAt); + + /** + * @dev Throws when there are no funds available to claim. + */ + error PaymentTreasuryNoFundsToClaim(); + + /** + * @dev Retrieves the max expiration duration configured for the current platform or globally. + * @return hasLimit Indicates whether a max expiration duration is configured. + * @return duration The max expiration duration in seconds. + */ + function _getMaxExpirationDuration() internal view returns (bool hasLimit, uint256 duration) { + bytes32 platformScopedKey = DataRegistryKeys.scopedToPlatform( + DataRegistryKeys.MAX_PAYMENT_EXPIRATION, + PLATFORM_HASH + ); + + // Prefer platform-specific value stored in GlobalParams via registry. + bytes32 maxExpirationBytes = INFO.getDataFromRegistry(platformScopedKey); + + if (maxExpirationBytes == ZERO_BYTES) { + maxExpirationBytes = INFO.getDataFromRegistry(DataRegistryKeys.MAX_PAYMENT_EXPIRATION); + } + + if (maxExpirationBytes == ZERO_BYTES) { + return (false, 0); + } + + duration = uint256(maxExpirationBytes); + + if (duration == 0) { + return (false, 0); + } + + hasLimit = true; + } + function __BaseContract_init( bytes32 platformHash, address infoAddress @@ -369,6 +449,71 @@ abstract contract BasePaymentTreasury is } } + /** + * @dev Struct to hold line item calculation totals to reduce stack depth. + */ + struct LineItemTotals { + uint256 totalGoalLineItemAmount; + uint256 totalProtocolFeeFromLineItems; + uint256 totalNonGoalClaimableAmount; + uint256 totalNonGoalRefundableAmount; + uint256 totalInstantTransferAmountForCheck; + uint256 totalInstantTransferAmount; + } + + /** + * @dev Validates, stores, and tracks line items in a single loop for gas efficiency. + * @param paymentId The payment ID to store line items for. + * @param lineItems Array of line items to validate, store, and track. + * @param paymentToken The token used for the payment. + */ + function _validateStoreAndTrackLineItems( + bytes32 paymentId, + ICampaignPaymentTreasury.LineItem[] calldata lineItems, + address paymentToken + ) internal { + for (uint256 i = 0; i < lineItems.length; i++) { + ICampaignPaymentTreasury.LineItem calldata item = lineItems[i]; + + // Validate line item + if (item.typeId == ZERO_BYTES || item.amount == 0) { + revert PaymentTreasuryInvalidInput(); + } + + // Get line item type configuration (single call per item) + ( + bool exists, + string memory label, + bool countsTowardGoal, + bool applyProtocolFee, + bool canRefund, + bool instantTransfer + ) = INFO.getLineItemType(PLATFORM_HASH, item.typeId); + + if (!exists) { + revert PaymentTreasuryInvalidInput(); + } + + // Store line item with configuration snapshot + s_paymentLineItems[paymentId].push(ICampaignPaymentTreasury.PaymentLineItem({ + typeId: item.typeId, + amount: item.amount, + label: label, + countsTowardGoal: countsTowardGoal, + applyProtocolFee: applyProtocolFee, + canRefund: canRefund, + instantTransfer: instantTransfer + })); + + // Track pending amounts based on whether it counts toward goal + if (countsTowardGoal) { + s_pendingPaymentPerToken[paymentToken] += item.amount; + } else { + s_nonGoalLineItemPendingPerToken[paymentToken] += item.amount; + } + } + } + /** * @inheritdoc ICampaignPaymentTreasury */ @@ -378,7 +523,9 @@ abstract contract BasePaymentTreasury is bytes32 itemId, address paymentToken, uint256 amount, - uint256 expiration + uint256 expiration, + ICampaignPaymentTreasury.LineItem[] calldata lineItems, + ICampaignPaymentTreasury.ExternalFees[] calldata externalFees ) public override virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { if(buyerId == ZERO_BYTES || @@ -391,6 +538,15 @@ abstract contract BasePaymentTreasury is revert PaymentTreasuryInvalidInput(); } + // Validate expiration does not exceed maximum allowed expiration time (platform-specific or global) + (bool hasMaxExpiration, uint256 maxExpirationDuration) = _getMaxExpirationDuration(); + if (hasMaxExpiration) { + uint256 maxAllowedExpiration = block.timestamp + maxExpirationDuration; + if (expiration > maxAllowedExpiration) { + revert PaymentTreasuryExpirationExceedsMax(expiration, maxAllowedExpiration); + } + } + // Validate token is accepted if (!INFO.isTokenAccepted(paymentToken)) { revert PaymentTreasuryTokenNotAccepted(paymentToken); @@ -407,9 +563,22 @@ abstract contract BasePaymentTreasury is amount: amount, // Amount in token's native decimals expiration: expiration, isConfirmed: false, - isCryptoPayment: false + isCryptoPayment: false, + lineItemCount: lineItems.length }); + // Validate, store, and track line items + _validateStoreAndTrackLineItems(paymentId, lineItems, paymentToken); + + // Store external fees + ICampaignPaymentTreasury.ExternalFees[] storage storedExternalFees = s_paymentExternalFees[paymentId]; + for (uint256 i = 0; i < externalFees.length; ) { + storedExternalFees.push(externalFees[i]); + unchecked { + ++i; + } + } + s_paymentIdToToken[paymentId] = paymentToken; s_pendingPaymentPerToken[paymentToken] += amount; @@ -434,7 +603,9 @@ abstract contract BasePaymentTreasury is bytes32[] calldata itemIds, address[] calldata paymentTokens, uint256[] calldata amounts, - uint256[] calldata expirations + uint256[] calldata expirations, + ICampaignPaymentTreasury.LineItem[][] calldata lineItemsArray, + ICampaignPaymentTreasury.ExternalFees[][] calldata externalFeesArray ) public override virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { // Validate array lengths are consistent @@ -444,10 +615,19 @@ abstract contract BasePaymentTreasury is length != itemIds.length || length != paymentTokens.length || length != amounts.length || - length != expirations.length) { + length != expirations.length || + length != lineItemsArray.length || + length != externalFeesArray.length) { revert PaymentTreasuryInvalidInput(); } + // Get max expiration duration once outside the loop for efficiency (platform-specific or global) + (bool hasMaxExpiration, uint256 maxExpirationDuration) = _getMaxExpirationDuration(); + uint256 maxAllowedExpiration = 0; + if (hasMaxExpiration) { + maxAllowedExpiration = block.timestamp + maxExpirationDuration; + } + // Process each payment in the batch for (uint256 i = 0; i < length;) { bytes32 paymentId = paymentIds[i]; @@ -456,6 +636,7 @@ abstract contract BasePaymentTreasury is address paymentToken = paymentTokens[i]; uint256 amount = amounts[i]; uint256 expiration = expirations[i]; + ICampaignPaymentTreasury.LineItem[] calldata lineItems = lineItemsArray[i]; // Validate individual payment parameters if(buyerId == ZERO_BYTES || @@ -468,6 +649,11 @@ abstract contract BasePaymentTreasury is revert PaymentTreasuryInvalidInput(); } + // Validate expiration does not exceed maximum allowed expiration time + if (hasMaxExpiration && expiration > maxAllowedExpiration) { + revert PaymentTreasuryExpirationExceedsMax(expiration, maxAllowedExpiration); + } + // Validate token is accepted if (!INFO.isTokenAccepted(paymentToken)) { revert PaymentTreasuryTokenNotAccepted(paymentToken); @@ -486,9 +672,23 @@ abstract contract BasePaymentTreasury is amount: amount, // Amount in token's native decimals expiration: expiration, isConfirmed: false, - isCryptoPayment: false + isCryptoPayment: false, + lineItemCount: lineItems.length }); + // Validate, store, and track line items in a single loop + _validateStoreAndTrackLineItems(paymentId, lineItems, paymentToken); + + // Store external fees + ICampaignPaymentTreasury.ExternalFees[] calldata externalFees = externalFeesArray[i]; + ICampaignPaymentTreasury.ExternalFees[] storage storedExternalFees = s_paymentExternalFees[paymentId]; + for (uint256 j = 0; j < externalFees.length; ) { + storedExternalFees.push(externalFees[j]); + unchecked { + ++j; + } + } + s_paymentIdToToken[paymentId] = paymentToken; s_pendingPaymentPerToken[paymentToken] += amount; @@ -519,7 +719,9 @@ abstract contract BasePaymentTreasury is bytes32 itemId, address buyerAddress, address paymentToken, - uint256 amount + uint256 amount, + ICampaignPaymentTreasury.LineItem[] calldata lineItems, + ICampaignPaymentTreasury.ExternalFees[] calldata externalFees ) public override virtual nonReentrant whenCampaignNotPaused whenCampaignNotCancelled { if(buyerAddress == address(0) || @@ -540,7 +742,90 @@ abstract contract BasePaymentTreasury is revert PaymentTreasuryPaymentAlreadyExist(paymentId); } - IERC20(paymentToken).safeTransferFrom(buyerAddress, address(this), amount); + // Validate, calculate total, store, and process line items + uint256 totalAmount = amount; + address platformAdmin = INFO.getPlatformAdminAddress(PLATFORM_HASH); + uint256 protocolFeePercent = INFO.getProtocolFeePercent(); + uint256 totalInstantTransferAmount = 0; + + for (uint256 i = 0; i < lineItems.length; i++) { + ICampaignPaymentTreasury.LineItem calldata item = lineItems[i]; + + // Validate line item + if (item.typeId == ZERO_BYTES || item.amount == 0) { + revert PaymentTreasuryInvalidInput(); + } + + // Get line item type configuration (single call per item) + ( + bool exists, + string memory label, + bool countsTowardGoal, + bool applyProtocolFee, + bool canRefund, + bool instantTransfer + ) = INFO.getLineItemType(PLATFORM_HASH, item.typeId); + + if (!exists) { + revert PaymentTreasuryInvalidInput(); + } + + // Accumulate total amount + totalAmount += item.amount; + + // Store line item with configuration snapshot + s_paymentLineItems[paymentId].push(ICampaignPaymentTreasury.PaymentLineItem({ + typeId: item.typeId, + amount: item.amount, + label: label, + countsTowardGoal: countsTowardGoal, + applyProtocolFee: applyProtocolFee, + canRefund: canRefund, + instantTransfer: instantTransfer + })); + + // Process line items immediately since crypto payment is confirmed + if (countsTowardGoal) { + // Line items that count toward goal use existing tracking variables + s_confirmedPaymentPerToken[paymentToken] += item.amount; + s_lifetimeConfirmedPaymentPerToken[paymentToken] += item.amount; + s_availableConfirmedPerToken[paymentToken] += item.amount; + } else { + // Apply protocol fee if applicable + uint256 feeAmount = 0; + if (applyProtocolFee) { + uint256 protocolFee = (item.amount * protocolFeePercent) / PERCENT_DIVIDER; + feeAmount += protocolFee; + s_protocolFeePerToken[paymentToken] += protocolFee; + } + uint256 netAmount = item.amount - feeAmount; + + if (instantTransfer) { + // Accumulate for batch transfer after loop + totalInstantTransferAmount += netAmount; + } else { + // Track outstanding non-goal balances using net amounts (after fees) + s_nonGoalLineItemConfirmedPerToken[paymentToken] += netAmount; + + if (canRefund) { + s_refundableNonGoalLineItemPerToken[paymentToken] += netAmount; + } else { + s_nonGoalLineItemClaimablePerToken[paymentToken] += netAmount; + } + } + } + } + + // Store external fees + ICampaignPaymentTreasury.ExternalFees[] storage storedExternalFees = s_paymentExternalFees[paymentId]; + for (uint256 i = 0; i < externalFees.length; ) { + storedExternalFees.push(externalFees[i]); + unchecked { + ++i; + } + } + + IERC20(paymentToken).safeTransferFrom(buyerAddress, address(this), totalAmount); s_payment[paymentId] = PaymentInfo({ buyerId: ZERO_BYTES, @@ -549,7 +834,8 @@ abstract contract BasePaymentTreasury is amount: amount, // Amount in token's native decimals expiration: 0, isConfirmed: true, - isCryptoPayment: true + isCryptoPayment: true, + lineItemCount: lineItems.length }); s_paymentIdToToken[paymentId] = paymentToken; @@ -557,6 +843,10 @@ abstract contract BasePaymentTreasury is s_lifetimeConfirmedPaymentPerToken[paymentToken] += amount; s_availableConfirmedPerToken[paymentToken] += amount; + // Perform single batch transfer if there are any instant transfer amounts + if (totalInstantTransferAmount > 0) { + IERC20(paymentToken).safeTransfer(platformAdmin, totalInstantTransferAmount); + } // Mint NFT for crypto payment uint256 tokenId = INFO.mintNFTForPledge( buyerAddress, @@ -591,16 +881,156 @@ abstract contract BasePaymentTreasury is address paymentToken = s_paymentIdToToken[paymentId]; uint256 amount = s_payment[paymentId].amount; + ICampaignPaymentTreasury.PaymentLineItem[] storage lineItems = s_paymentLineItems[paymentId]; + + // Remove pending tracking for line items using snapshot from payment creation + // This prevents issues if line item type configuration changed after payment creation + for (uint256 i = 0; i < lineItems.length; i++) { + // Use snapshot instead of current configuration to ensure consistency + if (lineItems[i].countsTowardGoal) { + s_pendingPaymentPerToken[paymentToken] -= lineItems[i].amount; + } else { + s_nonGoalLineItemPendingPerToken[paymentToken] -= lineItems[i].amount; + } + } delete s_payment[paymentId]; delete s_paymentIdToToken[paymentId]; - delete s_paymentIdToTokenId[paymentId]; + delete s_paymentLineItems[paymentId]; + delete s_paymentExternalFees[paymentId]; s_pendingPaymentPerToken[paymentToken] -= amount; emit PaymentCancelled(paymentId); } + /** + * @dev Calculates line item totals for balance checking and state updates. + * @param lineItems Array of line items to process. + * @param protocolFeePercent Protocol fee percentage. + * @return totals Struct containing all calculated totals. + */ + function _calculateLineItemTotals( + ICampaignPaymentTreasury.PaymentLineItem[] storage lineItems, + uint256 protocolFeePercent + ) internal view returns (LineItemTotals memory totals) { + for (uint256 i = 0; i < lineItems.length; i++) { + ICampaignPaymentTreasury.PaymentLineItem memory item = lineItems[i]; + + bool countsTowardGoal = item.countsTowardGoal; + bool applyProtocolFee = item.applyProtocolFee; + bool instantTransfer = item.instantTransfer; + + if (countsTowardGoal) { + totals.totalGoalLineItemAmount += item.amount; + } else { + uint256 feeAmount = 0; + if (applyProtocolFee) { + uint256 protocolFee = (item.amount * protocolFeePercent) / PERCENT_DIVIDER; + totals.totalProtocolFeeFromLineItems += protocolFee; + feeAmount += protocolFee; + } + + uint256 netAmount = item.amount - feeAmount; + + if (instantTransfer) { + totals.totalInstantTransferAmountForCheck += netAmount; + } else if (item.canRefund) { + totals.totalNonGoalRefundableAmount += netAmount; + } else { + totals.totalNonGoalClaimableAmount += netAmount; + } + } + } + } + + /** + * @dev Checks if there's sufficient balance for payment confirmation. + * @param paymentToken The token address. + * @param paymentAmount The base payment amount. + * @param totals Line item totals struct. + */ + function _checkBalanceForConfirmation( + address paymentToken, + uint256 paymentAmount, + LineItemTotals memory totals + ) internal view { + uint256 actualBalance = IERC20(paymentToken).balanceOf(address(this)); + uint256 currentlyCommitted = s_availableConfirmedPerToken[paymentToken] + + s_protocolFeePerToken[paymentToken] + + s_platformFeePerToken[paymentToken] + + s_nonGoalLineItemClaimablePerToken[paymentToken] + + s_refundableNonGoalLineItemPerToken[paymentToken]; + + uint256 newCommitted = currentlyCommitted + + paymentAmount + + totals.totalGoalLineItemAmount + + totals.totalProtocolFeeFromLineItems + + totals.totalNonGoalClaimableAmount + + totals.totalNonGoalRefundableAmount; + + if (newCommitted + totals.totalInstantTransferAmountForCheck > actualBalance) { + revert PaymentTreasuryInsufficientBalance( + newCommitted + totals.totalInstantTransferAmountForCheck, + actualBalance + ); + } + } + + /** + * @dev Updates state for line items during payment confirmation. + * @param paymentToken The token address. + * @param lineItems Array of line items to process. + * @param protocolFeePercent Protocol fee percentage. + * @return totalInstantTransferAmount Total amount to transfer instantly. + */ + function _updateLineItemsForConfirmation( + address paymentToken, + ICampaignPaymentTreasury.PaymentLineItem[] storage lineItems, + uint256 protocolFeePercent + ) internal returns (uint256 totalInstantTransferAmount) { + for (uint256 i = 0; i < lineItems.length; i++) { + ICampaignPaymentTreasury.PaymentLineItem memory item = lineItems[i]; + + bool countsTowardGoal = item.countsTowardGoal; + bool applyProtocolFee = item.applyProtocolFee; + bool canRefund = item.canRefund; + bool instantTransfer = item.instantTransfer; + + if (countsTowardGoal) { + s_pendingPaymentPerToken[paymentToken] -= item.amount; + s_confirmedPaymentPerToken[paymentToken] += item.amount; + s_lifetimeConfirmedPaymentPerToken[paymentToken] += item.amount; + s_availableConfirmedPerToken[paymentToken] += item.amount; + } else { + s_nonGoalLineItemPendingPerToken[paymentToken] -= item.amount; + + uint256 feeAmount = 0; + if (applyProtocolFee) { + uint256 protocolFee = (item.amount * protocolFeePercent) / PERCENT_DIVIDER; + feeAmount += protocolFee; + s_protocolFeePerToken[paymentToken] += protocolFee; + } + + uint256 netAmount = item.amount - feeAmount; + + if (instantTransfer) { + totalInstantTransferAmount += netAmount; + // Instant transfer items are not tracked in s_nonGoalLineItemConfirmedPerToken + } else { + // Track outstanding non-goal balances using net amounts (after fees) + s_nonGoalLineItemConfirmedPerToken[paymentToken] += netAmount; + + if (canRefund) { + s_refundableNonGoalLineItemPerToken[paymentToken] += netAmount; + } else { + s_nonGoalLineItemClaimablePerToken[paymentToken] += netAmount; + } + } + } + } + } + /** * @inheritdoc ICampaignPaymentTreasury */ @@ -612,38 +1042,41 @@ abstract contract BasePaymentTreasury is address paymentToken = s_paymentIdToToken[paymentId]; uint256 paymentAmount = s_payment[paymentId].amount; + ICampaignPaymentTreasury.PaymentLineItem[] storage lineItems = s_paymentLineItems[paymentId]; - // Check that we have enough unallocated tokens for this payment - uint256 actualBalance = IERC20(paymentToken).balanceOf(address(this)); - uint256 currentlyCommitted = s_availableConfirmedPerToken[paymentToken] + - s_protocolFeePerToken[paymentToken] + - s_platformFeePerToken[paymentToken]; + uint256 protocolFeePercent = INFO.getProtocolFeePercent(); + LineItemTotals memory totals = _calculateLineItemTotals(lineItems, protocolFeePercent); - if (currentlyCommitted + paymentAmount > actualBalance) { - revert PaymentTreasuryInsufficientBalance( - currentlyCommitted + paymentAmount, - actualBalance - ); - } + _checkBalanceForConfirmation(paymentToken, paymentAmount, totals); + + totals.totalInstantTransferAmount = _updateLineItemsForConfirmation( + paymentToken, + lineItems, + protocolFeePercent + ); s_payment[paymentId].isConfirmed = true; - + s_pendingPaymentPerToken[paymentToken] -= paymentAmount; s_confirmedPaymentPerToken[paymentToken] += paymentAmount; s_lifetimeConfirmedPaymentPerToken[paymentToken] += paymentAmount; s_availableConfirmedPerToken[paymentToken] += paymentAmount; - // Mint NFT if buyerAddress is provided + if (totals.totalInstantTransferAmount > 0) { + address platformAdmin = INFO.getPlatformAdminAddress(PLATFORM_HASH); + IERC20(paymentToken).safeTransfer(platformAdmin, totals.totalInstantTransferAmount); + } + if (buyerAddress != address(0)) { s_payment[paymentId].buyerAddress = buyerAddress; bytes32 itemId = s_payment[paymentId].itemId; uint256 tokenId = INFO.mintNFTForPledge( buyerAddress, - itemId, // Using itemId as the reward identifier + itemId, paymentToken, paymentAmount, - 0, // shippingFee (0 for payment treasuries) - 0 // tipAmount (0 for payment treasuries) + 0, + 0 ); s_paymentIdToTokenId[paymentId] = tokenId; } @@ -667,6 +1100,9 @@ abstract contract BasePaymentTreasury is bytes32 currentPaymentId; address currentToken; + uint256 protocolFeePercent = INFO.getProtocolFeePercent(); + address platformAdmin = INFO.getPlatformAdminAddress(PLATFORM_HASH); + for(uint256 i = 0; i < paymentIds.length;){ currentPaymentId = paymentIds[i]; @@ -674,38 +1110,39 @@ abstract contract BasePaymentTreasury is currentToken = s_paymentIdToToken[currentPaymentId]; uint256 amount = s_payment[currentPaymentId].amount; - uint256 actualBalance = IERC20(currentToken).balanceOf(address(this)); + ICampaignPaymentTreasury.PaymentLineItem[] storage lineItems = s_paymentLineItems[currentPaymentId]; - // Check if this confirmation would exceed balance - uint256 currentlyCommitted = s_availableConfirmedPerToken[currentToken] + - s_protocolFeePerToken[currentToken] + - s_platformFeePerToken[currentToken]; + LineItemTotals memory totals = _calculateLineItemTotals(lineItems, protocolFeePercent); + _checkBalanceForConfirmation(currentToken, amount, totals); - if (currentlyCommitted + amount > actualBalance) { - revert PaymentTreasuryInsufficientBalance( - currentlyCommitted + amount, - actualBalance - ); - } + totals.totalInstantTransferAmount = _updateLineItemsForConfirmation( + currentToken, + lineItems, + protocolFeePercent + ); s_payment[currentPaymentId].isConfirmed = true; + s_pendingPaymentPerToken[currentToken] -= amount; s_confirmedPaymentPerToken[currentToken] += amount; s_lifetimeConfirmedPaymentPerToken[currentToken] += amount; s_availableConfirmedPerToken[currentToken] += amount; + + if (totals.totalInstantTransferAmount > 0) { + IERC20(currentToken).safeTransfer(platformAdmin, totals.totalInstantTransferAmount); + } - // Mint NFT if buyer address provided for this payment if (buyerAddresses[i] != address(0)) { address buyerAddress = buyerAddresses[i]; s_payment[currentPaymentId].buyerAddress = buyerAddress; bytes32 itemId = s_payment[currentPaymentId].itemId; uint256 tokenId = INFO.mintNFTForPledge( buyerAddress, - itemId, // Using itemId as the reward identifier + itemId, currentToken, amount, - 0, // shippingFee (0 for payment treasuries) - 0 // tipAmount (0 for payment treasuries) + 0, + 0 ); s_paymentIdToTokenId[currentPaymentId] = tokenId; } @@ -750,14 +1187,118 @@ abstract contract BasePaymentTreasury is revert PaymentTreasuryCryptoPayment(paymentId); } + // Use snapshots of line item type configuration from payment creation time + // This prevents issues if line item type configuration changed after payment creation/confirmation + ICampaignPaymentTreasury.PaymentLineItem[] storage lineItems = s_paymentLineItems[paymentId]; + uint256 protocolFeePercent = INFO.getProtocolFeePercent(); + + // Calculate total line item refund amount using snapshots + uint256 totalGoalLineItemRefundAmount = 0; + uint256 totalNonGoalLineItemRefundAmount = 0; + + for (uint256 i = 0; i < lineItems.length; i++) { + ICampaignPaymentTreasury.PaymentLineItem memory item = lineItems[i]; + + // Use snapshot flags instead of current configuration + if (!item.canRefund) { + continue; // Skip non-refundable line items (based on snapshot at creation time) + } + + if (item.countsTowardGoal) { + // Goal line items: full amount is refundable from goal tracking + totalGoalLineItemRefundAmount += item.amount; + } else { + // Non-goal line items: handle fees and instant transfers + // For instant transfer items, the net amount was already sent to platform admin - don't refund + // For non-instant items, only refund the net amount (after fees), not the fees themselves + if (item.instantTransfer) { + // Skip instant transfer items - they were already sent to platform admin + continue; + } + + uint256 feeAmount = 0; + if (item.applyProtocolFee) { + feeAmount = (item.amount * protocolFeePercent) / PERCENT_DIVIDER; + } + uint256 netAmount = item.amount - feeAmount; + + // Only refund the net amount (fees are not refundable) + totalNonGoalLineItemRefundAmount += netAmount; + } + } + + // Check that we have enough available balance for the total refund (BEFORE modifying state) + // Goal line items are in availableConfirmedPerToken, non-goal items need separate check + uint256 totalRefundAmount = amountToRefund + totalGoalLineItemRefundAmount + totalNonGoalLineItemRefundAmount; + + // For goal line items and base payment, check availableConfirmedPerToken + if (availablePaymentAmount < (amountToRefund + totalGoalLineItemRefundAmount)) { + revert PaymentTreasuryPaymentNotClaimable(paymentId); + } + + // For non-goal line items, check that we have enough claimable balance + // (only non-instant transfer items are refundable, and only their net amounts after fees) + if (totalNonGoalLineItemRefundAmount > 0) { + uint256 availableRefundable = s_refundableNonGoalLineItemPerToken[paymentToken]; + if (availableRefundable < totalNonGoalLineItemRefundAmount) { + revert PaymentTreasuryPaymentNotClaimable(paymentId); + } + } + + // Check that contract has enough actual balance to perform the transfer + uint256 contractBalance = IERC20(paymentToken).balanceOf(address(this)); + if (contractBalance < totalRefundAmount) { + revert PaymentTreasuryPaymentNotClaimable(paymentId); + } + + // Update state: remove tracking for refundable line items using snapshots + for (uint256 i = 0; i < lineItems.length; i++) { + ICampaignPaymentTreasury.PaymentLineItem memory item = lineItems[i]; + + // Use snapshot flags instead of current configuration + if (!item.canRefund) { + continue; // Skip non-refundable line items (based on snapshot at creation time) + } + + if (item.countsTowardGoal) { + // Goal line items: remove from goal tracking + s_confirmedPaymentPerToken[paymentToken] -= item.amount; + s_availableConfirmedPerToken[paymentToken] -= item.amount; + } else { + // Non-goal line items: remove from non-goal tracking + // Note: instantTransfer items are skipped in the refund calculation above + if (item.instantTransfer) { + // Instant transfer items were already sent to platform admin; nothing tracked + continue; + } + + // Calculate fees and net amount using snapshot + uint256 feeAmount = 0; + if (item.applyProtocolFee) { + feeAmount = (item.amount * protocolFeePercent) / PERCENT_DIVIDER; + // Fees are NOT refunded - they remain in the protocol fee pool + } + + uint256 netAmount = item.amount - feeAmount; + + // Remove net amount from outstanding non-goal tracking + s_nonGoalLineItemConfirmedPerToken[paymentToken] -= netAmount; + + // Remove from refundable tracking (only net amount is refundable) + s_refundableNonGoalLineItemPerToken[paymentToken] -= netAmount; + } + } + delete s_payment[paymentId]; delete s_paymentIdToToken[paymentId]; + delete s_paymentLineItems[paymentId]; + delete s_paymentExternalFees[paymentId]; s_confirmedPaymentPerToken[paymentToken] -= amountToRefund; s_availableConfirmedPerToken[paymentToken] -= amountToRefund; - IERC20(paymentToken).safeTransfer(refundAddress, amountToRefund); - emit RefundClaimed(paymentId, amountToRefund, refundAddress); + IERC20(paymentToken).safeTransfer(refundAddress, totalRefundAmount); + emit RefundClaimed(paymentId, totalRefundAmount, refundAddress); } /** @@ -789,8 +1330,112 @@ abstract contract BasePaymentTreasury is // Get NFT owner before burning address nftOwner = INFO.ownerOf(tokenId); + // Use snapshots of line item type configuration from payment creation time + // This prevents issues if line item type configuration changed after payment creation/confirmation + ICampaignPaymentTreasury.PaymentLineItem[] storage lineItems = s_paymentLineItems[paymentId]; + uint256 protocolFeePercent = INFO.getProtocolFeePercent(); + + // Calculate total line item refund amount using snapshots + uint256 totalGoalLineItemRefundAmount = 0; + uint256 totalNonGoalLineItemRefundAmount = 0; + + for (uint256 i = 0; i < lineItems.length; i++) { + ICampaignPaymentTreasury.PaymentLineItem memory item = lineItems[i]; + + // Use snapshot flags instead of current configuration + if (!item.canRefund) { + continue; // Skip non-refundable line items (based on snapshot at creation time) + } + + if (item.countsTowardGoal) { + // Goal line items: full amount is refundable from goal tracking + totalGoalLineItemRefundAmount += item.amount; + } else { + // Non-goal line items: handle fees and instant transfers + // For instant transfer items, the net amount was already sent to platform admin - don't refund + // For non-instant items, only refund the net amount (after fees), not the fees themselves + if (item.instantTransfer) { + // Skip instant transfer items - they were already sent to platform admin + continue; + } + + uint256 feeAmount = 0; + if (item.applyProtocolFee) { + feeAmount = (item.amount * protocolFeePercent) / PERCENT_DIVIDER; + } + uint256 netAmount = item.amount - feeAmount; + + // Only refund the net amount (fees are not refundable) + totalNonGoalLineItemRefundAmount += netAmount; + } + } + + // Check that we have enough available balance for the total refund (BEFORE modifying state) + // Goal line items are in availableConfirmedPerToken, non-goal items need separate check + uint256 totalRefundAmount = amountToRefund + totalGoalLineItemRefundAmount + totalNonGoalLineItemRefundAmount; + + // For goal line items and base payment, check availableConfirmedPerToken + if (availablePaymentAmount < (amountToRefund + totalGoalLineItemRefundAmount)) { + revert PaymentTreasuryPaymentNotClaimable(paymentId); + } + + // For non-goal line items, check that we have enough claimable balance + // (only non-instant transfer items are refundable, and only their net amounts after fees) + if (totalNonGoalLineItemRefundAmount > 0) { + uint256 availableRefundable = s_refundableNonGoalLineItemPerToken[paymentToken]; + if (availableRefundable < totalNonGoalLineItemRefundAmount) { + revert PaymentTreasuryPaymentNotClaimable(paymentId); + } + } + + // Check that contract has enough actual balance to perform the transfer + uint256 contractBalance = IERC20(paymentToken).balanceOf(address(this)); + if (contractBalance < totalRefundAmount) { + revert PaymentTreasuryPaymentNotClaimable(paymentId); + } + + // Update state: remove tracking for refundable line items using snapshots + for (uint256 i = 0; i < lineItems.length; i++) { + ICampaignPaymentTreasury.PaymentLineItem memory item = lineItems[i]; + + // Use snapshot flags instead of current configuration + if (!item.canRefund) { + continue; // Skip non-refundable line items (based on snapshot at creation time) + } + + if (item.countsTowardGoal) { + // Goal line items: remove from goal tracking + s_confirmedPaymentPerToken[paymentToken] -= item.amount; + s_availableConfirmedPerToken[paymentToken] -= item.amount; + } else { + // Non-goal line items: remove from non-goal tracking + // Note: instantTransfer items are skipped in the refund calculation above + if (item.instantTransfer) { + // Instant transfer items were already sent to platform admin; nothing tracked + continue; + } + + // Calculate fees and net amount using snapshot + uint256 feeAmount = 0; + if (item.applyProtocolFee) { + feeAmount = (item.amount * protocolFeePercent) / PERCENT_DIVIDER; + // Fees are NOT refunded - they remain in the protocol fee pool + } + + uint256 netAmount = item.amount - feeAmount; + + // Remove net amount from outstanding non-goal tracking + s_nonGoalLineItemConfirmedPerToken[paymentToken] -= netAmount; + + // Remove from refundable tracking (only net amount is refundable) + s_refundableNonGoalLineItemPerToken[paymentToken] -= netAmount; + } + } + delete s_payment[paymentId]; delete s_paymentIdToToken[paymentId]; + delete s_paymentLineItems[paymentId]; + delete s_paymentExternalFees[paymentId]; delete s_paymentIdToTokenId[paymentId]; s_confirmedPaymentPerToken[paymentToken] -= amountToRefund; @@ -799,8 +1444,8 @@ abstract contract BasePaymentTreasury is // Burn NFT (requires treasury approval from owner) INFO.burn(tokenId); - IERC20(paymentToken).safeTransfer(nftOwner, amountToRefund); - emit RefundClaimed(paymentId, amountToRefund, nftOwner); + IERC20(paymentToken).safeTransfer(nftOwner, totalRefundAmount); + emit RefundClaimed(paymentId, totalRefundAmount, nftOwner); } /** @@ -839,6 +1484,123 @@ abstract contract BasePaymentTreasury is } } + /** + * @notice Allows platform admin to claim non-goal line items that are available for claiming. + * @param token The token address to claim. + */ + function claimNonGoalLineItems(address token) + public + virtual + onlyPlatformAdmin(PLATFORM_HASH) + whenCampaignNotPaused + whenCampaignNotCancelled + { + if (!INFO.isTokenAccepted(token)) { + revert PaymentTreasuryTokenNotAccepted(token); + } + + uint256 claimableAmount = s_nonGoalLineItemClaimablePerToken[token]; + if (claimableAmount == 0) { + revert PaymentTreasuryInvalidInput(); + } + + s_nonGoalLineItemClaimablePerToken[token] = 0; + uint256 currentNonGoalConfirmed = s_nonGoalLineItemConfirmedPerToken[token]; + s_nonGoalLineItemConfirmedPerToken[token] = currentNonGoalConfirmed > claimableAmount + ? currentNonGoalConfirmed - claimableAmount + : 0; + address platformAdmin = INFO.getPlatformAdminAddress(PLATFORM_HASH); + + IERC20(token).safeTransfer(platformAdmin, claimableAmount); + + emit NonGoalLineItemsClaimed(token, claimableAmount, platformAdmin); + } + + /** + * @notice Allows the platform admin to claim all remaining funds once the claim window has opened. + */ + function claimExpiredFunds() + public + virtual + onlyPlatformAdmin(PLATFORM_HASH) + whenCampaignNotPaused + whenCampaignNotCancelled + { + uint256 claimDelay = INFO.getPlatformClaimDelay(PLATFORM_HASH); + uint256 claimableAt = INFO.getDeadline(); + claimableAt += claimDelay; + + if (block.timestamp < claimableAt) { + revert PaymentTreasuryClaimWindowNotReached(claimableAt); + } + + address[] memory acceptedTokens = INFO.getAcceptedTokens(); + address platformAdmin = INFO.getPlatformAdminAddress(PLATFORM_HASH); + address protocolAdmin = INFO.getProtocolAdminAddress(); + + bool claimedAny; + + for (uint256 i = 0; i < acceptedTokens.length; i++) { + address token = acceptedTokens[i]; + + uint256 availableConfirmed = s_availableConfirmedPerToken[token]; + uint256 claimableAmount = s_nonGoalLineItemClaimablePerToken[token]; + uint256 refundableAmount = s_refundableNonGoalLineItemPerToken[token]; + uint256 platformFeeAmount = s_platformFeePerToken[token]; + uint256 protocolFeeAmount = s_protocolFeePerToken[token]; + + uint256 platformAmount = availableConfirmed + claimableAmount + refundableAmount + platformFeeAmount; + uint256 protocolAmount = protocolFeeAmount; + + if (platformAmount == 0 && protocolAmount == 0) { + continue; + } + + if (availableConfirmed > 0) { + uint256 currentConfirmed = s_confirmedPaymentPerToken[token]; + s_confirmedPaymentPerToken[token] = currentConfirmed > availableConfirmed + ? currentConfirmed - availableConfirmed + : 0; + s_availableConfirmedPerToken[token] = 0; + } + + if (claimableAmount > 0 || refundableAmount > 0) { + uint256 reduction = claimableAmount + refundableAmount; + uint256 currentNonGoalConfirmed = s_nonGoalLineItemConfirmedPerToken[token]; + s_nonGoalLineItemConfirmedPerToken[token] = currentNonGoalConfirmed > reduction + ? currentNonGoalConfirmed - reduction + : 0; + s_nonGoalLineItemClaimablePerToken[token] = 0; + s_refundableNonGoalLineItemPerToken[token] = 0; + } + + if (platformFeeAmount > 0) { + s_platformFeePerToken[token] = 0; + } + + if (protocolFeeAmount > 0) { + s_protocolFeePerToken[token] = 0; + } + + // transfer funds after state has been cleared + if (platformAmount > 0) { + IERC20(token).safeTransfer(platformAdmin, platformAmount); + claimedAny = true; + } + + if (protocolAmount > 0) { + IERC20(token).safeTransfer(protocolAdmin, protocolAmount); + claimedAny = true; + } + + emit ExpiredFundsClaimed(token, platformAmount, protocolAmount); + } + + if (!claimedAny) { + revert PaymentTreasuryNoFundsToClaim(); + } + } + /** * @inheritdoc ICampaignPaymentTreasury */ @@ -975,6 +1737,42 @@ abstract contract BasePaymentTreasury is } } + /** + * @inheritdoc ICampaignPaymentTreasury + */ + function getPaymentData(bytes32 paymentId) public view override returns (ICampaignPaymentTreasury.PaymentData memory) { + PaymentInfo memory payment = s_payment[paymentId]; + address paymentToken = s_paymentIdToToken[paymentId]; + ICampaignPaymentTreasury.PaymentLineItem[] storage lineItemsStorage = s_paymentLineItems[paymentId]; + ICampaignPaymentTreasury.ExternalFees[] storage externalFeesStorage = s_paymentExternalFees[paymentId]; + + // Copy line items from storage to memory (required: cannot directly assign storage array to memory array) + ICampaignPaymentTreasury.PaymentLineItem[] memory lineItems = new ICampaignPaymentTreasury.PaymentLineItem[](lineItemsStorage.length); + for (uint256 i = 0; i < lineItemsStorage.length; i++) { + lineItems[i] = lineItemsStorage[i]; + } + + // Copy external fees from storage to memory (same reason as line items) + ICampaignPaymentTreasury.ExternalFees[] memory externalFees = new ICampaignPaymentTreasury.ExternalFees[](externalFeesStorage.length); + for (uint256 i = 0; i < externalFeesStorage.length; i++) { + externalFees[i] = externalFeesStorage[i]; + } + + return ICampaignPaymentTreasury.PaymentData({ + buyerAddress: payment.buyerAddress, + buyerId: payment.buyerId, + itemId: payment.itemId, + amount: payment.amount, + expiration: payment.expiration, + isConfirmed: payment.isConfirmed, + isCryptoPayment: payment.isCryptoPayment, + lineItemCount: payment.lineItemCount, + paymentToken: paymentToken, + lineItems: lineItems, + externalFees: externalFees + }); + } + /** * @dev Internal function to check the success condition for fee disbursement. * @return Whether the success condition is met. diff --git a/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol b/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol index 0316699d..431c6459 100644 --- a/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol +++ b/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol @@ -149,10 +149,12 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te bytes32 itemId, address paymentToken, uint256 amount, - uint256 expiration + uint256 expiration, + ICampaignPaymentTreasury.LineItem[] memory lineItems, + ICampaignPaymentTreasury.ExternalFees[] memory externalFees ) internal { vm.prank(caller); - paymentTreasury.createPayment(paymentId, buyerId, itemId, paymentToken, amount, expiration); + paymentTreasury.createPayment(paymentId, buyerId, itemId, paymentToken, amount, expiration, lineItems, externalFees); } /** @@ -164,10 +166,12 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te bytes32 itemId, address buyerAddress, address paymentToken, - uint256 amount + uint256 amount, + ICampaignPaymentTreasury.LineItem[] memory lineItems, + ICampaignPaymentTreasury.ExternalFees[] memory externalFees ) internal { vm.prank(caller); - paymentTreasury.processCryptoPayment(paymentId, itemId, buyerAddress, paymentToken, amount); + paymentTreasury.processCryptoPayment(paymentId, itemId, buyerAddress, paymentToken, amount, lineItems, externalFees); } /** @@ -330,7 +334,9 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te // Create payment with token specified uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; - createPayment(users.platform1AdminAddress, paymentId, buyerId, itemId, address(testToken), amount, expiration); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); + ICampaignPaymentTreasury.ExternalFees[] memory emptyExternalFees = new ICampaignPaymentTreasury.ExternalFees[](0); + createPayment(users.platform1AdminAddress, paymentId, buyerId, itemId, address(testToken), amount, expiration, emptyLineItems, emptyExternalFees); // Transfer tokens from buyer to treasury vm.prank(buyerAddress); @@ -354,7 +360,8 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te testToken.approve(treasuryAddress, amount); // Process crypto payment - processCryptoPayment(buyerAddress, paymentId, itemId, buyerAddress, address(testToken), amount); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); + processCryptoPayment(buyerAddress, paymentId, itemId, buyerAddress, address(testToken), amount, emptyLineItems, new ICampaignPaymentTreasury.ExternalFees[](0)); } /** @@ -385,7 +392,9 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te // Create payment with token specified uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; - createPayment(users.platform1AdminAddress, paymentId, buyerId, itemId, token, amount, expiration); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); + ICampaignPaymentTreasury.ExternalFees[] memory emptyExternalFees = new ICampaignPaymentTreasury.ExternalFees[](0); + createPayment(users.platform1AdminAddress, paymentId, buyerId, itemId, token, amount, expiration, emptyLineItems, emptyExternalFees); // Transfer tokens from buyer to treasury vm.prank(buyerAddress); @@ -410,6 +419,7 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te TestToken(token).approve(treasuryAddress, amount); // Process crypto payment - processCryptoPayment(buyerAddress, paymentId, itemId, buyerAddress, token, amount); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); + processCryptoPayment(buyerAddress, paymentId, itemId, buyerAddress, token, amount, emptyLineItems, new ICampaignPaymentTreasury.ExternalFees[](0)); } } \ No newline at end of file diff --git a/test/foundry/integration/PaymentTreasury/PaymentTreasuryBatchLimitTest.t.sol b/test/foundry/integration/PaymentTreasury/PaymentTreasuryBatchLimitTest.t.sol index 6bcf873d..bc253870 100644 --- a/test/foundry/integration/PaymentTreasury/PaymentTreasuryBatchLimitTest.t.sol +++ b/test/foundry/integration/PaymentTreasury/PaymentTreasuryBatchLimitTest.t.sol @@ -7,6 +7,7 @@ import "forge-std/console.sol"; import "forge-std/Test.sol"; import {LogDecoder} from "../../utils/LogDecoder.sol"; import {PaymentTreasury} from "src/treasuries/PaymentTreasury.sol"; +import {ICampaignPaymentTreasury} from "src/interfaces/ICampaignPaymentTreasury.sol"; contract PaymentTreasuryBatchLimit_Test is PaymentTreasury_Integration_Shared_Test { uint256 constant CELO_BLOCK_GAS_LIMIT = 30_000_000; @@ -33,7 +34,9 @@ contract PaymentTreasuryBatchLimit_Test is PaymentTreasury_Integration_Shared_Te bytes32 buyerId = keccak256(abi.encodePacked("buyer", i)); bytes32 itemId = keccak256(abi.encodePacked("item", i)); - paymentTreasury.createPayment(paymentId, buyerId, itemId, address(testToken), paymentAmount, expiration); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); + ICampaignPaymentTreasury.ExternalFees[] memory emptyExternalFees = new ICampaignPaymentTreasury.ExternalFees[](0); + paymentTreasury.createPayment(paymentId, buyerId, itemId, address(testToken), paymentAmount, expiration, emptyLineItems, emptyExternalFees); paymentIds[i] = paymentId; } diff --git a/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol b/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol index 95612cff..c4487958 100644 --- a/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol +++ b/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol @@ -111,7 +111,8 @@ contract PaymentTreasuryFunction_Integration_Test is vm.prank(users.backer1Address); testToken.approve(treasuryAddress, amount); - processCryptoPayment(users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), amount); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); + processCryptoPayment(users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), amount, emptyLineItems, new ICampaignPaymentTreasury.ExternalFees[](0)); assertEq(paymentTreasury.getRaisedAmount(), amount, "Raised amount should match crypto payment"); assertEq(paymentTreasury.getAvailableRaisedAmount(), amount, "Available amount should match crypto payment"); @@ -621,13 +622,16 @@ contract PaymentTreasuryFunction_Integration_Test is // Try to create payment with unaccepted token vm.expectRevert(); vm.prank(users.platform1AdminAddress); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); paymentTreasury.createPayment( PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, address(rejectedToken), amount, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); } @@ -642,14 +646,16 @@ contract PaymentTreasuryFunction_Integration_Test is // Try to process crypto payment with unaccepted token vm.expectRevert(); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); processCryptoPayment( users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(rejectedToken), - amount - ); + amount, + emptyLineItems + , new ICampaignPaymentTreasury.ExternalFees[](0)); } function test_balanceTrackingAcrossMultipleTokens() public { @@ -798,13 +804,16 @@ contract PaymentTreasuryFunction_Integration_Test is // Treasury 1: Create, fund, and confirm payment vm.prank(users.platform1AdminAddress); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); paymentTreasury1.createPayment( keccak256("payment-p1"), BUYER_ID_1, ITEM_ID_1, address(testToken), amount1, - block.timestamp + PAYMENT_EXPIRATION + block.timestamp + PAYMENT_EXPIRATION, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); // Fund backer and transfer to treasury @@ -823,7 +832,9 @@ contract PaymentTreasuryFunction_Integration_Test is ITEM_ID_2, address(testToken), amount2, - block.timestamp + PAYMENT_EXPIRATION + block.timestamp + PAYMENT_EXPIRATION, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); // Fund backer and transfer to treasury diff --git a/test/foundry/integration/PaymentTreasury/PaymentTreasuryLineItems.t.sol b/test/foundry/integration/PaymentTreasury/PaymentTreasuryLineItems.t.sol new file mode 100644 index 00000000..d7b29f5d --- /dev/null +++ b/test/foundry/integration/PaymentTreasury/PaymentTreasuryLineItems.t.sol @@ -0,0 +1,716 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.22; + +import "./PaymentTreasury.t.sol"; +import {ICampaignPaymentTreasury} from "src/interfaces/ICampaignPaymentTreasury.sol"; + +/// @notice Tests for PaymentTreasury with line items and expiration +contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Test { + // Line item type IDs + bytes32 internal constant SHIPPING_FEE_TYPE_ID = keccak256("shipping_fee"); + bytes32 internal constant TIP_TYPE_ID = keccak256("tip"); + bytes32 internal constant INTEREST_TYPE_ID = keccak256("interest"); + bytes32 internal constant REFUNDABLE_FEE_WITH_PROTOCOL_TYPE_ID = keccak256("refundable_fee_with_protocol"); + + function setUp() public override { + super.setUp(); + + // Register line item types + vm.prank(users.platform1AdminAddress); + globalParams.setPlatformLineItemType( + PLATFORM_1_HASH, + SHIPPING_FEE_TYPE_ID, + "shipping_fee", + true, // countsTowardGoal + false, // applyProtocolFee + true, // canRefund + false // instantTransfer + ); + + vm.prank(users.platform1AdminAddress); + globalParams.setPlatformLineItemType( + PLATFORM_1_HASH, + TIP_TYPE_ID, + "tip", + false, // countsTowardGoal + false, // applyProtocolFee + false, // canRefund + true // instantTransfer + ); + + vm.prank(users.platform1AdminAddress); + globalParams.setPlatformLineItemType( + PLATFORM_1_HASH, + INTEREST_TYPE_ID, + "interest", + false, // countsTowardGoal + true, // applyProtocolFee + false, // canRefund + false // instantTransfer + ); + + vm.prank(users.platform1AdminAddress); + globalParams.setPlatformLineItemType( + PLATFORM_1_HASH, + REFUNDABLE_FEE_WITH_PROTOCOL_TYPE_ID, + "refundable_fee_with_protocol", + false, // countsTowardGoal + true, // applyProtocolFee + true, // canRefund + false // instantTransfer + ); + } + + /*////////////////////////////////////////////////////////////// + LINE ITEMS - CREATE PAYMENT + //////////////////////////////////////////////////////////////*/ + + function test_createPaymentWithShippingFee() public { + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + uint256 shippingFeeAmount = 50e18; + + ICampaignPaymentTreasury.LineItem[] memory lineItems = new ICampaignPaymentTreasury.LineItem[](1); + lineItems[0] = ICampaignPaymentTreasury.LineItem({ + typeId: SHIPPING_FEE_TYPE_ID, + amount: shippingFeeAmount + }); + + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration, + lineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + // Shipping fee counts toward goal, so it should be tracked in pending payments + assertEq(paymentTreasury.getRaisedAmount(), 0); + assertEq(paymentTreasury.getAvailableRaisedAmount(), 0); + } + + function test_createPaymentWithTip() public { + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + uint256 tipAmount = 25e18; + + ICampaignPaymentTreasury.LineItem[] memory lineItems = new ICampaignPaymentTreasury.LineItem[](1); + lineItems[0] = ICampaignPaymentTreasury.LineItem({ + typeId: TIP_TYPE_ID, + amount: tipAmount + }); + + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration, + lineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + // Tip doesn't count toward goal, so it should be tracked separately + assertEq(paymentTreasury.getRaisedAmount(), 0); + } + + function test_createPaymentWithInterest() public { + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + uint256 interestAmount = 100e18; + + ICampaignPaymentTreasury.LineItem[] memory lineItems = new ICampaignPaymentTreasury.LineItem[](1); + lineItems[0] = ICampaignPaymentTreasury.LineItem({ + typeId: INTEREST_TYPE_ID, + amount: interestAmount + }); + + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration, + lineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + // Interest doesn't count toward goal but applies protocol fee + assertEq(paymentTreasury.getRaisedAmount(), 0); + } + + function test_createPaymentWithMultipleLineItems() public { + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + uint256 shippingFeeAmount = 50e18; + uint256 tipAmount = 25e18; + uint256 interestAmount = 100e18; + + ICampaignPaymentTreasury.LineItem[] memory lineItems = new ICampaignPaymentTreasury.LineItem[](3); + lineItems[0] = ICampaignPaymentTreasury.LineItem({ + typeId: SHIPPING_FEE_TYPE_ID, + amount: shippingFeeAmount + }); + lineItems[1] = ICampaignPaymentTreasury.LineItem({ + typeId: TIP_TYPE_ID, + amount: tipAmount + }); + lineItems[2] = ICampaignPaymentTreasury.LineItem({ + typeId: INTEREST_TYPE_ID, + amount: interestAmount + }); + + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration, + lineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + assertEq(paymentTreasury.getRaisedAmount(), 0); + } + + function test_createPaymentRevertWhenLineItemTypeDoesNotExist() public { + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + bytes32 nonExistentTypeId = keccak256("non_existent"); + + ICampaignPaymentTreasury.LineItem[] memory lineItems = new ICampaignPaymentTreasury.LineItem[](1); + lineItems[0] = ICampaignPaymentTreasury.LineItem({ + typeId: nonExistentTypeId, + amount: 50e18 + }); + + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration, + lineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + } + + function test_createPaymentRevertWhenLineItemHasZeroTypeId() public { + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + + ICampaignPaymentTreasury.LineItem[] memory lineItems = new ICampaignPaymentTreasury.LineItem[](1); + lineItems[0] = ICampaignPaymentTreasury.LineItem({ + typeId: bytes32(0), + amount: 50e18 + }); + + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration, + lineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + } + + function test_createPaymentRevertWhenLineItemHasZeroAmount() public { + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + + ICampaignPaymentTreasury.LineItem[] memory lineItems = new ICampaignPaymentTreasury.LineItem[](1); + lineItems[0] = ICampaignPaymentTreasury.LineItem({ + typeId: SHIPPING_FEE_TYPE_ID, + amount: 0 + }); + + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration, + lineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + } + + /*////////////////////////////////////////////////////////////// + LINE ITEMS - PROCESS CRYPTO PAYMENT + //////////////////////////////////////////////////////////////*/ + + function test_processCryptoPaymentWithShippingFee() public { + uint256 shippingFeeAmount = 50e18; + uint256 totalAmount = PAYMENT_AMOUNT_1 + shippingFeeAmount; + + deal(address(testToken), users.backer1Address, totalAmount); + vm.prank(users.backer1Address); + testToken.approve(treasuryAddress, totalAmount); + + ICampaignPaymentTreasury.LineItem[] memory lineItems = new ICampaignPaymentTreasury.LineItem[](1); + lineItems[0] = ICampaignPaymentTreasury.LineItem({ + typeId: SHIPPING_FEE_TYPE_ID, + amount: shippingFeeAmount + }); + + vm.prank(users.backer1Address); + paymentTreasury.processCryptoPayment( + PAYMENT_ID_1, + ITEM_ID_1, + users.backer1Address, + address(testToken), + PAYMENT_AMOUNT_1, + lineItems + , new ICampaignPaymentTreasury.ExternalFees[](0)); + + // Payment should be confirmed immediately for crypto payments + assertEq(paymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1 + shippingFeeAmount); + assertEq(testToken.balanceOf(treasuryAddress), totalAmount); + } + + function test_processCryptoPaymentWithTip() public { + uint256 tipAmount = 25e18; + uint256 totalAmount = PAYMENT_AMOUNT_1 + tipAmount; + + deal(address(testToken), users.backer1Address, totalAmount); + vm.prank(users.backer1Address); + testToken.approve(treasuryAddress, totalAmount); + + uint256 platformAdminBalanceBefore = testToken.balanceOf(users.platform1AdminAddress); + + ICampaignPaymentTreasury.LineItem[] memory lineItems = new ICampaignPaymentTreasury.LineItem[](1); + lineItems[0] = ICampaignPaymentTreasury.LineItem({ + typeId: TIP_TYPE_ID, + amount: tipAmount + }); + + vm.prank(users.backer1Address); + paymentTreasury.processCryptoPayment( + PAYMENT_ID_1, + ITEM_ID_1, + users.backer1Address, + address(testToken), + PAYMENT_AMOUNT_1, + lineItems + , new ICampaignPaymentTreasury.ExternalFees[](0)); + + // Tip doesn't count toward goal, but payment amount does + assertEq(paymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1); + // Tip is instantly transferred to platform admin, so treasury only holds payment amount + assertEq(testToken.balanceOf(treasuryAddress), PAYMENT_AMOUNT_1); + // Platform admin received the tip + assertEq(testToken.balanceOf(users.platform1AdminAddress), platformAdminBalanceBefore + tipAmount); + } + + function test_processCryptoPaymentWithMultipleLineItems() public { + uint256 shippingFeeAmount = 50e18; + uint256 tipAmount = 25e18; + uint256 interestAmount = 100e18; + uint256 totalAmount = PAYMENT_AMOUNT_1 + shippingFeeAmount + tipAmount + interestAmount; + + deal(address(testToken), users.backer1Address, totalAmount); + vm.prank(users.backer1Address); + testToken.approve(treasuryAddress, totalAmount); + + uint256 platformAdminBalanceBefore = testToken.balanceOf(users.platform1AdminAddress); + uint256 tipNetAmount = tipAmount; // No protocol fee on tip + + ICampaignPaymentTreasury.LineItem[] memory lineItems = new ICampaignPaymentTreasury.LineItem[](3); + lineItems[0] = ICampaignPaymentTreasury.LineItem({ + typeId: SHIPPING_FEE_TYPE_ID, + amount: shippingFeeAmount + }); + lineItems[1] = ICampaignPaymentTreasury.LineItem({ + typeId: TIP_TYPE_ID, + amount: tipAmount + }); + lineItems[2] = ICampaignPaymentTreasury.LineItem({ + typeId: INTEREST_TYPE_ID, + amount: interestAmount + }); + + vm.prank(users.backer1Address); + paymentTreasury.processCryptoPayment( + PAYMENT_ID_1, + ITEM_ID_1, + users.backer1Address, + address(testToken), + PAYMENT_AMOUNT_1, + lineItems + , new ICampaignPaymentTreasury.ExternalFees[](0)); + + // Only payment amount + shipping fee count toward goal + assertEq(paymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1 + shippingFeeAmount); + // Treasury holds: payment amount + shipping fee + interest (full amount, protocol fee tracked separately) + // Tip is instantly transferred to platform admin + assertEq(testToken.balanceOf(treasuryAddress), PAYMENT_AMOUNT_1 + shippingFeeAmount + interestAmount); + // Platform admin received the tip instantly + assertEq(testToken.balanceOf(users.platform1AdminAddress), platformAdminBalanceBefore + tipNetAmount); + } + + /*////////////////////////////////////////////////////////////// + EXPIRATION TESTS + //////////////////////////////////////////////////////////////*/ + + function test_createPaymentWithValidExpiration() public { + uint256 expiration = block.timestamp + 1 days; + + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + assertEq(paymentTreasury.getRaisedAmount(), 0); + } + + function test_createPaymentRevertWhenExpirationInPast() public { + uint256 expiration = block.timestamp - 1; + + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + } + + function test_createPaymentRevertWhenExpirationIsCurrentTime() public { + uint256 expiration = block.timestamp; + + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + } + + function test_createPaymentWithLongExpiration() public { + uint256 expiration = block.timestamp + 365 days; + + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + assertEq(paymentTreasury.getRaisedAmount(), 0); + } + + function test_cancelPaymentRevertWhenExpired() public { + uint256 expiration = block.timestamp + 1 hours; + + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + // Advance time past expiration + vm.warp(block.timestamp + 2 hours); + + // Should revert when trying to cancel expired payment + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.cancelPayment(PAYMENT_ID_1); + } + + function test_confirmPaymentBeforeExpiration() public { + uint256 expiration = block.timestamp + 1 days; + + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + // Fund the payment + deal(address(testToken), users.backer1Address, PAYMENT_AMOUNT_1); + vm.prank(users.backer1Address); + testToken.transfer(treasuryAddress, PAYMENT_AMOUNT_1); + + // Should be able to confirm before expiration + vm.prank(users.platform1AdminAddress); + paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); + + assertEq(paymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1); + } + + function test_getPaymentDataIncludesLineItemsAndExternalFees() public { + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + uint256 shippingFeeAmount = 50e18; + uint256 tipAmount = 25e18; + + ICampaignPaymentTreasury.LineItem[] memory lineItems = new ICampaignPaymentTreasury.LineItem[](2); + lineItems[0] = ICampaignPaymentTreasury.LineItem({ + typeId: SHIPPING_FEE_TYPE_ID, + amount: shippingFeeAmount + }); + lineItems[1] = ICampaignPaymentTreasury.LineItem({ + typeId: TIP_TYPE_ID, + amount: tipAmount + }); + + ICampaignPaymentTreasury.ExternalFees[] memory externalFees = new ICampaignPaymentTreasury.ExternalFees[](2); + externalFees[0] = ICampaignPaymentTreasury.ExternalFees({ + feeType: keccak256(abi.encodePacked("gateway_fee")), + feeAmount: 15e18 + }); + externalFees[1] = ICampaignPaymentTreasury.ExternalFees({ + feeType: keccak256(abi.encodePacked("processing_fee")), + feeAmount: 5e18 + }); + + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + PAYMENT_AMOUNT_1, + expiration, + lineItems, + externalFees + ); + + ICampaignPaymentTreasury.PaymentData memory paymentData = paymentTreasury.getPaymentData(PAYMENT_ID_1); + + assertEq(paymentData.buyerId, BUYER_ID_1); + assertEq(paymentData.itemId, ITEM_ID_1); + assertEq(paymentData.amount, PAYMENT_AMOUNT_1); + assertEq(paymentData.expiration, expiration); + assertFalse(paymentData.isConfirmed); + assertFalse(paymentData.isCryptoPayment); + assertEq(paymentData.lineItemCount, lineItems.length); + assertEq(paymentData.paymentToken, address(testToken)); + + assertEq(paymentData.lineItems.length, lineItems.length); + assertEq(paymentData.lineItems[0].typeId, SHIPPING_FEE_TYPE_ID); + assertEq(paymentData.lineItems[0].amount, shippingFeeAmount); + assertEq(keccak256(bytes(paymentData.lineItems[0].label)), keccak256(bytes("shipping_fee"))); + assertTrue(paymentData.lineItems[0].countsTowardGoal); + assertFalse(paymentData.lineItems[0].applyProtocolFee); + assertTrue(paymentData.lineItems[0].canRefund); + assertFalse(paymentData.lineItems[0].instantTransfer); + + assertEq(paymentData.lineItems[1].typeId, TIP_TYPE_ID); + assertEq(paymentData.lineItems[1].amount, tipAmount); + assertEq(keccak256(bytes(paymentData.lineItems[1].label)), keccak256(bytes("tip"))); + assertFalse(paymentData.lineItems[1].countsTowardGoal); + assertFalse(paymentData.lineItems[1].applyProtocolFee); + assertFalse(paymentData.lineItems[1].canRefund); + assertTrue(paymentData.lineItems[1].instantTransfer); + + assertEq(paymentData.externalFees.length, externalFees.length); + assertEq(paymentData.externalFees[0].feeType, externalFees[0].feeType); + assertEq(paymentData.externalFees[0].feeAmount, externalFees[0].feeAmount); + assertEq(paymentData.externalFees[1].feeType, externalFees[1].feeType); + assertEq(paymentData.externalFees[1].feeAmount, externalFees[1].feeAmount); + } + + function test_processCryptoPaymentRefundableNonGoalWithProtocolFee() public { + uint256 baseAmount = PAYMENT_AMOUNT_1; + uint256 lineItemAmount = 200e18; + uint256 totalAmount = baseAmount + lineItemAmount; + + deal(address(testToken), users.backer1Address, totalAmount); + + vm.prank(users.backer1Address); + testToken.approve(treasuryAddress, totalAmount); + + ICampaignPaymentTreasury.LineItem[] memory lineItems = new ICampaignPaymentTreasury.LineItem[](1); + lineItems[0] = ICampaignPaymentTreasury.LineItem({ + typeId: REFUNDABLE_FEE_WITH_PROTOCOL_TYPE_ID, + amount: lineItemAmount + }); + + bytes32 paymentId = keccak256("refundableFeePayment"); + + vm.prank(users.backer1Address); + paymentTreasury.processCryptoPayment( + paymentId, + ITEM_ID_1, + users.backer1Address, + address(testToken), + baseAmount, + lineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + + uint256 buyerBalanceAfterPayment = testToken.balanceOf(users.backer1Address); + + uint256 expectedFee = (lineItemAmount * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 expectedNetLineItem = lineItemAmount - expectedFee; + uint256 expectedRefund = baseAmount + expectedNetLineItem; + + vm.prank(users.backer1Address); + // Approve treasury to burn NFT + CampaignInfo(campaignAddress).approve(address(paymentTreasury), 1); + paymentTreasury.claimRefund(paymentId); + + assertEq( + testToken.balanceOf(users.backer1Address), + buyerBalanceAfterPayment + expectedRefund + ); + assertEq(testToken.balanceOf(treasuryAddress), expectedFee); + } + + /*////////////////////////////////////////////////////////////// + LINE ITEMS - BATCH OPERATIONS + //////////////////////////////////////////////////////////////*/ + + function test_createPaymentBatchWithLineItems() public { + bytes32[] memory paymentIds = new bytes32[](2); + paymentIds[0] = PAYMENT_ID_1; + paymentIds[1] = PAYMENT_ID_2; + + bytes32[] memory buyerIds = new bytes32[](2); + buyerIds[0] = BUYER_ID_1; + buyerIds[1] = BUYER_ID_2; + + bytes32[] memory itemIds = new bytes32[](2); + itemIds[0] = ITEM_ID_1; + itemIds[1] = ITEM_ID_2; + + address[] memory paymentTokens = new address[](2); + paymentTokens[0] = address(testToken); + paymentTokens[1] = address(testToken); + + uint256[] memory amounts = new uint256[](2); + amounts[0] = PAYMENT_AMOUNT_1; + amounts[1] = PAYMENT_AMOUNT_2; + + uint256[] memory expirations = new uint256[](2); + expirations[0] = block.timestamp + PAYMENT_EXPIRATION; + expirations[1] = block.timestamp + PAYMENT_EXPIRATION; + + ICampaignPaymentTreasury.LineItem[][] memory lineItemsArray = new ICampaignPaymentTreasury.LineItem[][](2); + + // First payment with shipping fee + lineItemsArray[0] = new ICampaignPaymentTreasury.LineItem[](1); + lineItemsArray[0][0] = ICampaignPaymentTreasury.LineItem({ + typeId: SHIPPING_FEE_TYPE_ID, + amount: 50e18 + }); + + // Second payment with tip + lineItemsArray[1] = new ICampaignPaymentTreasury.LineItem[](1); + lineItemsArray[1][0] = ICampaignPaymentTreasury.LineItem({ + typeId: TIP_TYPE_ID, + amount: 25e18 + }); + + vm.prank(users.platform1AdminAddress); + ICampaignPaymentTreasury.ExternalFees[][] memory externalFeesArray = new ICampaignPaymentTreasury.ExternalFees[][](2); + externalFeesArray[0] = new ICampaignPaymentTreasury.ExternalFees[](0); + externalFeesArray[1] = new ICampaignPaymentTreasury.ExternalFees[](0); + paymentTreasury.createPaymentBatch( + paymentIds, + buyerIds, + itemIds, + paymentTokens, + amounts, + expirations, + lineItemsArray, + externalFeesArray + ); + + assertEq(paymentTreasury.getRaisedAmount(), 0); + } + + function test_createPaymentBatchRevertWhenLineItemsArrayLengthMismatch() public { + bytes32[] memory paymentIds = new bytes32[](2); + paymentIds[0] = PAYMENT_ID_1; + paymentIds[1] = PAYMENT_ID_2; + + bytes32[] memory buyerIds = new bytes32[](2); + buyerIds[0] = BUYER_ID_1; + buyerIds[1] = BUYER_ID_2; + + bytes32[] memory itemIds = new bytes32[](2); + itemIds[0] = ITEM_ID_1; + itemIds[1] = ITEM_ID_2; + + address[] memory paymentTokens = new address[](2); + paymentTokens[0] = address(testToken); + paymentTokens[1] = address(testToken); + + uint256[] memory amounts = new uint256[](2); + amounts[0] = PAYMENT_AMOUNT_1; + amounts[1] = PAYMENT_AMOUNT_2; + + uint256[] memory expirations = new uint256[](2); + expirations[0] = block.timestamp + PAYMENT_EXPIRATION; + expirations[1] = block.timestamp + PAYMENT_EXPIRATION; + + // Wrong length - only 1 item instead of 2 + ICampaignPaymentTreasury.LineItem[][] memory lineItemsArray = new ICampaignPaymentTreasury.LineItem[][](1); + lineItemsArray[0] = new ICampaignPaymentTreasury.LineItem[](0); + // Also wrong length for externalFeesArray to match the test intent + ICampaignPaymentTreasury.ExternalFees[][] memory externalFeesArray = new ICampaignPaymentTreasury.ExternalFees[][](1); + externalFeesArray[0] = new ICampaignPaymentTreasury.ExternalFees[](0); + + vm.expectRevert(); + vm.prank(users.platform1AdminAddress); + paymentTreasury.createPaymentBatch( + paymentIds, + buyerIds, + itemIds, + paymentTokens, + amounts, + expirations, + lineItemsArray, + externalFeesArray + ); + } +} + diff --git a/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasuryFunction.t.sol b/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasuryFunction.t.sol index 3047b0d8..237654fe 100644 --- a/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasuryFunction.t.sol +++ b/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasuryFunction.t.sol @@ -27,6 +27,7 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC advanceToWithinRange(); uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.createPayment( PAYMENT_ID_1, @@ -34,9 +35,10 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); - // Payment created successfully assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); assertEq(timeConstrainedPaymentTreasury.getAvailableRaisedAmount(), 0); @@ -69,14 +71,23 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC expirations[0] = block.timestamp + PAYMENT_EXPIRATION; expirations[1] = block.timestamp + PAYMENT_EXPIRATION; + ICampaignPaymentTreasury.LineItem[][] memory emptyLineItemsArray = new ICampaignPaymentTreasury.LineItem[][](2); + emptyLineItemsArray[0] = new ICampaignPaymentTreasury.LineItem[](0); + emptyLineItemsArray[1] = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); + ICampaignPaymentTreasury.ExternalFees[][] memory externalFeesArray = new ICampaignPaymentTreasury.ExternalFees[][](2); + externalFeesArray[0] = new ICampaignPaymentTreasury.ExternalFees[](0); + externalFeesArray[1] = new ICampaignPaymentTreasury.ExternalFees[](0); timeConstrainedPaymentTreasury.createPaymentBatch( paymentIds, buyerIds, itemIds, paymentTokens, amounts, - expirations + expirations, + emptyLineItemsArray, + + externalFeesArray ); // Payments created successfully @@ -90,14 +101,16 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC vm.prank(users.backer1Address); testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.processCryptoPayment( PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), - PAYMENT_AMOUNT_1 - ); + PAYMENT_AMOUNT_1, + emptyLineItems + , new ICampaignPaymentTreasury.ExternalFees[](0)); // Payment processed successfully assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1); @@ -109,6 +122,7 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC // First create a payment uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.createPayment( PAYMENT_ID_1, @@ -116,9 +130,10 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); - // Then cancel it vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.cancelPayment(PAYMENT_ID_1); @@ -137,14 +152,16 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC vm.prank(users.backer1Address); testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.processCryptoPayment( uniquePaymentId, ITEM_ID_1, users.backer1Address, address(testToken), - PAYMENT_AMOUNT_1 - ); + PAYMENT_AMOUNT_1, + emptyLineItems + , new ICampaignPaymentTreasury.ExternalFees[](0)); // Payment created and confirmed successfully by processCryptoPayment assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1); @@ -162,26 +179,30 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC vm.prank(users.backer1Address); testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.processCryptoPayment( uniquePaymentId1, ITEM_ID_1, users.backer1Address, address(testToken), - PAYMENT_AMOUNT_1 - ); + PAYMENT_AMOUNT_1, + emptyLineItems + , new ICampaignPaymentTreasury.ExternalFees[](0)); vm.prank(users.backer2Address); testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_2); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems2 = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.processCryptoPayment( uniquePaymentId2, ITEM_ID_2, users.backer2Address, address(testToken), - PAYMENT_AMOUNT_2 - ); + PAYMENT_AMOUNT_2, + emptyLineItems2 + , new ICampaignPaymentTreasury.ExternalFees[](0)); // Payments created and confirmed successfully by processCryptoPayment assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2); @@ -199,14 +220,16 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC vm.prank(users.backer1Address); testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.processCryptoPayment( uniquePaymentId, ITEM_ID_1, users.backer1Address, address(testToken), - PAYMENT_AMOUNT_1 - ); + PAYMENT_AMOUNT_1, + emptyLineItems + , new ICampaignPaymentTreasury.ExternalFees[](0)); // Advance to after launch to be able to claim refund advanceToAfterLaunch(); @@ -235,14 +258,16 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC vm.prank(users.backer1Address); testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.processCryptoPayment( uniquePaymentId, ITEM_ID_1, users.backer1Address, address(testToken), - PAYMENT_AMOUNT_1 - ); + PAYMENT_AMOUNT_1, + emptyLineItems + , new ICampaignPaymentTreasury.ExternalFees[](0)); // Advance to after launch to be able to disburse fees advanceToAfterLaunch(); @@ -265,14 +290,16 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC vm.prank(users.backer1Address); testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.processCryptoPayment( uniquePaymentId, ITEM_ID_1, users.backer1Address, address(testToken), - PAYMENT_AMOUNT_1 - ); + PAYMENT_AMOUNT_1, + emptyLineItems + , new ICampaignPaymentTreasury.ExternalFees[](0)); // Advance to after launch to be able to withdraw advanceToAfterLaunch(); @@ -288,6 +315,7 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC advanceToBeforeLaunch(); uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.expectRevert(); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.createPayment( @@ -296,7 +324,9 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); } @@ -304,6 +334,7 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC advanceToAfterDeadline(); uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.expectRevert(); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.createPayment( @@ -312,7 +343,9 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); } @@ -348,6 +381,7 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC vm.warp(campaignDeadline - 1); // Use deadline - 1 to be within range uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.createPayment( PAYMENT_ID_1, @@ -355,9 +389,10 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); - // Should succeed at deadline - 1 assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); } @@ -367,6 +402,7 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC vm.warp(campaignDeadline - 1); // Use deadline - 1 to be within range uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.createPayment( PAYMENT_ID_1, @@ -374,9 +410,10 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); - // Should succeed at deadline - 1 assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); } @@ -386,6 +423,7 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC advanceToAfterDeadline(); uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.expectRevert(); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.createPayment( @@ -394,7 +432,9 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); } @@ -403,6 +443,7 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC vm.warp(campaignLaunchTime); uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.createPayment( PAYMENT_ID_1, @@ -410,9 +451,10 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); - // Should succeed at the exact launch time assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); } @@ -422,6 +464,7 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC vm.warp(campaignDeadline); uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.createPayment( PAYMENT_ID_1, @@ -429,9 +472,10 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); - // Should succeed at the exact deadline assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); } @@ -447,14 +491,16 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC vm.prank(users.backer1Address); testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.processCryptoPayment( uniquePaymentId, ITEM_ID_1, users.backer1Address, address(testToken), - PAYMENT_AMOUNT_1 - ); + PAYMENT_AMOUNT_1, + emptyLineItems + , new ICampaignPaymentTreasury.ExternalFees[](0)); // Advance to after launch time advanceToAfterLaunch(); diff --git a/test/foundry/unit/GlobalParams.t.sol b/test/foundry/unit/GlobalParams.t.sol index 309ffd88..41d25561 100644 --- a/test/foundry/unit/GlobalParams.t.sol +++ b/test/foundry/unit/GlobalParams.t.sol @@ -157,6 +157,129 @@ contract GlobalParams_UnitTest is Test, Defaults { globalParams.removeTokenFromCurrency(USD, address(nonExistentToken)); } + function testUpdatePlatformClaimDelay() public { + bytes32 platformHash = keccak256("claimDelayPlatform"); + address platformAdmin = address(0xB0B); + + vm.prank(admin); + globalParams.enlistPlatform(platformHash, platformAdmin, 500); + + uint256 claimDelay = 5 days; + vm.prank(platformAdmin); + globalParams.updatePlatformClaimDelay(platformHash, claimDelay); + + assertEq(globalParams.getPlatformClaimDelay(platformHash), claimDelay); + } + + function testUpdatePlatformClaimDelayRevertsForNonAdmin() public { + bytes32 platformHash = keccak256("claimDelayPlatformRevert"); + address platformAdmin = address(0xC0DE); + + vm.prank(admin); + globalParams.enlistPlatform(platformHash, platformAdmin, 600); + + vm.expectRevert(abi.encodeWithSelector(GlobalParams.GlobalParamsUnauthorized.selector)); + globalParams.updatePlatformClaimDelay(platformHash, 3 days); + } + + function testSetPlatformLineItemTypeAllowsRefundableWithProtocolFee() public { + bytes32 platformHash = keccak256("lineItemPlatform"); + address platformAdmin = address(0xCAFE); + bytes32 typeId = keccak256("refundable_fee_with_protocol"); + + vm.prank(admin); + globalParams.enlistPlatform(platformHash, platformAdmin, 500); + + vm.prank(platformAdmin); + globalParams.setPlatformLineItemType( + platformHash, + typeId, + "refundable_fee_with_protocol", + false, // countsTowardGoal + true, // applyProtocolFee + true, // canRefund + false // instantTransfer + ); + + ( + bool exists, + , + bool countsTowardGoal, + bool applyProtocolFee, + bool canRefund, + bool instantTransfer + ) = globalParams.getPlatformLineItemType(platformHash, typeId); + + assertTrue(exists); + assertFalse(countsTowardGoal); + assertTrue(applyProtocolFee); + assertTrue(canRefund); + assertFalse(instantTransfer); + } + + function testSetPlatformLineItemTypeRevertsWhenGoalAppliesProtocolFee() public { + bytes32 platformHash = keccak256("goalPlatform"); + address platformAdmin = address(0xDEAD); + bytes32 typeId = keccak256("goal_type"); + + vm.prank(admin); + globalParams.enlistPlatform(platformHash, platformAdmin, 400); + + vm.expectRevert(GlobalParams.GlobalParamsInvalidInput.selector); + vm.prank(platformAdmin); + globalParams.setPlatformLineItemType( + platformHash, + typeId, + "goal_type", + true, // countsTowardGoal + true, // applyProtocolFee (should revert) + true, // canRefund + false // instantTransfer + ); + } + + function testSetPlatformLineItemTypeRevertsWhenGoalCannotRefund() public { + bytes32 platformHash = keccak256("goalRefundPlatform"); + address platformAdmin = address(0xFEED); + bytes32 typeId = keccak256("goal_no_refund"); + + vm.prank(admin); + globalParams.enlistPlatform(platformHash, platformAdmin, 450); + + vm.expectRevert(GlobalParams.GlobalParamsInvalidInput.selector); + vm.prank(platformAdmin); + globalParams.setPlatformLineItemType( + platformHash, + typeId, + "goal_no_refund", + true, // countsTowardGoal + false, // applyProtocolFee + false, // canRefund (should revert) + false // instantTransfer + ); + } + + function testSetPlatformLineItemTypeRevertsWhenInstantTransferRefundable() public { + bytes32 platformHash = keccak256("instantPlatform"); + address platformAdmin = address(0xABCD); + bytes32 typeId = keccak256("instant_refundable"); + + vm.prank(admin); + globalParams.enlistPlatform(platformHash, platformAdmin, 300); + + vm.expectRevert(GlobalParams.GlobalParamsInvalidInput.selector); + vm.prank(platformAdmin); + globalParams.setPlatformLineItemType( + platformHash, + typeId, + "instant_refundable", + false, // countsTowardGoal (non-goal) + false, // applyProtocolFee + true, // canRefund (should revert with instantTransfer) + true // instantTransfer + ); + } + function testGetTokensForCurrency() public { address[] memory usdTokens = globalParams.getTokensForCurrency(USD); assertEq(usdTokens.length, 2); diff --git a/test/foundry/unit/PaymentTreasury.t.sol b/test/foundry/unit/PaymentTreasury.t.sol index ebb135ab..70c30766 100644 --- a/test/foundry/unit/PaymentTreasury.t.sol +++ b/test/foundry/unit/PaymentTreasury.t.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.22; import "../integration/PaymentTreasury/PaymentTreasury.t.sol"; import "forge-std/Test.sol"; import {PaymentTreasury} from "src/treasuries/PaymentTreasury.sol"; +import {BasePaymentTreasury} from "src/utils/BasePaymentTreasury.sol"; import {CampaignInfo} from "src/CampaignInfo.sol"; import {TestToken} from "../../mocks/TestToken.sol"; @@ -84,13 +85,16 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testCreatePayment() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.prank(users.platform1AdminAddress); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); paymentTreasury.createPayment( PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, address(testToken), // Added token parameter PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); // Payment created but not confirmed assertEq(paymentTreasury.getRaisedAmount(), 0); @@ -101,19 +105,23 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.expectRevert(); vm.prank(users.backer1Address); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); paymentTreasury.createPayment( PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); } function testCreatePaymentRevertWhenZeroBuyerId() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.expectRevert(); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_1, @@ -121,13 +129,16 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); } function testCreatePaymentRevertWhenZeroAmount() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.expectRevert(); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_1, @@ -135,12 +146,15 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te ITEM_ID_1, address(testToken), 0, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); } function testCreatePaymentRevertWhenExpired() public { vm.expectRevert(); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_1, @@ -148,13 +162,16 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - block.timestamp - 1 + block.timestamp - 1, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); } function testCreatePaymentRevertWhenZeroPaymentId() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.expectRevert(); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( bytes32(0), @@ -162,13 +179,16 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); } function testCreatePaymentRevertWhenZeroItemId() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.expectRevert(); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_1, @@ -176,13 +196,16 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te bytes32(0), address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); } function testCreatePaymentRevertWhenZeroTokenAddress() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.expectRevert(); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_1, @@ -190,7 +213,9 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te ITEM_ID_1, address(0), // Zero token address PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); } @@ -200,6 +225,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.expectRevert(); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_1, @@ -207,21 +233,27 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te ITEM_ID_1, address(unacceptedToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); } function testCreatePaymentRevertWhenPaymentExists() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.startPrank(users.platform1AdminAddress); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); paymentTreasury.createPayment( PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems2 = new ICampaignPaymentTreasury.LineItem[](0); vm.expectRevert(); paymentTreasury.createPayment( PAYMENT_ID_1, @@ -229,7 +261,9 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te ITEM_ID_2, address(testToken), PAYMENT_AMOUNT_2, - expiration + expiration, + emptyLineItems2, + new ICampaignPaymentTreasury.ExternalFees[](0) ); vm.stopPrank(); } @@ -243,13 +277,16 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te // createPayment checks both treasury and campaign pause vm.expectRevert(); vm.prank(users.platform1AdminAddress); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); paymentTreasury.createPayment( PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); } @@ -262,13 +299,16 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.expectRevert(); vm.prank(users.platform1AdminAddress); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); paymentTreasury.createPayment( PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); } @@ -283,21 +323,58 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.backer1Address); testToken.approve(treasuryAddress, amount); - processCryptoPayment(users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), amount); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); + processCryptoPayment(users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), amount, emptyLineItems, new ICampaignPaymentTreasury.ExternalFees[](0)); assertEq(paymentTreasury.getRaisedAmount(), amount); assertEq(paymentTreasury.getAvailableRaisedAmount(), amount); assertEq(testToken.balanceOf(treasuryAddress), amount); } + function testProcessCryptoPaymentStoresExternalFees() public { + uint256 amount = 1000e18; + deal(address(testToken), users.backer1Address, amount); + + vm.prank(users.backer1Address); + testToken.approve(treasuryAddress, amount); + + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); + ICampaignPaymentTreasury.ExternalFees[] memory externalFees = new ICampaignPaymentTreasury.ExternalFees[](2); + externalFees[0] = ICampaignPaymentTreasury.ExternalFees({feeType: keccak256("feeType1"), feeAmount: 10}); + externalFees[1] = ICampaignPaymentTreasury.ExternalFees({feeType: keccak256("feeType2"), feeAmount: 25}); + + bytes32 cryptoPaymentId = keccak256("cryptoPaymentWithFees"); + processCryptoPayment( + users.backer1Address, + cryptoPaymentId, + ITEM_ID_1, + users.backer1Address, + address(testToken), + amount, + emptyLineItems, + externalFees + ); + + ICampaignPaymentTreasury.PaymentData memory paymentData = paymentTreasury.getPaymentData(cryptoPaymentId); + assertEq(paymentData.amount, amount); + assertTrue(paymentData.isConfirmed); + assertEq(paymentData.externalFees.length, 2); + assertEq(paymentData.externalFees[0].feeType, keccak256("feeType1")); + assertEq(paymentData.externalFees[0].feeAmount, 10); + assertEq(paymentData.externalFees[1].feeType, keccak256("feeType2")); + assertEq(paymentData.externalFees[1].feeAmount, 25); + } + function testProcessCryptoPaymentRevertWhenZeroBuyerAddress() public { vm.expectRevert(); - processCryptoPayment(users.platform1AdminAddress, PAYMENT_ID_1, ITEM_ID_1, address(0), address(testToken), 1000e18); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); + processCryptoPayment(users.platform1AdminAddress, PAYMENT_ID_1, ITEM_ID_1, address(0), address(testToken), 1000e18, emptyLineItems, new ICampaignPaymentTreasury.ExternalFees[](0)); } function testProcessCryptoPaymentRevertWhenZeroAmount() public { vm.expectRevert(); - processCryptoPayment(users.platform1AdminAddress, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), 0); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); + processCryptoPayment(users.platform1AdminAddress, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), 0, emptyLineItems, new ICampaignPaymentTreasury.ExternalFees[](0)); } function testProcessCryptoPaymentRevertWhenPaymentExists() public { @@ -307,10 +384,107 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.backer1Address); testToken.approve(treasuryAddress, amount * 2); - processCryptoPayment(users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), amount); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); + processCryptoPayment(users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), amount, emptyLineItems, new ICampaignPaymentTreasury.ExternalFees[](0)); vm.expectRevert(); - processCryptoPayment(users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), amount); + processCryptoPayment(users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), amount, emptyLineItems, new ICampaignPaymentTreasury.ExternalFees[](0)); + } + + function testClaimExpiredFundsRevertsBeforeWindow() public { + uint256 claimDelay = 7 days; + vm.prank(users.platform1AdminAddress); + globalParams.updatePlatformClaimDelay(PLATFORM_1_HASH, claimDelay); + + _createAndProcessCryptoPayment(PAYMENT_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); + + uint256 claimableAt = CampaignInfo(campaignAddress).getDeadline() + claimDelay; + vm.warp(claimableAt - 1); + + vm.prank(users.platform1AdminAddress); + vm.expectRevert( + abi.encodeWithSelector( + BasePaymentTreasury.PaymentTreasuryClaimWindowNotReached.selector, + claimableAt + ) + ); + paymentTreasury.claimExpiredFunds(); + } + + function testClaimExpiredFundsTransfersAllBalances() public { + uint256 claimDelay = 7 days; + vm.prank(users.platform1AdminAddress); + globalParams.updatePlatformClaimDelay(PLATFORM_1_HASH, claimDelay); + + bytes32 refundableTypeId = keccak256("refundable_non_goal_type"); + vm.prank(users.platform1AdminAddress); + globalParams.setPlatformLineItemType( + PLATFORM_1_HASH, + refundableTypeId, + "Refundable Non Goal", + false, + false, + true, + false + ); + + uint256 lineItemAmount = 250e18; + ICampaignPaymentTreasury.LineItem[] memory lineItems = new ICampaignPaymentTreasury.LineItem[](1); + lineItems[0] = ICampaignPaymentTreasury.LineItem({typeId: refundableTypeId, amount: lineItemAmount}); + + uint256 totalAmount = PAYMENT_AMOUNT_1 + lineItemAmount; + deal(address(testToken), users.backer1Address, totalAmount); + + vm.prank(users.backer1Address); + testToken.approve(treasuryAddress, totalAmount); + + vm.prank(users.backer1Address); + paymentTreasury.processCryptoPayment( + PAYMENT_ID_1, + ITEM_ID_1, + users.backer1Address, + address(testToken), + PAYMENT_AMOUNT_1, + lineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + + uint256 claimableAt = CampaignInfo(campaignAddress).getDeadline() + claimDelay; + vm.warp(claimableAt + 1); + + uint256 platformBalanceBefore = testToken.balanceOf(users.platform1AdminAddress); + uint256 protocolBalanceBefore = testToken.balanceOf(users.protocolAdminAddress); + + vm.prank(users.platform1AdminAddress); + paymentTreasury.claimExpiredFunds(); + + assertEq( + testToken.balanceOf(users.platform1AdminAddress), + platformBalanceBefore + totalAmount, + "Platform admin should receive all remaining funds" + ); + assertEq( + testToken.balanceOf(users.protocolAdminAddress), + protocolBalanceBefore, + "Protocol admin should not receive funds when no protocol fees accrued" + ); + assertEq(paymentTreasury.getAvailableRaisedAmount(), 0, "Available raised amount should be zero"); + assertEq(testToken.balanceOf(treasuryAddress), 0, "Treasury token balance should be zero"); + } + + function testClaimExpiredFundsRevertsWhenNoFunds() public { + uint256 claimDelay = 1 days; + vm.prank(users.platform1AdminAddress); + globalParams.updatePlatformClaimDelay(PLATFORM_1_HASH, claimDelay); + + uint256 claimableAt = CampaignInfo(campaignAddress).getDeadline() + claimDelay; + vm.warp(claimableAt + 1); + + vm.prank(users.platform1AdminAddress); + vm.expectRevert( + abi.encodeWithSelector(BasePaymentTreasury.PaymentTreasuryNoFundsToClaim.selector) + ); + paymentTreasury.claimExpiredFunds(); } /*////////////////////////////////////////////////////////////// @@ -321,13 +495,16 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te // Create payment first uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.prank(users.platform1AdminAddress); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); paymentTreasury.createPayment( PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); // Cancel it vm.prank(users.platform1AdminAddress); @@ -355,13 +532,16 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testCancelPaymentRevertWhenExpired() public { uint256 expiration = block.timestamp + 1 hours; vm.prank(users.platform1AdminAddress); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); paymentTreasury.createPayment( PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); // Warp past expiration vm.warp(expiration + 1); @@ -499,13 +679,16 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testClaimRefundRevertWhenNotConfirmed() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.prank(users.platform1AdminAddress); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); paymentTreasury.createPayment( PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); vm.expectRevert(); vm.prank(users.platform1AdminAddress); @@ -672,6 +855,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te // createPayment checks treasury pause as well uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.expectRevert(); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( @@ -680,7 +864,9 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te ITEM_ID_2, address(testToken), PAYMENT_AMOUNT_2, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); } @@ -694,13 +880,16 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te // Should be able to create payment uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.prank(users.platform1AdminAddress); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); paymentTreasury.createPayment( PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); } @@ -716,6 +905,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te paymentTreasury.disburseFees(); uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.expectRevert(); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( @@ -724,7 +914,9 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te ITEM_ID_2, address(testToken), PAYMENT_AMOUNT_2, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); } @@ -741,6 +933,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te paymentTreasury.disburseFees(); uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.expectRevert(); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( @@ -749,7 +942,9 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te ITEM_ID_2, address(testToken), PAYMENT_AMOUNT_2, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); } @@ -820,6 +1015,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te uint256 longExpiration = block.timestamp + 7 days; // Create payments with different expirations + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.startPrank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_1, @@ -827,7 +1023,9 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - shortExpiration + shortExpiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); paymentTreasury.createPayment( PAYMENT_ID_2, @@ -835,7 +1033,9 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te ITEM_ID_2, address(testToken), PAYMENT_AMOUNT_2, - longExpiration + longExpiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); vm.stopPrank(); @@ -885,6 +1085,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testCannotCreatePhantomBalances() public { // Create payment for 1000 tokens with USDC specified uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_1, @@ -892,7 +1093,9 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te ITEM_ID_1, address(testToken), // Token specified during creation 1000e18, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); // Try to confirm without any tokens - should revert @@ -916,8 +1119,9 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te // Create two payments of 500 each, both with testToken uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.startPrank(users.platform1AdminAddress); - paymentTreasury.createPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, address(testToken), 500e18, expiration); - paymentTreasury.createPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, address(testToken), 500e18, expiration); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); + paymentTreasury.createPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, address(testToken), 500e18, expiration, emptyLineItems, new ICampaignPaymentTreasury.ExternalFees[](0)); + paymentTreasury.createPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, address(testToken), 500e18, expiration, emptyLineItems, new ICampaignPaymentTreasury.ExternalFees[](0)); vm.stopPrank(); // Send only 500 tokens total @@ -941,8 +1145,10 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te // Create two payments uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.startPrank(users.platform1AdminAddress); - paymentTreasury.createPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, address(testToken), 500e18, expiration); - paymentTreasury.createPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, address(testToken), 500e18, expiration); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); + ICampaignPaymentTreasury.ExternalFees[] memory emptyExternalFees = new ICampaignPaymentTreasury.ExternalFees[](0); + paymentTreasury.createPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, address(testToken), 500e18, expiration, emptyLineItems, emptyExternalFees); + paymentTreasury.createPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, address(testToken), 500e18, expiration, emptyLineItems, emptyExternalFees); vm.stopPrank(); // Send only 500 tokens @@ -1007,14 +1213,16 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te deal(address(usdcToken), users.backer1Address, usdcAmount); vm.prank(users.backer1Address); usdcToken.approve(treasuryAddress, usdcAmount); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); processCryptoPayment( users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(usdcToken), - usdcAmount - ); + usdcAmount, + emptyLineItems + , new ICampaignPaymentTreasury.ExternalFees[](0)); // cUSD payment deal(address(cUSDToken), users.backer2Address, cUSDAmount); @@ -1026,8 +1234,9 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te ITEM_ID_2, users.backer2Address, address(cUSDToken), - cUSDAmount - ); + cUSDAmount, + emptyLineItems + , new ICampaignPaymentTreasury.ExternalFees[](0)); uint256 expectedTotal = 800e18 + 1200e18; assertEq(paymentTreasury.getRaisedAmount(), expectedTotal); @@ -1229,6 +1438,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te // Create two payments expecting USDT _createAndFundPaymentWithToken(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, usdtAmount, users.backer1Address, address(usdtToken)); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( PAYMENT_ID_2, @@ -1236,7 +1446,9 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te ITEM_ID_2, address(usdtToken), // Token specified usdtAmount, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); // Only funded first payment, second has no tokens @@ -1348,8 +1560,16 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te expirations[2] = block.timestamp + 3 days; // Execute batch creation - vm.prank(users.platform1AdminAddress); - paymentTreasury.createPaymentBatch(paymentIds, buyerIds, itemIds, _createPaymentTokensArray(3, address(testToken)), amounts, expirations); + ICampaignPaymentTreasury.LineItem[][] memory emptyLineItemsArray = new ICampaignPaymentTreasury.LineItem[][](3); + emptyLineItemsArray[0] = new ICampaignPaymentTreasury.LineItem[](0); + emptyLineItemsArray[1] = new ICampaignPaymentTreasury.LineItem[](0); + emptyLineItemsArray[2] = new ICampaignPaymentTreasury.LineItem[](0); + vm.prank(users.platform1AdminAddress); + ICampaignPaymentTreasury.ExternalFees[][] memory emptyExternalFeesArray = new ICampaignPaymentTreasury.ExternalFees[][](3); + for (uint256 i = 0; i < 3; i++) { + emptyExternalFeesArray[i] = new ICampaignPaymentTreasury.ExternalFees[](0); + } + paymentTreasury.createPaymentBatch(paymentIds, buyerIds, itemIds, _createPaymentTokensArray(3, address(testToken)), amounts, expirations, emptyLineItemsArray, emptyExternalFeesArray); // Verify that payments were created by checking raised amount is still 0 (not confirmed yet) assertEq(paymentTreasury.getRaisedAmount(), 0); @@ -1363,9 +1583,17 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te uint256[] memory amounts = new uint256[](2); uint256[] memory expirations = new uint256[](2); + ICampaignPaymentTreasury.LineItem[][] memory emptyLineItemsArray = new ICampaignPaymentTreasury.LineItem[][](paymentIds.length); + for (uint256 i = 0; i < paymentIds.length; i++) { + emptyLineItemsArray[i] = new ICampaignPaymentTreasury.LineItem[](0); + } vm.prank(users.platform1AdminAddress); + ICampaignPaymentTreasury.ExternalFees[][] memory emptyExternalFeesArray = new ICampaignPaymentTreasury.ExternalFees[][](paymentIds.length); + for (uint256 i = 0; i < paymentIds.length; i++) { + emptyExternalFeesArray[i] = new ICampaignPaymentTreasury.ExternalFees[](0); + } vm.expectRevert(); - paymentTreasury.createPaymentBatch(paymentIds, buyerIds, itemIds, _createPaymentTokensArray(paymentIds.length, address(testToken)), amounts, expirations); + paymentTreasury.createPaymentBatch(paymentIds, buyerIds, itemIds, _createPaymentTokensArray(paymentIds.length, address(testToken)), amounts, expirations, emptyLineItemsArray, emptyExternalFeesArray); } function testCreatePaymentBatchRevertWhenEmptyArray() public { @@ -1375,22 +1603,33 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te uint256[] memory amounts = new uint256[](0); uint256[] memory expirations = new uint256[](0); + ICampaignPaymentTreasury.LineItem[][] memory emptyLineItemsArray = new ICampaignPaymentTreasury.LineItem[][](paymentIds.length); + for (uint256 i = 0; i < paymentIds.length; i++) { + emptyLineItemsArray[i] = new ICampaignPaymentTreasury.LineItem[](0); + } + ICampaignPaymentTreasury.ExternalFees[][] memory emptyExternalFeesArray = new ICampaignPaymentTreasury.ExternalFees[][](paymentIds.length); + for (uint256 i = 0; i < paymentIds.length; i++) { + emptyExternalFeesArray[i] = new ICampaignPaymentTreasury.ExternalFees[](0); + } vm.prank(users.platform1AdminAddress); vm.expectRevert(); - paymentTreasury.createPaymentBatch(paymentIds, buyerIds, itemIds, _createPaymentTokensArray(paymentIds.length, address(testToken)), amounts, expirations); + paymentTreasury.createPaymentBatch(paymentIds, buyerIds, itemIds, _createPaymentTokensArray(paymentIds.length, address(testToken)), amounts, expirations, emptyLineItemsArray, emptyExternalFeesArray); } function testCreatePaymentBatchRevertWhenPaymentAlreadyExists() public { // First create a single payment uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.prank(users.platform1AdminAddress); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); paymentTreasury.createPayment( PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); // Now try to create a batch with the same payment ID @@ -1406,9 +1645,17 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te amounts[0] = PAYMENT_AMOUNT_2; expirations[0] = block.timestamp + 2 days; + ICampaignPaymentTreasury.LineItem[][] memory emptyLineItemsArray = new ICampaignPaymentTreasury.LineItem[][](paymentIds.length); + for (uint256 i = 0; i < paymentIds.length; i++) { + emptyLineItemsArray[i] = new ICampaignPaymentTreasury.LineItem[](0); + } + ICampaignPaymentTreasury.ExternalFees[][] memory emptyExternalFeesArray = new ICampaignPaymentTreasury.ExternalFees[][](paymentIds.length); + for (uint256 i = 0; i < paymentIds.length; i++) { + emptyExternalFeesArray[i] = new ICampaignPaymentTreasury.ExternalFees[](0); + } vm.prank(users.platform1AdminAddress); vm.expectRevert(); - paymentTreasury.createPaymentBatch(paymentIds, buyerIds, itemIds, _createPaymentTokensArray(paymentIds.length, address(testToken)), amounts, expirations); + paymentTreasury.createPaymentBatch(paymentIds, buyerIds, itemIds, _createPaymentTokensArray(paymentIds.length, address(testToken)), amounts, expirations, emptyLineItemsArray, emptyExternalFeesArray); } function testCreatePaymentBatchRevertWhenNotPlatformAdmin() public { @@ -1424,9 +1671,17 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te amounts[0] = PAYMENT_AMOUNT_1; expirations[0] = block.timestamp + 1 days; + ICampaignPaymentTreasury.LineItem[][] memory emptyLineItemsArray = new ICampaignPaymentTreasury.LineItem[][](paymentIds.length); + for (uint256 i = 0; i < paymentIds.length; i++) { + emptyLineItemsArray[i] = new ICampaignPaymentTreasury.LineItem[](0); + } + ICampaignPaymentTreasury.ExternalFees[][] memory emptyExternalFeesArray = new ICampaignPaymentTreasury.ExternalFees[][](paymentIds.length); + for (uint256 i = 0; i < paymentIds.length; i++) { + emptyExternalFeesArray[i] = new ICampaignPaymentTreasury.ExternalFees[](0); + } vm.prank(users.creator1Address); // Not platform admin vm.expectRevert(); - paymentTreasury.createPaymentBatch(paymentIds, buyerIds, itemIds, _createPaymentTokensArray(paymentIds.length, address(testToken)), amounts, expirations); + paymentTreasury.createPaymentBatch(paymentIds, buyerIds, itemIds, _createPaymentTokensArray(paymentIds.length, address(testToken)), amounts, expirations, emptyLineItemsArray, emptyExternalFeesArray); } function testCreatePaymentBatchWithMultipleTokens() public { @@ -1464,8 +1719,16 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te expirations[2] = block.timestamp + 3 days; // Execute batch creation with multiple tokens - vm.prank(users.platform1AdminAddress); - paymentTreasury.createPaymentBatch(paymentIds, buyerIds, itemIds, paymentTokens, amounts, expirations); + ICampaignPaymentTreasury.LineItem[][] memory emptyLineItemsArray = new ICampaignPaymentTreasury.LineItem[][](3); + emptyLineItemsArray[0] = new ICampaignPaymentTreasury.LineItem[](0); + emptyLineItemsArray[1] = new ICampaignPaymentTreasury.LineItem[](0); + emptyLineItemsArray[2] = new ICampaignPaymentTreasury.LineItem[](0); + vm.prank(users.platform1AdminAddress); + ICampaignPaymentTreasury.ExternalFees[][] memory externalFeesArray = new ICampaignPaymentTreasury.ExternalFees[][](3); + externalFeesArray[0] = new ICampaignPaymentTreasury.ExternalFees[](0); + externalFeesArray[1] = new ICampaignPaymentTreasury.ExternalFees[](0); + externalFeesArray[2] = new ICampaignPaymentTreasury.ExternalFees[](0); + paymentTreasury.createPaymentBatch(paymentIds, buyerIds, itemIds, paymentTokens, amounts, expirations, emptyLineItemsArray, externalFeesArray); // Verify that payments were created assertEq(paymentTreasury.getRaisedAmount(), 0); diff --git a/test/foundry/unit/TimeConstrainedPaymentTreasury.t.sol b/test/foundry/unit/TimeConstrainedPaymentTreasury.t.sol index 9f37b562..12ad8564 100644 --- a/test/foundry/unit/TimeConstrainedPaymentTreasury.t.sol +++ b/test/foundry/unit/TimeConstrainedPaymentTreasury.t.sol @@ -86,6 +86,7 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment advanceToWithinRange(); uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.createPayment( PAYMENT_ID_1, @@ -93,9 +94,10 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); - // Payment created successfully assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); assertEq(timeConstrainedPaymentTreasury.getAvailableRaisedAmount(), 0); @@ -105,6 +107,7 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment advanceToBeforeLaunch(); uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.expectRevert(); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.createPayment( @@ -113,7 +116,9 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); } @@ -121,6 +126,7 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment advanceToAfterDeadline(); uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.expectRevert(); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.createPayment( @@ -129,7 +135,9 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); } @@ -158,14 +166,23 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment expirations[0] = block.timestamp + PAYMENT_EXPIRATION; expirations[1] = block.timestamp + PAYMENT_EXPIRATION; + ICampaignPaymentTreasury.LineItem[][] memory emptyLineItemsArray = new ICampaignPaymentTreasury.LineItem[][](2); + emptyLineItemsArray[0] = new ICampaignPaymentTreasury.LineItem[](0); + emptyLineItemsArray[1] = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); + ICampaignPaymentTreasury.ExternalFees[][] memory externalFeesArray = new ICampaignPaymentTreasury.ExternalFees[][](2); + externalFeesArray[0] = new ICampaignPaymentTreasury.ExternalFees[](0); + externalFeesArray[1] = new ICampaignPaymentTreasury.ExternalFees[](0); timeConstrainedPaymentTreasury.createPaymentBatch( paymentIds, buyerIds, itemIds, paymentTokens, amounts, - expirations + expirations, + emptyLineItemsArray, + + externalFeesArray ); // Payments created successfully @@ -192,6 +209,10 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment uint256[] memory expirations = new uint256[](1); expirations[0] = block.timestamp + PAYMENT_EXPIRATION; + ICampaignPaymentTreasury.LineItem[][] memory emptyLineItemsArray = new ICampaignPaymentTreasury.LineItem[][](1); + emptyLineItemsArray[0] = new ICampaignPaymentTreasury.LineItem[](0); + ICampaignPaymentTreasury.ExternalFees[][] memory externalFeesArray = new ICampaignPaymentTreasury.ExternalFees[][](1); + externalFeesArray[0] = new ICampaignPaymentTreasury.ExternalFees[](0); vm.expectRevert(); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.createPaymentBatch( @@ -200,7 +221,9 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment itemIds, paymentTokens, amounts, - expirations + expirations, + emptyLineItemsArray, + externalFeesArray ); } @@ -212,13 +235,15 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); vm.prank(users.platform1AdminAddress); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); timeConstrainedPaymentTreasury.processCryptoPayment( PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), - PAYMENT_AMOUNT_1 - ); + PAYMENT_AMOUNT_1, + emptyLineItems + , new ICampaignPaymentTreasury.ExternalFees[](0)); // Payment processed successfully assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1); @@ -229,13 +254,15 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment vm.expectRevert(); vm.prank(users.platform1AdminAddress); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); timeConstrainedPaymentTreasury.processCryptoPayment( PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), - PAYMENT_AMOUNT_1 - ); + PAYMENT_AMOUNT_1, + emptyLineItems + , new ICampaignPaymentTreasury.ExternalFees[](0)); } function testCancelPaymentWithinTimeRange() public { @@ -243,6 +270,7 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment // First create a payment uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.createPayment( PAYMENT_ID_1, @@ -250,9 +278,10 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); - // Then cancel it vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.cancelPayment(PAYMENT_ID_1); @@ -277,13 +306,15 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); vm.prank(users.platform1AdminAddress); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); timeConstrainedPaymentTreasury.processCryptoPayment( PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), - PAYMENT_AMOUNT_1 - ); + PAYMENT_AMOUNT_1, + emptyLineItems + , new ICampaignPaymentTreasury.ExternalFees[](0)); // Payment created and confirmed successfully by processCryptoPayment assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1); @@ -305,25 +336,29 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); vm.prank(users.platform1AdminAddress); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); timeConstrainedPaymentTreasury.processCryptoPayment( PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), - PAYMENT_AMOUNT_1 - ); + PAYMENT_AMOUNT_1, + emptyLineItems + , new ICampaignPaymentTreasury.ExternalFees[](0)); vm.prank(users.backer2Address); testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_2); vm.prank(users.platform1AdminAddress); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems2 = new ICampaignPaymentTreasury.LineItem[](0); timeConstrainedPaymentTreasury.processCryptoPayment( PAYMENT_ID_2, ITEM_ID_2, users.backer2Address, address(testToken), - PAYMENT_AMOUNT_2 - ); + PAYMENT_AMOUNT_2, + emptyLineItems2 + , new ICampaignPaymentTreasury.ExternalFees[](0)); // Payments created and confirmed successfully by processCryptoPayment assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2); @@ -353,13 +388,15 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); vm.prank(users.platform1AdminAddress); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); timeConstrainedPaymentTreasury.processCryptoPayment( PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), - PAYMENT_AMOUNT_1 - ); + PAYMENT_AMOUNT_1, + emptyLineItems + , new ICampaignPaymentTreasury.ExternalFees[](0)); // Advance to after launch to be able to claim refund advanceToAfterLaunch(); @@ -393,13 +430,15 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); vm.prank(users.platform1AdminAddress); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); timeConstrainedPaymentTreasury.processCryptoPayment( PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), - PAYMENT_AMOUNT_1 - ); + PAYMENT_AMOUNT_1, + emptyLineItems + , new ICampaignPaymentTreasury.ExternalFees[](0)); // Advance to after launch time advanceToAfterLaunch(); @@ -428,13 +467,15 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); vm.prank(users.platform1AdminAddress); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); timeConstrainedPaymentTreasury.processCryptoPayment( PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), - PAYMENT_AMOUNT_1 - ); + PAYMENT_AMOUNT_1, + emptyLineItems + , new ICampaignPaymentTreasury.ExternalFees[](0)); // Advance to after launch time advanceToAfterLaunch(); @@ -465,6 +506,7 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment vm.warp(campaignDeadline - 1); // Use deadline - 1 to be within range uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.createPayment( PAYMENT_ID_1, @@ -472,9 +514,10 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); - // Should succeed at deadline - 1 assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); } @@ -484,6 +527,7 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment vm.warp(campaignDeadline - 1); // Use deadline - 1 to be within range uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.createPayment( PAYMENT_ID_1, @@ -491,9 +535,10 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); - // Should succeed at deadline - 1 assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); } @@ -503,6 +548,7 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment advanceToAfterDeadline(); uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.expectRevert(); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.createPayment( @@ -511,7 +557,9 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); } @@ -524,6 +572,7 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment vm.warp(campaignLaunchTime); uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.createPayment( PAYMENT_ID_1, @@ -531,9 +580,10 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); - // Should succeed at the exact launch time assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); } @@ -543,6 +593,7 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment vm.warp(campaignDeadline); uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.createPayment( PAYMENT_ID_1, @@ -550,9 +601,10 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment ITEM_ID_1, address(testToken), PAYMENT_AMOUNT_1, - expiration + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) ); - // Should succeed at the exact deadline assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); } @@ -566,13 +618,15 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); vm.prank(users.platform1AdminAddress); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); timeConstrainedPaymentTreasury.processCryptoPayment( PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), - PAYMENT_AMOUNT_1 - ); + PAYMENT_AMOUNT_1, + emptyLineItems + , new ICampaignPaymentTreasury.ExternalFees[](0)); // Advance to after launch time advanceToAfterLaunch(); From de4ca271b1bf751f259247f474ba80cab077fce1 Mon Sep 17 00:00:00 2001 From: mahabubAlahi <32974385+mahabubAlahi@users.noreply.github.com> Date: Wed, 12 Nov 2025 13:39:55 +0600 Subject: [PATCH 51/63] Update contract documentation (#43) - Introduced new sections in SUMMARY.md and README.md for constants and storage, enhancing documentation structure. - Added DataRegistryKeys and various storage contracts (AdminAccessCheckerStorage, CampaignInfoFactoryStorage, GlobalParamsStorage, TreasuryFactoryStorage) to improve organization and accessibility of key data. - Updated CampaignInfo and CampaignInfoFactory documentation to reflect recent changes and ensure consistency. - Enhanced utility functions and interfaces to support new storage structures and constants, improving overall code maintainability and clarity. --- docs/src/SUMMARY.md | 9 + .../CampaignInfo.sol/contract.CampaignInfo.md | 383 ++++++++++-- .../contract.CampaignInfoFactory.md | 78 +-- .../GlobalParams.sol/contract.GlobalParams.md | 315 +++++++--- docs/src/src/README.md | 2 + .../contract.TreasuryFactory.md | 61 +- .../library.DataRegistryKeys.md | 61 ++ docs/src/src/constants/README.md | 4 + .../interface.ICampaignData.md | 12 +- .../interface.ICampaignInfo.md | 294 ++++++++- .../interface.ICampaignInfoFactory.md | 20 +- .../interface.ICampaignPaymentTreasury.md | 259 +++++++- .../interface.ICampaignTreasury.md | 47 +- .../interface.IGlobalParams.md | 142 ++++- .../interfaces/IItem.sol/interface.IItem.md | 14 +- .../IReward.sol/interface.IReward.md | 2 +- .../interface.ITreasuryFactory.md | 29 +- .../library.AdminAccessCheckerStorage.md | 37 ++ .../library.CampaignInfoFactoryStorage.md | 41 ++ .../library.GlobalParamsStorage.md | 75 +++ docs/src/src/storage/README.md | 7 + .../library.TreasuryFactoryStorage.md | 38 ++ .../AllOrNothing.sol/contract.AllOrNothing.md | 135 ++--- .../contract.KeepWhatsRaised.md | 313 +++++----- .../contract.PaymentTreasury.md | 123 ++-- docs/src/src/treasuries/README.md | 1 + ...contract.TimeConstrainedPaymentTreasury.md | 289 +++++++++ .../abstract.AdminAccessChecker.md | 62 +- .../abstract.BasePaymentTreasury.md | 559 +++++++++++++++--- .../BaseTreasury.sol/abstract.BaseTreasury.md | 74 ++- .../abstract.CampaignAccessChecker.md | 42 +- .../utils/Counters.sol/library.Counters.md | 9 +- .../FiatEnabled.sol/abstract.FiatEnabled.md | 16 +- .../ItemRegistry.sol/contract.ItemRegistry.md | 12 +- .../abstract.PausableCancellable.md | 30 +- .../utils/PledgeNFT.sol/abstract.PledgeNFT.md | 383 ++++++++++++ docs/src/src/utils/README.md | 1 + .../abstract.TimestampChecker.md | 20 +- 38 files changed, 3247 insertions(+), 752 deletions(-) create mode 100644 docs/src/src/constants/DataRegistryKeys.sol/library.DataRegistryKeys.md create mode 100644 docs/src/src/constants/README.md create mode 100644 docs/src/src/storage/AdminAccessCheckerStorage.sol/library.AdminAccessCheckerStorage.md create mode 100644 docs/src/src/storage/CampaignInfoFactoryStorage.sol/library.CampaignInfoFactoryStorage.md create mode 100644 docs/src/src/storage/GlobalParamsStorage.sol/library.GlobalParamsStorage.md create mode 100644 docs/src/src/storage/README.md create mode 100644 docs/src/src/storage/TreasuryFactoryStorage.sol/library.TreasuryFactoryStorage.md create mode 100644 docs/src/src/treasuries/TimeConstrainedPaymentTreasury.sol/contract.TimeConstrainedPaymentTreasury.md create mode 100644 docs/src/src/utils/PledgeNFT.sol/abstract.PledgeNFT.md diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index ccec9b40..b8ac6e2f 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -1,6 +1,8 @@ # Summary - [Home](README.md) # src + - [❱ constants](src/constants/README.md) + - [DataRegistryKeys](src/constants/DataRegistryKeys.sol/library.DataRegistryKeys.md) - [❱ interfaces](src/interfaces/README.md) - [ICampaignData](src/interfaces/ICampaignData.sol/interface.ICampaignData.md) - [ICampaignInfo](src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md) @@ -11,10 +13,16 @@ - [IItem](src/interfaces/IItem.sol/interface.IItem.md) - [IReward](src/interfaces/IReward.sol/interface.IReward.md) - [ITreasuryFactory](src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md) + - [❱ storage](src/storage/README.md) + - [AdminAccessCheckerStorage](src/storage/AdminAccessCheckerStorage.sol/library.AdminAccessCheckerStorage.md) + - [CampaignInfoFactoryStorage](src/storage/CampaignInfoFactoryStorage.sol/library.CampaignInfoFactoryStorage.md) + - [GlobalParamsStorage](src/storage/GlobalParamsStorage.sol/library.GlobalParamsStorage.md) + - [TreasuryFactoryStorage](src/storage/TreasuryFactoryStorage.sol/library.TreasuryFactoryStorage.md) - [❱ treasuries](src/treasuries/README.md) - [AllOrNothing](src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md) - [KeepWhatsRaised](src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md) - [PaymentTreasury](src/treasuries/PaymentTreasury.sol/contract.PaymentTreasury.md) + - [TimeConstrainedPaymentTreasury](src/treasuries/TimeConstrainedPaymentTreasury.sol/contract.TimeConstrainedPaymentTreasury.md) - [❱ utils](src/utils/README.md) - [AdminAccessChecker](src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md) - [BasePaymentTreasury](src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md) @@ -24,6 +32,7 @@ - [FiatEnabled](src/utils/FiatEnabled.sol/abstract.FiatEnabled.md) - [ItemRegistry](src/utils/ItemRegistry.sol/contract.ItemRegistry.md) - [PausableCancellable](src/utils/PausableCancellable.sol/abstract.PausableCancellable.md) + - [PledgeNFT](src/utils/PledgeNFT.sol/abstract.PledgeNFT.md) - [TimestampChecker](src/utils/TimestampChecker.sol/abstract.TimestampChecker.md) - [CampaignInfo](src/CampaignInfo.sol/contract.CampaignInfo.md) - [CampaignInfoFactory](src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md) diff --git a/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md b/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md index cd7c451b..e3a41f4e 100644 --- a/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md +++ b/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md @@ -1,8 +1,8 @@ # CampaignInfo -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/CampaignInfo.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/CampaignInfo.sol) **Inherits:** -[ICampaignData](/src/interfaces/ICampaignData.sol/interface.ICampaignData.md), [ICampaignInfo](/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md), Ownable, [PausableCancellable](/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md), [TimestampChecker](/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), [AdminAccessChecker](/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md), Initializable +[ICampaignData](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md), [ICampaignInfo](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md), Ownable, [PausableCancellable](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md), [TimestampChecker](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), [AdminAccessChecker](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md), [PledgeNFT](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/PledgeNFT.sol/abstract.PledgeNFT.md), Initializable Manages campaign information and platform data. @@ -11,63 +11,70 @@ Manages campaign information and platform data. ### s_campaignData ```solidity -CampaignData private s_campaignData; +CampaignData private s_campaignData ``` ### s_platformTreasuryAddress ```solidity -mapping(bytes32 => address) private s_platformTreasuryAddress; +mapping(bytes32 => address) private s_platformTreasuryAddress ``` ### s_platformFeePercent ```solidity -mapping(bytes32 => uint256) private s_platformFeePercent; +mapping(bytes32 => uint256) private s_platformFeePercent ``` ### s_isSelectedPlatform ```solidity -mapping(bytes32 => bool) private s_isSelectedPlatform; +mapping(bytes32 => bool) private s_isSelectedPlatform ``` ### s_isApprovedPlatform ```solidity -mapping(bytes32 => bool) private s_isApprovedPlatform; +mapping(bytes32 => bool) private s_isApprovedPlatform ``` ### s_platformData ```solidity -mapping(bytes32 => bytes32) private s_platformData; +mapping(bytes32 => bytes32) private s_platformData ``` ### s_approvedPlatformHashes ```solidity -bytes32[] private s_approvedPlatformHashes; +bytes32[] private s_approvedPlatformHashes ``` ### s_acceptedTokens ```solidity -address[] private s_acceptedTokens; +address[] private s_acceptedTokens ``` ### s_isAcceptedToken ```solidity -mapping(address => bool) private s_isAcceptedToken; +mapping(address => bool) private s_isAcceptedToken +``` + + +### s_isLocked + +```solidity +bool private s_isLocked ``` @@ -79,11 +86,37 @@ mapping(address => bool) private s_isAcceptedToken; function getApprovedPlatformHashes() external view returns (bytes32[] memory); ``` +### isLocked + +Returns whether the campaign is locked (after treasury deployment). + + +```solidity +function isLocked() external view override returns (bool); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|True if the campaign is locked, false otherwise.| + + +### whenNotLocked + +Modifier that checks if the campaign is not locked. + + +```solidity +modifier whenNotLocked() ; +``` + ### constructor +Constructor passes empty strings to ERC721 + ```solidity -constructor() Ownable(_msgSender()); +constructor() Ownable(_msgSender()) ERC721("", ""); ``` ### initialize @@ -97,7 +130,11 @@ function initialize( bytes32[] calldata platformDataKey, bytes32[] calldata platformDataValue, CampaignData calldata campaignData, - address[] calldata acceptedTokens + address[] calldata acceptedTokens, + string calldata nftName, + string calldata nftSymbol, + string calldata nftImageURI, + string calldata nftContractURI ) external initializer; ``` @@ -131,7 +168,7 @@ function checkIfPlatformSelected(bytes32 platformHash) public view override retu ### checkIfPlatformApproved -*Check if a platform is already approved* +Check if a platform is already approved ```solidity @@ -182,7 +219,9 @@ function getProtocolAdminAddress() public view override returns (address); ### getTotalRaisedAmount -Retrieves the total amount raised in the campaign. +Retrieves the total amount raised across non-cancelled treasuries. + +This excludes cancelled treasuries and is affected by refunds. ```solidity @@ -195,6 +234,100 @@ function getTotalRaisedAmount() external view override returns (uint256); |``|`uint256`|The total amount raised in the campaign.| +### getTotalLifetimeRaisedAmount + +Retrieves the total lifetime raised amount across all treasuries. + +This amount never decreases even when refunds are processed. +It represents the sum of all pledges/payments ever made to the campaign, +regardless of cancellations or refunds. + + +```solidity +function getTotalLifetimeRaisedAmount() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The total lifetime raised amount as a uint256 value.| + + +### getTotalRefundedAmount + +Retrieves the total refunded amount across all treasuries. + +This is calculated as the difference between lifetime raised amount +and current raised amount. It represents the sum of all refunds +that have been processed across all treasuries. + + +```solidity +function getTotalRefundedAmount() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The total refunded amount as a uint256 value.| + + +### getTotalAvailableRaisedAmount + +Retrieves the total available raised amount across all treasuries. + +This includes funds from both active and cancelled treasuries, +and is affected by refunds. It represents the actual current +balance of funds across all treasuries. + + +```solidity +function getTotalAvailableRaisedAmount() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The total available raised amount as a uint256 value.| + + +### getTotalCancelledAmount + +Retrieves the total raised amount from cancelled treasuries only. + +This is the opposite of getTotalRaisedAmount(), which only includes +non-cancelled treasuries. This function only sums up raised amounts +from treasuries that have been cancelled. + + +```solidity +function getTotalCancelledAmount() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The total raised amount from cancelled treasuries as a uint256 value.| + + +### getTotalExpectedAmount + +Retrieves the total expected (pending) amount across payment treasuries. + +This only applies to payment treasuries and represents payments that +have been created but not yet confirmed. Regular treasuries are skipped. + + +```solidity +function getTotalExpectedAmount() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The total expected amount as a uint256 value.| + + ### getPlatformAdminAddress Retrieves the address of the platform administrator for a specific platform. @@ -329,7 +462,7 @@ function isTokenAccepted(address token) external view override returns (bool); ### paused -*Returns true if the campaign is paused, and false otherwise.* +Returns true if the campaign is paused, and false otherwise. ```solidity @@ -338,7 +471,7 @@ function paused() public view override(ICampaignInfo, PausableCancellable) retur ### cancelled -*Returns true if the campaign is cancelled, and false otherwise.* +Returns true if the campaign is cancelled, and false otherwise. ```solidity @@ -366,6 +499,27 @@ function getPlatformFeePercent(bytes32 platformHash) external view override retu |``|`uint256`|The platform fee percentage applied to the campaign on the platform.| +### getPlatformClaimDelay + +Retrieves the claim delay (in seconds) configured for the given platform. + + +```solidity +function getPlatformClaimDelay(bytes32 platformHash) external view override returns (uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`platformHash`|`bytes32`|The identifier of the platform.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The claim delay in seconds.| + + ### getPlatformData Retrieves platform-specific data for the campaign. @@ -402,10 +556,84 @@ function getIdentifierHash() external view override returns (bytes32); |``|`bytes32`|The bytes32 hash that uniquely identifies the campaign.| +### getDataFromRegistry + +Retrieves a value from the GlobalParams data registry. + + +```solidity +function getDataFromRegistry(bytes32 key) external view override returns (bytes32 value); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`key`|`bytes32`|The registry key.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`value`|`bytes32`|The registry value.| + + +### getBufferTime + +Retrieves the buffer time from the GlobalParams data registry. + + +```solidity +function getBufferTime() external view override returns (uint256 bufferTime); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`bufferTime`|`uint256`|The buffer time value.| + + +### getLineItemType + +Retrieves a platform-specific line item type configuration from GlobalParams. + + +```solidity +function getLineItemType(bytes32 platformHash, bytes32 typeId) + external + view + override + returns ( + bool exists, + string memory label, + bool countsTowardGoal, + bool applyProtocolFee, + bool canRefund, + bool instantTransfer + ); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`platformHash`|`bytes32`|The identifier of the platform.| +|`typeId`|`bytes32`|The identifier of the line item type.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`exists`|`bool`|Whether this line item type exists and is active.| +|`label`|`string`|The label identifier for the line item type.| +|`countsTowardGoal`|`bool`|Whether this line item counts toward the campaign goal.| +|`applyProtocolFee`|`bool`|Whether this line item is included in protocol fee calculation.| +|`canRefund`|`bool`|Whether this line item can be refunded.| +|`instantTransfer`|`bool`|Whether this line item amount can be instantly transferred.| + + ### transferOwnership -*Transfers ownership of the contract to a new account (`newOwner`). -Can only be called by the current owner.* +Transfers ownership of the contract to a new account (`newOwner`). +Can only be called by the current owner. ```solidity @@ -427,9 +655,9 @@ function updateLaunchTime(uint256 launchTime) external override onlyOwner - currentTimeIsLess(getLaunchTime()) whenNotPaused - whenNotCancelled; + whenNotCancelled + whenNotLocked; ``` **Parameters** @@ -444,13 +672,7 @@ Updates the campaign's deadline. ```solidity -function updateDeadline(uint256 deadline) - external - override - onlyOwner - currentTimeIsLess(getLaunchTime()) - whenNotPaused - whenNotCancelled; +function updateDeadline(uint256 deadline) external override onlyOwner whenNotPaused whenNotCancelled whenNotLocked; ``` **Parameters** @@ -469,9 +691,9 @@ function updateGoalAmount(uint256 goalAmount) external override onlyOwner - currentTimeIsLess(getLaunchTime()) whenNotPaused - whenNotCancelled; + whenNotCancelled + whenNotLocked; ``` **Parameters** @@ -484,7 +706,7 @@ function updateGoalAmount(uint256 goalAmount) Updates the selection status of a platform for the campaign. -*It can only be called for a platform if its not approved i.e. the platform treasury is not deployed* +It can only be called for a platform if its not approved i.e. the platform treasury is not deployed ```solidity @@ -507,7 +729,7 @@ function updateSelectedPlatform( ### _pauseCampaign -*External function to pause the campaign.* +External function to pause the campaign. ```solidity @@ -516,7 +738,7 @@ function _pauseCampaign(bytes32 message) external onlyProtocolAdmin; ### _unpauseCampaign -*External function to unpause the campaign.* +External function to unpause the campaign. ```solidity @@ -525,16 +747,79 @@ function _unpauseCampaign(bytes32 message) external onlyProtocolAdmin; ### _cancelCampaign -*External function to cancel the campaign.* +External function to cancel the campaign. ```solidity function _cancelCampaign(bytes32 message) external; ``` +### setImageURI + +Sets the image URI for NFT metadata + +Can only be updated before campaign launch + + +```solidity +function setImageURI(string calldata newImageURI) + external + override(ICampaignInfo, PledgeNFT) + onlyOwner + currentTimeIsLess(getLaunchTime()); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`newImageURI`|`string`|The new image URI| + + +### updateContractURI + +Updates the contract-level metadata URI + +Can only be updated before campaign launch + + +```solidity +function updateContractURI(string calldata newContractURI) + external + override(ICampaignInfo, PledgeNFT) + onlyOwner + currentTimeIsLess(getLaunchTime()); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`newContractURI`|`string`|The new contract URI| + + +### mintNFTForPledge + + +```solidity +function mintNFTForPledge( + address backer, + bytes32 reward, + address tokenAddress, + uint256 amount, + uint256 shippingFee, + uint256 tipAmount +) public override(ICampaignInfo, PledgeNFT) returns (uint256 tokenId); +``` + +### burn + + +```solidity +function burn(uint256 tokenId) public override(ICampaignInfo, PledgeNFT); +``` + ### _setPlatformInfo -*Sets platform information for the campaign.* +Sets platform information for the campaign and grants treasury role. ```solidity @@ -550,7 +835,7 @@ function _setPlatformInfo(bytes32 platformHash, address platformTreasuryAddress) ## Events ### CampaignInfoLaunchTimeUpdated -*Emitted when the launch time of the campaign is updated.* +Emitted when the launch time of the campaign is updated. ```solidity @@ -564,7 +849,7 @@ event CampaignInfoLaunchTimeUpdated(uint256 newLaunchTime); |`newLaunchTime`|`uint256`|The new launch time.| ### CampaignInfoDeadlineUpdated -*Emitted when the deadline of the campaign is updated.* +Emitted when the deadline of the campaign is updated. ```solidity @@ -578,7 +863,7 @@ event CampaignInfoDeadlineUpdated(uint256 newDeadline); |`newDeadline`|`uint256`|The new deadline.| ### CampaignInfoGoalAmountUpdated -*Emitted when the goal amount of the campaign is updated.* +Emitted when the goal amount of the campaign is updated. ```solidity @@ -592,7 +877,7 @@ event CampaignInfoGoalAmountUpdated(uint256 newGoalAmount); |`newGoalAmount`|`uint256`|The new goal amount.| ### CampaignInfoSelectedPlatformUpdated -*Emitted when the selection state of a platform is updated.* +Emitted when the selection state of a platform is updated. ```solidity @@ -607,7 +892,7 @@ event CampaignInfoSelectedPlatformUpdated(bytes32 indexed platformHash, bool sel |`selection`|`bool`|The new selection state.| ### CampaignInfoPlatformInfoUpdated -*Emitted when platform information is updated for the campaign.* +Emitted when platform information is updated for the campaign. ```solidity @@ -623,7 +908,7 @@ event CampaignInfoPlatformInfoUpdated(bytes32 indexed platformHash, address inde ## Errors ### CampaignInfoInvalidPlatformUpdate -*Emitted when an invalid platform update is attempted.* +Emitted when an invalid platform update is attempted. ```solidity @@ -638,7 +923,7 @@ error CampaignInfoInvalidPlatformUpdate(bytes32 platformHash, bool selection); |`selection`|`bool`|The selection state (true/false).| ### CampaignInfoUnauthorized -*Emitted when an unauthorized action is attempted.* +Emitted when an unauthorized action is attempted. ```solidity @@ -646,7 +931,7 @@ error CampaignInfoUnauthorized(); ``` ### CampaignInfoInvalidInput -*Emitted when an invalid input is detected.* +Emitted when an invalid input is detected. ```solidity @@ -654,7 +939,7 @@ error CampaignInfoInvalidInput(); ``` ### CampaignInfoPlatformNotSelected -*Emitted when a platform is not selected for the campaign.* +Emitted when a platform is not selected for the campaign. ```solidity @@ -668,7 +953,7 @@ error CampaignInfoPlatformNotSelected(bytes32 platformHash); |`platformHash`|`bytes32`|The bytes32 identifier of the platform.| ### CampaignInfoPlatformAlreadyApproved -*Emitted when a platform is already approved for the campaign.* +Emitted when a platform is already approved for the campaign. ```solidity @@ -681,6 +966,14 @@ error CampaignInfoPlatformAlreadyApproved(bytes32 platformHash); |----|----|-----------| |`platformHash`|`bytes32`|The bytes32 identifier of the platform.| +### CampaignInfoIsLocked +Emitted when an operation is attempted on a locked campaign. + + +```solidity +error CampaignInfoIsLocked(); +``` + ## Structs ### Config diff --git a/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md b/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md index 9c5701d6..3c019b4e 100644 --- a/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md +++ b/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md @@ -1,38 +1,22 @@ # CampaignInfoFactory -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/CampaignInfoFactory.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/CampaignInfoFactory.sol) **Inherits:** -Initializable, [ICampaignInfoFactory](/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md), OwnableUpgradeable, UUPSUpgradeable +Initializable, [ICampaignInfoFactory](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md), OwnableUpgradeable, UUPSUpgradeable Factory contract for creating campaign information contracts. -*UUPS Upgradeable contract with ERC-7201 namespaced storage* - - -## State Variables -### CAMPAIGN_INFO_FACTORY_STORAGE_LOCATION - -```solidity -bytes32 private constant CAMPAIGN_INFO_FACTORY_STORAGE_LOCATION = - 0x2857858a392b093e1f8b3f368c2276ce911f27cef445605a2932ebe945968d00; -``` +UUPS Upgradeable contract with ERC-7201 namespaced storage ## Functions -### _getCampaignInfoFactoryStorage - - -```solidity -function _getCampaignInfoFactoryStorage() private pure returns (CampaignInfoFactoryStorage storage $); -``` - ### constructor -*Constructor that disables initializers to prevent implementation contract initialization* +Constructor that disables initializers to prevent implementation contract initialization ```solidity -constructor(); +constructor() ; ``` ### initialize @@ -60,7 +44,7 @@ function initialize( ### _authorizeUpgrade -*Function that authorizes an upgrade to a new implementation* +Function that authorizes an upgrade to a new implementation ```solidity @@ -75,13 +59,13 @@ function _authorizeUpgrade(address newImplementation) internal override onlyOwne ### createCampaign -Creates a new campaign information contract. +Creates a new campaign with NFT -*IMPORTANT: Protocol and platform fees are retrieved at execution time and locked +IMPORTANT: Protocol and platform fees are retrieved at execution time and locked permanently in the campaign contract. Users should verify current fees before calling this function or using intermediate contracts that check fees haven't changed from expected values. The protocol fee is stored as immutable in the cloned -contract and platform fees are stored during initialization.* +contract and platform fees are stored during initialization. ```solidity @@ -91,19 +75,27 @@ function createCampaign( bytes32[] calldata selectedPlatformHash, bytes32[] calldata platformDataKey, bytes32[] calldata platformDataValue, - CampaignData calldata campaignData + CampaignData calldata campaignData, + string calldata nftName, + string calldata nftSymbol, + string calldata nftImageURI, + string calldata contractURI ) external override; ``` **Parameters** |Name|Type|Description| |----|----|-----------| -|`creator`|`address`|The address of the creator of the campaign.| -|`identifierHash`|`bytes32`|The unique identifier hash of the campaign.| -|`selectedPlatformHash`|`bytes32[]`|An array of platform identifiers selected for the campaign.| -|`platformDataKey`|`bytes32[]`|An array of platform-specific data keys.| -|`platformDataValue`|`bytes32[]`|An array of platform-specific data values.| -|`campaignData`|`CampaignData`|The struct containing campaign launch details (including currency).| +|`creator`|`address`|The campaign creator address| +|`identifierHash`|`bytes32`|The unique identifier hash for the campaign| +|`selectedPlatformHash`|`bytes32[]`|Array of selected platform hashes| +|`platformDataKey`|`bytes32[]`|Array of platform data keys| +|`platformDataValue`|`bytes32[]`|Array of platform data values| +|`campaignData`|`CampaignData`|The campaign data| +|`nftName`|`string`|NFT collection name| +|`nftSymbol`|`string`|NFT collection symbol| +|`nftImageURI`|`string`|NFT image URI for individual tokens| +|`contractURI`|`string`|IPFS URI for contract-level metadata (constructed off-chain)| ### updateImplementation @@ -165,7 +157,7 @@ function identifierToCampaignInfo(bytes32 identifierHash) external view returns ## Errors ### CampaignInfoFactoryInvalidInput -*Emitted when invalid input is provided.* +Emitted when invalid input is provided. ```solidity @@ -173,7 +165,7 @@ error CampaignInfoFactoryInvalidInput(); ``` ### CampaignInfoFactoryCampaignInitializationFailed -*Emitted when campaign creation fails.* +Emitted when campaign creation fails. ```solidity @@ -193,26 +185,10 @@ error CampaignInfoFactoryCampaignWithSameIdentifierExists(bytes32 identifierHash ``` ### CampaignInfoInvalidTokenList -*Emitted when the campaign currency has no tokens.* +Emitted when the campaign currency has no tokens. ```solidity error CampaignInfoInvalidTokenList(); ``` -## Structs -### CampaignInfoFactoryStorage -**Note:** -storage-location: erc7201:ccprotocol.storage.CampaignInfoFactory - - -```solidity -struct CampaignInfoFactoryStorage { - IGlobalParams globalParams; - address treasuryFactoryAddress; - address implementation; - mapping(address => bool) isValidCampaignInfo; - mapping(bytes32 => address) identifierToCampaignInfo; -} -``` - diff --git a/docs/src/src/GlobalParams.sol/contract.GlobalParams.md b/docs/src/src/GlobalParams.sol/contract.GlobalParams.md index 4a19700f..900cb777 100644 --- a/docs/src/src/GlobalParams.sol/contract.GlobalParams.md +++ b/docs/src/src/GlobalParams.sol/contract.GlobalParams.md @@ -1,55 +1,40 @@ # GlobalParams -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/GlobalParams.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/GlobalParams.sol) **Inherits:** -Initializable, [IGlobalParams](/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md), OwnableUpgradeable, UUPSUpgradeable +Initializable, [IGlobalParams](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md), OwnableUpgradeable, UUPSUpgradeable Manages global parameters and platform information. -*UUPS Upgradeable contract with ERC-7201 namespaced storage* +UUPS Upgradeable contract with ERC-7201 namespaced storage ## State Variables -### GLOBAL_PARAMS_STORAGE_LOCATION - -```solidity -bytes32 private constant GLOBAL_PARAMS_STORAGE_LOCATION = - 0x83d0145f7c1378f10048390769ec94f999b3ba6d94904b8fd7251512962b1c00; -``` - - ### ZERO_BYTES ```solidity -bytes32 private constant ZERO_BYTES = 0x0000000000000000000000000000000000000000000000000000000000000000; +bytes32 private constant ZERO_BYTES = 0x0000000000000000000000000000000000000000000000000000000000000000 ``` ## Functions -### _getGlobalParamsStorage - - -```solidity -function _getGlobalParamsStorage() private pure returns (GlobalParamsStorage storage $); -``` - ### notAddressZero -*Reverts if the input address is zero.* +Reverts if the input address is zero. ```solidity -modifier notAddressZero(address account); +modifier notAddressZero(address account) ; ``` ### onlyPlatformAdmin -*Modifier that restricts function access to platform administrators of a specific platform. -Users attempting to execute functions with this modifier must be the platform admin for the given platform.* +Modifier that restricts function access to platform administrators of a specific platform. +Users attempting to execute functions with this modifier must be the platform admin for the given platform. ```solidity -modifier onlyPlatformAdmin(bytes32 platformHash); +modifier onlyPlatformAdmin(bytes32 platformHash) ; ``` **Parameters** @@ -62,21 +47,21 @@ modifier onlyPlatformAdmin(bytes32 platformHash); ```solidity -modifier platformIsListed(bytes32 platformHash); +modifier platformIsListed(bytes32 platformHash) ; ``` ### constructor -*Constructor that disables initializers to prevent implementation contract initialization* +Constructor that disables initializers to prevent implementation contract initialization ```solidity -constructor(); +constructor() ; ``` ### initialize -*Initializer function (replaces constructor)* +Initializer function (replaces constructor) ```solidity @@ -99,7 +84,7 @@ function initialize( ### _authorizeUpgrade -*Function that authorizes an upgrade to a new implementation* +Function that authorizes an upgrade to a new implementation ```solidity @@ -246,6 +231,32 @@ function getPlatformFeePercent(bytes32 platformHash) |`platformFeePercent`|`uint256`|The platform fee percentage as a uint256 value.| +### getPlatformClaimDelay + +Retrieves the claim delay (in seconds) for a specific platform. + + +```solidity +function getPlatformClaimDelay(bytes32 platformHash) + external + view + override + platformIsListed(platformHash) + returns (uint256 claimDelay); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`platformHash`|`bytes32`|The unique identifier of the platform.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`claimDelay`|`uint256`|The claim delay in seconds.| + + ### getPlatformDataOwner Retrieves the owner of platform-specific data. @@ -313,7 +324,7 @@ function checkIfPlatformDataKeyValid(bytes32 platformDataKey) external view over Enlists a platform with its admin address and fee percentage. -*The platformFeePercent can be any value including zero.* +The platformFeePercent can be any value including zero. ```solidity @@ -439,6 +450,26 @@ function updatePlatformAdminAddress(bytes32 platformHash, address platformAdminA |`platformAdminAddress`|`address`|| +### updatePlatformClaimDelay + +Updates the claim delay for a specific platform. + + +```solidity +function updatePlatformClaimDelay(bytes32 platformHash, uint256 claimDelay) + external + override + platformIsListed(platformHash) + onlyPlatformAdmin(platformHash); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`platformHash`|`bytes32`|The unique identifier of the platform.| +|`claimDelay`|`uint256`|The claim delay in seconds.| + + ### addTokenToCurrency Adds a token to a currency. @@ -461,7 +492,11 @@ Removes a token from a currency. ```solidity -function removeTokenFromCurrency(bytes32 currency, address token) external override onlyOwner notAddressZero(token); +function removeTokenFromCurrency(bytes32 currency, address token) + external + override + onlyOwner + notAddressZero(token); ``` **Parameters** @@ -492,9 +527,98 @@ function getTokensForCurrency(bytes32 currency) external view override returns ( |``|`address[]`|An array of token addresses accepted for the currency.| +### setPlatformLineItemType + +Sets or updates a platform-specific line item type configuration. + +Only callable by the platform admin. + + +```solidity +function setPlatformLineItemType( + bytes32 platformHash, + bytes32 typeId, + string calldata label, + bool countsTowardGoal, + bool applyProtocolFee, + bool canRefund, + bool instantTransfer +) external platformIsListed(platformHash) onlyPlatformAdmin(platformHash); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`platformHash`|`bytes32`|The identifier of the platform.| +|`typeId`|`bytes32`|The identifier of the line item type.| +|`label`|`string`|The label identifier for the line item type.| +|`countsTowardGoal`|`bool`|Whether this line item counts toward the campaign goal.| +|`applyProtocolFee`|`bool`|Whether this line item is included in protocol fee calculation.| +|`canRefund`|`bool`|Whether this line item can be refunded.| +|`instantTransfer`|`bool`|Whether this line item amount can be instantly transferred. Constraints: - If countsTowardGoal is true, then applyProtocolFee must be false, canRefund must be true, and instantTransfer must be false. - Non-goal instant transfer items cannot be refundable.| + + +### removePlatformLineItemType + +Removes a platform-specific line item type by setting its exists flag to false. + +Only callable by the platform admin. This prevents the type from being used in new pledges. + + +```solidity +function removePlatformLineItemType(bytes32 platformHash, bytes32 typeId) + external + platformIsListed(platformHash) + onlyPlatformAdmin(platformHash); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`platformHash`|`bytes32`|The identifier of the platform.| +|`typeId`|`bytes32`|The identifier of the line item type to remove.| + + +### getPlatformLineItemType + +Retrieves a platform-specific line item type configuration. + + +```solidity +function getPlatformLineItemType(bytes32 platformHash, bytes32 typeId) + external + view + returns ( + bool exists, + string memory label, + bool countsTowardGoal, + bool applyProtocolFee, + bool canRefund, + bool instantTransfer + ); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`platformHash`|`bytes32`|The identifier of the platform.| +|`typeId`|`bytes32`|The identifier of the line item type.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`exists`|`bool`|Whether this line item type exists and is active.| +|`label`|`string`|The label identifier for the line item type.| +|`countsTowardGoal`|`bool`|Whether this line item counts toward the campaign goal.| +|`applyProtocolFee`|`bool`|Whether this line item is included in protocol fee calculation.| +|`canRefund`|`bool`|Whether this line item can be refunded.| +|`instantTransfer`|`bool`|Whether this line item amount can be instantly transferred to platform admin after payment confirmation.| + + ### _revertIfAddressZero -*Reverts if the input address is zero.* +Reverts if the input address is zero. ```solidity @@ -503,8 +627,8 @@ function _revertIfAddressZero(address account) internal pure; ### _onlyPlatformAdmin -*Internal function to check if the sender is the platform administrator for a specific platform. -If the sender is not the platform admin, it reverts with AdminAccessCheckerUnauthorized error.* +Internal function to check if the sender is the platform administrator for a specific platform. +If the sender is not the platform admin, it reverts with GlobalParamsUnauthorized error. ```solidity @@ -519,11 +643,13 @@ function _onlyPlatformAdmin(bytes32 platformHash) private view; ## Events ### PlatformEnlisted -*Emitted when a platform is enlisted.* +Emitted when a platform is enlisted. ```solidity -event PlatformEnlisted(bytes32 indexed platformHash, address indexed platformAdminAddress, uint256 platformFeePercent); +event PlatformEnlisted( + bytes32 indexed platformHash, address indexed platformAdminAddress, uint256 platformFeePercent +); ``` **Parameters** @@ -535,7 +661,7 @@ event PlatformEnlisted(bytes32 indexed platformHash, address indexed platformAdm |`platformFeePercent`|`uint256`|The fee percentage of the enlisted platform.| ### PlatformDelisted -*Emitted when a platform is delisted.* +Emitted when a platform is delisted. ```solidity @@ -549,7 +675,7 @@ event PlatformDelisted(bytes32 indexed platformHash); |`platformHash`|`bytes32`|The identifier of the delisted platform.| ### ProtocolAdminAddressUpdated -*Emitted when the protocol admin address is updated.* +Emitted when the protocol admin address is updated. ```solidity @@ -563,7 +689,7 @@ event ProtocolAdminAddressUpdated(address indexed newAdminAddress); |`newAdminAddress`|`address`|The new protocol admin address.| ### TokenAddedToCurrency -*Emitted when a token is added to a currency.* +Emitted when a token is added to a currency. ```solidity @@ -578,7 +704,7 @@ event TokenAddedToCurrency(bytes32 indexed currency, address indexed token); |`token`|`address`|The token address added.| ### TokenRemovedFromCurrency -*Emitted when a token is removed from a currency.* +Emitted when a token is removed from a currency. ```solidity @@ -593,7 +719,7 @@ event TokenRemovedFromCurrency(bytes32 indexed currency, address indexed token); |`token`|`address`|The token address removed.| ### ProtocolFeePercentUpdated -*Emitted when the protocol fee percent is updated.* +Emitted when the protocol fee percent is updated. ```solidity @@ -607,7 +733,7 @@ event ProtocolFeePercentUpdated(uint256 newFeePercent); |`newFeePercent`|`uint256`|The new protocol fee percentage.| ### PlatformAdminAddressUpdated -*Emitted when the platform admin address is updated.* +Emitted when the platform admin address is updated. ```solidity @@ -622,7 +748,7 @@ event PlatformAdminAddressUpdated(bytes32 indexed platformHash, address indexed |`newAdminAddress`|`address`|The new admin address of the platform.| ### PlatformDataAdded -*Emitted when platform data is added.* +Emitted when platform data is added. ```solidity @@ -637,7 +763,7 @@ event PlatformDataAdded(bytes32 indexed platformHash, bytes32 indexed platformDa |`platformDataKey`|`bytes32`|The data key added to the platform.| ### PlatformDataRemoved -*Emitted when platform data is removed.* +Emitted when platform data is removed. ```solidity @@ -652,7 +778,7 @@ event PlatformDataRemoved(bytes32 indexed platformHash, bytes32 platformDataKey) |`platformDataKey`|`bytes32`|The data key removed from the platform.| ### DataAddedToRegistry -*Emitted when data is added to the registry.* +Emitted when data is added to the registry. ```solidity @@ -666,9 +792,58 @@ event DataAddedToRegistry(bytes32 indexed key, bytes32 value); |`key`|`bytes32`|The registry key.| |`value`|`bytes32`|The registry value.| +### PlatformLineItemTypeSet +Emitted when a platform-specific line item type is set or updated. + + +```solidity +event PlatformLineItemTypeSet( + bytes32 indexed platformHash, + bytes32 indexed typeId, + string label, + bool countsTowardGoal, + bool applyProtocolFee, + bool canRefund, + bool instantTransfer +); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`platformHash`|`bytes32`|The identifier of the platform.| +|`typeId`|`bytes32`|The identifier of the line item type.| +|`label`|`string`|The label of the line item type.| +|`countsTowardGoal`|`bool`|Whether this line item counts toward the campaign goal.| +|`applyProtocolFee`|`bool`|Whether this line item is included in protocol fee calculation.| +|`canRefund`|`bool`|Whether this line item can be refunded.| +|`instantTransfer`|`bool`|Whether this line item amount can be instantly transferred to platform admin after payment confirmation.| + +### PlatformClaimDelayUpdated + +```solidity +event PlatformClaimDelayUpdated(bytes32 indexed platformHash, uint256 claimDelay); +``` + +### PlatformLineItemTypeRemoved +Emitted when a platform-specific line item type is removed. + + +```solidity +event PlatformLineItemTypeRemoved(bytes32 indexed platformHash, bytes32 indexed typeId); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`platformHash`|`bytes32`|The identifier of the platform.| +|`typeId`|`bytes32`|The identifier of the removed line item type.| + ## Errors ### GlobalParamsInvalidInput -*Throws when the input address is zero.* +Throws when the input address is zero. ```solidity @@ -676,7 +851,7 @@ error GlobalParamsInvalidInput(); ``` ### GlobalParamsPlatformNotListed -*Throws when the platform is not listed.* +Throws when the platform is not listed. ```solidity @@ -690,7 +865,7 @@ error GlobalParamsPlatformNotListed(bytes32 platformHash); |`platformHash`|`bytes32`|The identifier of the platform.| ### GlobalParamsPlatformAlreadyListed -*Throws when the platform is already listed.* +Throws when the platform is already listed. ```solidity @@ -704,7 +879,7 @@ error GlobalParamsPlatformAlreadyListed(bytes32 platformHash); |`platformHash`|`bytes32`|The identifier of the platform.| ### GlobalParamsPlatformAdminNotSet -*Throws when the platform admin is not set.* +Throws when the platform admin is not set. ```solidity @@ -718,7 +893,7 @@ error GlobalParamsPlatformAdminNotSet(bytes32 platformHash); |`platformHash`|`bytes32`|The identifier of the platform.| ### GlobalParamsPlatformFeePercentIsZero -*Throws when the platform fee percent is zero.* +Throws when the platform fee percent is zero. ```solidity @@ -732,7 +907,7 @@ error GlobalParamsPlatformFeePercentIsZero(bytes32 platformHash); |`platformHash`|`bytes32`|The identifier of the platform.| ### GlobalParamsPlatformDataAlreadySet -*Throws when the platform data is already set.* +Throws when the platform data is already set. ```solidity @@ -740,7 +915,7 @@ error GlobalParamsPlatformDataAlreadySet(); ``` ### GlobalParamsPlatformDataNotSet -*Throws when the platform data is not set.* +Throws when the platform data is not set. ```solidity @@ -748,7 +923,7 @@ error GlobalParamsPlatformDataNotSet(); ``` ### GlobalParamsPlatformDataSlotTaken -*Throws when the platform data slot is already taken.* +Throws when the platform data slot is already taken. ```solidity @@ -756,7 +931,7 @@ error GlobalParamsPlatformDataSlotTaken(); ``` ### GlobalParamsUnauthorized -*Throws when the caller is not authorized.* +Throws when the caller is not authorized. ```solidity @@ -764,7 +939,7 @@ error GlobalParamsUnauthorized(); ``` ### GlobalParamsCurrencyTokenLengthMismatch -*Throws when currency and token arrays length mismatch.* +Throws when currency and token arrays length mismatch. ```solidity @@ -772,7 +947,7 @@ error GlobalParamsCurrencyTokenLengthMismatch(); ``` ### GlobalParamsCurrencyHasNoTokens -*Throws when a currency has no tokens registered.* +Throws when a currency has no tokens registered. ```solidity @@ -786,7 +961,7 @@ error GlobalParamsCurrencyHasNoTokens(bytes32 currency); |`currency`|`bytes32`|The currency identifier.| ### GlobalParamsTokenNotInCurrency -*Throws when a token is not found in a currency.* +Throws when a token is not found in a currency. ```solidity @@ -800,24 +975,18 @@ error GlobalParamsTokenNotInCurrency(bytes32 currency, address token); |`currency`|`bytes32`|The currency identifier.| |`token`|`address`|The token address.| -## Structs -### GlobalParamsStorage -**Note:** -storage-location: erc7201:ccprotocol.storage.GlobalParams +### GlobalParamsPlatformLineItemTypeNotFound +Throws when a platform-specific line item type is not found. ```solidity -struct GlobalParamsStorage { - address protocolAdminAddress; - uint256 protocolFeePercent; - mapping(bytes32 => bool) platformIsListed; - mapping(bytes32 => address) platformAdminAddress; - mapping(bytes32 => uint256) platformFeePercent; - mapping(bytes32 => bytes32) platformDataOwner; - mapping(bytes32 => bool) platformData; - mapping(bytes32 => bytes32) dataRegistry; - mapping(bytes32 => address[]) currencyToTokens; - Counters.Counter numberOfListedPlatforms; -} +error GlobalParamsPlatformLineItemTypeNotFound(bytes32 platformHash, bytes32 typeId); ``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`platformHash`|`bytes32`|The identifier of the platform.| +|`typeId`|`bytes32`|The identifier of the line item type.| + diff --git a/docs/src/src/README.md b/docs/src/src/README.md index 7592aab6..954c176d 100644 --- a/docs/src/src/README.md +++ b/docs/src/src/README.md @@ -1,7 +1,9 @@ # Contents +- [constants](/src/constants) - [interfaces](/src/interfaces) +- [storage](/src/storage) - [treasuries](/src/treasuries) - [utils](/src/utils) - [CampaignInfo](CampaignInfo.sol/contract.CampaignInfo.md) diff --git a/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md b/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md index 5c414cd0..4d9818de 100644 --- a/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md +++ b/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md @@ -1,38 +1,22 @@ # TreasuryFactory -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/TreasuryFactory.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/TreasuryFactory.sol) **Inherits:** -Initializable, [ITreasuryFactory](/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md), [AdminAccessChecker](/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md), UUPSUpgradeable +Initializable, [ITreasuryFactory](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md), [AdminAccessChecker](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md), UUPSUpgradeable Factory contract for creating treasury contracts -*UUPS Upgradeable contract with ERC-7201 namespaced storage* - - -## State Variables -### TREASURY_FACTORY_STORAGE_LOCATION - -```solidity -bytes32 private constant TREASURY_FACTORY_STORAGE_LOCATION = - 0x96b7de8c171ef460648aea35787d043e89feb6b6de2623a1e6f17a91b9c9e900; -``` +UUPS Upgradeable contract with ERC-7201 namespaced storage ## Functions -### _getTreasuryFactoryStorage - - -```solidity -function _getTreasuryFactoryStorage() private pure returns (TreasuryFactoryStorage storage $); -``` - ### constructor -*Constructor that disables initializers to prevent implementation contract initialization* +Constructor that disables initializers to prevent implementation contract initialization ```solidity -constructor(); +constructor() ; ``` ### initialize @@ -52,7 +36,7 @@ function initialize(IGlobalParams globalParams) public initializer; ### _authorizeUpgrade -*Function that authorizes an upgrade to a new implementation* +Function that authorizes an upgrade to a new implementation ```solidity @@ -69,7 +53,7 @@ function _authorizeUpgrade(address newImplementation) internal override onlyProt Registers a treasury implementation for a given platform. -*Callable only by the platform admin.* +Callable only by the platform admin. ```solidity @@ -91,7 +75,7 @@ function registerTreasuryImplementation(bytes32 platformHash, uint256 implementa Approves a previously registered implementation. -*Callable only by the protocol admin.* +Callable only by the protocol admin. ```solidity @@ -146,17 +130,15 @@ function removeTreasuryImplementation(bytes32 platformHash, uint256 implementati Deploys a treasury clone using an approved implementation. -*Callable only by the platform admin.* +Callable only by the platform admin. ```solidity -function deploy( - bytes32 platformHash, - address infoAddress, - uint256 implementationId, - string calldata name, - string calldata symbol -) external override onlyPlatformAdmin(platformHash) returns (address clone); +function deploy(bytes32 platformHash, address infoAddress, uint256 implementationId) + external + override + onlyPlatformAdmin(platformHash) + returns (address clone); ``` **Parameters** @@ -165,8 +147,6 @@ function deploy( |`platformHash`|`bytes32`|The platform identifier.| |`infoAddress`|`address`|The address of the campaign info contract.| |`implementationId`|`uint256`|The ID of the implementation to use.| -|`name`|`string`|The name of the treasury token.| -|`symbol`|`string`|The symbol of the treasury token.| **Returns** @@ -224,16 +204,3 @@ error TreasuryFactoryTreasuryInitializationFailed(); error TreasuryFactorySettingPlatformInfoFailed(); ``` -## Structs -### TreasuryFactoryStorage -**Note:** -storage-location: erc7201:ccprotocol.storage.TreasuryFactory - - -```solidity -struct TreasuryFactoryStorage { - mapping(bytes32 => mapping(uint256 => address)) implementationMap; - mapping(address => bool) approvedImplementations; -} -``` - diff --git a/docs/src/src/constants/DataRegistryKeys.sol/library.DataRegistryKeys.md b/docs/src/src/constants/DataRegistryKeys.sol/library.DataRegistryKeys.md new file mode 100644 index 00000000..8ab78b0e --- /dev/null +++ b/docs/src/src/constants/DataRegistryKeys.sol/library.DataRegistryKeys.md @@ -0,0 +1,61 @@ +# DataRegistryKeys +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/constants/DataRegistryKeys.sol) + +Centralized storage for all dataRegistry keys used in GlobalParams + +This library provides a single source of truth for all dataRegistry keys +to ensure consistency across contracts and prevent key collisions. + + +## State Variables +### BUFFER_TIME + +```solidity +bytes32 public constant BUFFER_TIME = keccak256("bufferTime") +``` + + +### MAX_PAYMENT_EXPIRATION + +```solidity +bytes32 public constant MAX_PAYMENT_EXPIRATION = keccak256("maxPaymentExpiration") +``` + + +### CAMPAIGN_LAUNCH_BUFFER + +```solidity +bytes32 public constant CAMPAIGN_LAUNCH_BUFFER = keccak256("campaignLaunchBuffer") +``` + + +### MINIMUM_CAMPAIGN_DURATION + +```solidity +bytes32 public constant MINIMUM_CAMPAIGN_DURATION = keccak256("minimumCampaignDuration") +``` + + +## Functions +### scopedToPlatform + +Generates a namespaced registry key scoped to a specific platform. + + +```solidity +function scopedToPlatform(bytes32 baseKey, bytes32 platformHash) internal pure returns (bytes32 platformKey); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`baseKey`|`bytes32`|The base registry key.| +|`platformHash`|`bytes32`|The identifier of the platform.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`platformKey`|`bytes32`|The platform-scoped registry key.| + + diff --git a/docs/src/src/constants/README.md b/docs/src/src/constants/README.md new file mode 100644 index 00000000..fd3796c8 --- /dev/null +++ b/docs/src/src/constants/README.md @@ -0,0 +1,4 @@ + + +# Contents +- [DataRegistryKeys](DataRegistryKeys.sol/library.DataRegistryKeys.md) diff --git a/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md b/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md index a605c9bf..92bc95df 100644 --- a/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md +++ b/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md @@ -1,20 +1,20 @@ # ICampaignData -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/interfaces/ICampaignData.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/interfaces/ICampaignData.sol) An interface for managing campaign data in a CCP. ## Structs ### CampaignData -*Struct to represent campaign data, including launch time, deadline, goal amount, and currency.* +Struct to represent campaign data, including launch time, deadline, goal amount, and currency. ```solidity struct CampaignData { - uint256 launchTime; - uint256 deadline; - uint256 goalAmount; - bytes32 currency; + uint256 launchTime; // Timestamp when the campaign is launched. + uint256 deadline; // Timestamp or block number when the campaign ends. + uint256 goalAmount; // Funding goal amount that the campaign aims to achieve. + bytes32 currency; // Currency identifier for the campaign (e.g., bytes32("USD")). } ``` diff --git a/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md b/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md index 1844c384..b4d83e83 100644 --- a/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md +++ b/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md @@ -1,8 +1,13 @@ # ICampaignInfo -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/interfaces/ICampaignInfo.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/interfaces/ICampaignInfo.sol) + +**Inherits:** +IERC721 An interface for managing campaign information in a crowdfunding system. +Inherits from IERC721 as CampaignInfo is an ERC721 NFT collection + ## Functions ### owner @@ -43,7 +48,9 @@ function checkIfPlatformSelected(bytes32 platformHash) external view returns (bo ### getTotalRaisedAmount -Retrieves the total amount raised in the campaign. +Retrieves the total amount raised across non-cancelled treasuries. + +This excludes cancelled treasuries and is affected by refunds. ```solidity @@ -56,6 +63,100 @@ function getTotalRaisedAmount() external view returns (uint256); |``|`uint256`|The total amount raised in the campaign.| +### getTotalLifetimeRaisedAmount + +Retrieves the total lifetime raised amount across all treasuries. + +This amount never decreases even when refunds are processed. +It represents the sum of all pledges/payments ever made to the campaign, +regardless of cancellations or refunds. + + +```solidity +function getTotalLifetimeRaisedAmount() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The total lifetime raised amount as a uint256 value.| + + +### getTotalRefundedAmount + +Retrieves the total refunded amount across all treasuries. + +This is calculated as the difference between lifetime raised amount +and current raised amount. It represents the sum of all refunds +that have been processed across all treasuries. + + +```solidity +function getTotalRefundedAmount() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The total refunded amount as a uint256 value.| + + +### getTotalAvailableRaisedAmount + +Retrieves the total available raised amount across all treasuries. + +This includes funds from both active and cancelled treasuries, +and is affected by refunds. It represents the actual current +balance of funds across all treasuries. + + +```solidity +function getTotalAvailableRaisedAmount() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The total available raised amount as a uint256 value.| + + +### getTotalCancelledAmount + +Retrieves the total raised amount from cancelled treasuries only. + +This is the opposite of getTotalRaisedAmount(), which only includes +non-cancelled treasuries. This function only sums up raised amounts +from treasuries that have been cancelled. + + +```solidity +function getTotalCancelledAmount() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The total raised amount from cancelled treasuries as a uint256 value.| + + +### getTotalExpectedAmount + +Retrieves the total expected (pending) amount across payment treasuries. + +This only applies to payment treasuries and represents payments that +have been created but not yet confirmed. Regular treasuries are skipped. + + +```solidity +function getTotalExpectedAmount() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The total expected amount as a uint256 value.| + + ### getProtocolAdminAddress Retrieves the address of the protocol administrator. @@ -224,6 +325,27 @@ function getPlatformFeePercent(bytes32 platformHash) external view returns (uint |``|`uint256`|The platform fee percentage applied to the campaign on the platform.| +### getPlatformClaimDelay + +Retrieves the claim delay (in seconds) configured for the given platform. + + +```solidity +function getPlatformClaimDelay(bytes32 platformHash) external view returns (uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`platformHash`|`bytes32`|The identifier of the platform.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The claim delay in seconds.| + + ### getPlatformData Retrieves platform-specific data for the campaign. @@ -324,7 +446,7 @@ function updateGoalAmount(uint256 goalAmount) external; Updates the selection status of a platform for the campaign. -*It can only be called for a platform if its not approved i.e. the platform treasury is not deployed* +It can only be called for a platform if its not approved i.e. the platform treasury is not deployed ```solidity @@ -347,7 +469,7 @@ function updateSelectedPlatform( ### paused -*Returns true if the campaign is paused, and false otherwise.* +Returns true if the campaign is paused, and false otherwise. ```solidity @@ -356,10 +478,172 @@ function paused() external view returns (bool); ### cancelled -*Returns true if the campaign is cancelled, and false otherwise.* +Returns true if the campaign is cancelled, and false otherwise. ```solidity function cancelled() external view returns (bool); ``` +### getDataFromRegistry + +Retrieves a value from the GlobalParams data registry. + + +```solidity +function getDataFromRegistry(bytes32 key) external view returns (bytes32 value); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`key`|`bytes32`|The registry key.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`value`|`bytes32`|The registry value.| + + +### getBufferTime + +Retrieves the buffer time from the GlobalParams data registry. + + +```solidity +function getBufferTime() external view returns (uint256 bufferTime); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`bufferTime`|`uint256`|The buffer time value.| + + +### getLineItemType + +Retrieves a platform-specific line item type configuration from GlobalParams. + + +```solidity +function getLineItemType(bytes32 platformHash, bytes32 typeId) + external + view + returns ( + bool exists, + string memory label, + bool countsTowardGoal, + bool applyProtocolFee, + bool canRefund, + bool instantTransfer + ); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`platformHash`|`bytes32`|The identifier of the platform.| +|`typeId`|`bytes32`|The identifier of the line item type.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`exists`|`bool`|Whether this line item type exists and is active.| +|`label`|`string`|The label identifier for the line item type.| +|`countsTowardGoal`|`bool`|Whether this line item counts toward the campaign goal.| +|`applyProtocolFee`|`bool`|Whether this line item is included in protocol fee calculation.| +|`canRefund`|`bool`|Whether this line item can be refunded.| +|`instantTransfer`|`bool`|Whether this line item amount can be instantly transferred.| + + +### mintNFTForPledge + +Mints a pledge NFT for a backer + +Can only be called by treasuries with MINTER_ROLE + + +```solidity +function mintNFTForPledge( + address backer, + bytes32 reward, + address tokenAddress, + uint256 amount, + uint256 shippingFee, + uint256 tipAmount +) external returns (uint256 tokenId); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`backer`|`address`|The backer address| +|`reward`|`bytes32`|The reward identifier| +|`tokenAddress`|`address`|The address of the token used for the pledge| +|`amount`|`uint256`|The pledge amount| +|`shippingFee`|`uint256`|The shipping fee| +|`tipAmount`|`uint256`|The tip amount| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|The minted token ID (pledge ID)| + + +### setImageURI + +Sets the image URI for NFT metadata + + +```solidity +function setImageURI(string calldata newImageURI) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`newImageURI`|`string`|The new image URI| + + +### updateContractURI + +Updates the contract-level metadata URI + + +```solidity +function updateContractURI(string calldata newContractURI) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`newContractURI`|`string`|The new contract URI| + + +### burn + +Burns a pledge NFT + + +```solidity +function burn(uint256 tokenId) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|The token ID to burn| + + +### isLocked + +Returns true if the campaign is locked (after treasury deployment), and false otherwise. + + +```solidity +function isLocked() external view returns (bool); +``` + diff --git a/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md b/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md index 6f9bb218..9340fba5 100644 --- a/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md +++ b/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md @@ -1,8 +1,8 @@ # ICampaignInfoFactory -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/interfaces/ICampaignInfoFactory.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/interfaces/ICampaignInfoFactory.sol) **Inherits:** -[ICampaignData](/src/interfaces/ICampaignData.sol/interface.ICampaignData.md) +[ICampaignData](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md) An interface for creating and managing campaign information contracts. @@ -10,13 +10,13 @@ An interface for creating and managing campaign information contracts. ## Functions ### createCampaign -Creates a new campaign information contract. +Creates a new campaign information contract with NFT. -*IMPORTANT: Protocol and platform fees are retrieved at execution time and locked +IMPORTANT: Protocol and platform fees are retrieved at execution time and locked permanently in the campaign contract. Users should verify current fees before calling this function or using intermediate contracts that check fees haven't changed from expected values. The protocol fee is stored as immutable in the cloned -contract and platform fees are stored during initialization.* +contract and platform fees are stored during initialization. ```solidity @@ -26,7 +26,11 @@ function createCampaign( bytes32[] calldata selectedPlatformHash, bytes32[] calldata platformDataKey, bytes32[] calldata platformDataValue, - CampaignData calldata campaignData + CampaignData calldata campaignData, + string calldata nftName, + string calldata nftSymbol, + string calldata nftImageURI, + string calldata contractURI ) external; ``` **Parameters** @@ -39,6 +43,10 @@ function createCampaign( |`platformDataKey`|`bytes32[]`|An array of platform-specific data keys.| |`platformDataValue`|`bytes32[]`|An array of platform-specific data values.| |`campaignData`|`CampaignData`|The struct containing campaign launch details (including currency).| +|`nftName`|`string`|NFT collection name| +|`nftSymbol`|`string`|NFT collection symbol| +|`nftImageURI`|`string`|NFT image URI for individual tokens| +|`contractURI`|`string`|IPFS URI for contract-level metadata| ### updateImplementation diff --git a/docs/src/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md b/docs/src/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md index e542e253..790e0a65 100644 --- a/docs/src/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md +++ b/docs/src/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md @@ -1,5 +1,5 @@ # ICampaignPaymentTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/interfaces/ICampaignPaymentTreasury.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/interfaces/ICampaignPaymentTreasury.sol) An interface for managing campaign payment treasury contracts. @@ -17,7 +17,9 @@ function createPayment( bytes32 itemId, address paymentToken, uint256 amount, - uint256 expiration + uint256 expiration, + LineItem[] calldata lineItems, + ExternalFees[] calldata externalFees ) external; ``` **Parameters** @@ -30,13 +32,46 @@ function createPayment( |`paymentToken`|`address`|The token to use for the payment.| |`amount`|`uint256`|The amount to be paid for the item.| |`expiration`|`uint256`|The timestamp after which the payment expires.| +|`lineItems`|`LineItem[]`|Array of line items associated with this payment.| +|`externalFees`|`ExternalFees[]`|Array of external fees associated with this payment.| + + +### createPaymentBatch + +Creates multiple payment entries in a single transaction to prevent nonce conflicts. + + +```solidity +function createPaymentBatch( + bytes32[] calldata paymentIds, + bytes32[] calldata buyerIds, + bytes32[] calldata itemIds, + address[] calldata paymentTokens, + uint256[] calldata amounts, + uint256[] calldata expirations, + LineItem[][] calldata lineItemsArray, + ExternalFees[][] calldata externalFeesArray +) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentIds`|`bytes32[]`|An array of unique identifiers for the payments.| +|`buyerIds`|`bytes32[]`|An array of buyer IDs corresponding to each payment.| +|`itemIds`|`bytes32[]`|An array of item identifiers corresponding to each payment.| +|`paymentTokens`|`address[]`|An array of tokens corresponding to each payment.| +|`amounts`|`uint256[]`|An array of amounts corresponding to each payment.| +|`expirations`|`uint256[]`|An array of expiration timestamps corresponding to each payment.| +|`lineItemsArray`|`LineItem[][]`|An array of line item arrays, one for each payment.| +|`externalFeesArray`|`ExternalFees[][]`|An array of external fees arrays, one for each payment.| ### processCryptoPayment Allows a buyer to make a direct crypto payment for an item. -*This function transfers tokens directly from the buyer's wallet and confirms the payment immediately.* +This function transfers tokens directly from the buyer's wallet and confirms the payment immediately. ```solidity @@ -45,7 +80,9 @@ function processCryptoPayment( bytes32 itemId, address buyerAddress, address paymentToken, - uint256 amount + uint256 amount, + LineItem[] calldata lineItems, + ExternalFees[] calldata externalFees ) external; ``` **Parameters** @@ -57,6 +94,8 @@ function processCryptoPayment( |`buyerAddress`|`address`|The address of the buyer making the payment.| |`paymentToken`|`address`|The token to use for the payment.| |`amount`|`uint256`|The amount to be paid for the item.| +|`lineItems`|`LineItem[]`|Array of line items associated with this payment.| +|`externalFees`|`ExternalFees[]`|Array of external fees associated with this payment.| ### cancelPayment @@ -80,13 +119,14 @@ Confirms and finalizes the payment associated with the given payment ID. ```solidity -function confirmPayment(bytes32 paymentId) external; +function confirmPayment(bytes32 paymentId, address buyerAddress) external; ``` **Parameters** |Name|Type|Description| |----|----|-----------| |`paymentId`|`bytes32`|The unique identifier of the payment to confirm.| +|`buyerAddress`|`address`|Optional buyer address to mint NFT to. Pass address(0) to skip NFT minting.| ### confirmPaymentBatch @@ -95,13 +135,14 @@ Confirms and finalizes multiple payments in a single transaction. ```solidity -function confirmPaymentBatch(bytes32[] calldata paymentIds) external; +function confirmPaymentBatch(bytes32[] calldata paymentIds, address[] calldata buyerAddresses) external; ``` **Parameters** |Name|Type|Description| |----|----|-----------| |`paymentIds`|`bytes32[]`|An array of unique payment identifiers to be confirmed.| +|`buyerAddresses`|`address[]`|Array of buyer addresses to mint NFTs to. Must match paymentIds length. Pass address(0) to skip NFT minting for specific payments.| ### disburseFees @@ -124,7 +165,9 @@ function withdraw() external; ### claimRefund -Claims a refund for a specific payment ID. +Claims a refund for non-NFT payments (payments without minted NFTs). + +Only callable by platform admin. Used for payments confirmed without a buyer address. ```solidity @@ -134,13 +177,16 @@ function claimRefund(bytes32 paymentId, address refundAddress) external; |Name|Type|Description| |----|----|-----------| -|`paymentId`|`bytes32`|The unique identifier of the refundable payment.| +|`paymentId`|`bytes32`|The unique identifier of the refundable payment (must NOT have an NFT).| |`refundAddress`|`address`|The address where the refunded amount should be sent.| ### claimRefund -Allows buyers to claim refunds for crypto payments, or platform admin to process refunds on behalf of buyers. +Claims a refund for NFT payments (payments with minted NFTs). + +Burns the NFT associated with the payment. Caller must have approved the treasury for the NFT. +Used for processCryptoPayment and confirmPayment (with buyer address) transactions. ```solidity @@ -150,8 +196,17 @@ function claimRefund(bytes32 paymentId) external; |Name|Type|Description| |----|----|-----------| -|`paymentId`|`bytes32`|The unique identifier of the refundable payment.| +|`paymentId`|`bytes32`|The unique identifier of the refundable payment (must have an NFT).| + +### claimExpiredFunds + +Allows platform admin to claim all remaining funds once the claim window has opened. + + +```solidity +function claimExpiredFunds() external; +``` ### getplatformHash @@ -213,3 +268,187 @@ function getAvailableRaisedAmount() external view returns (uint256); |``|`uint256`|The current available raised amount as a uint256 value.| +### getPaymentData + +Retrieves comprehensive payment data including payment info, token, line items, and external fees. + + +```solidity +function getPaymentData(bytes32 paymentId) external view returns (PaymentData memory); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the payment.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`PaymentData`|A PaymentData struct containing all payment information.| + + +### getLifetimeRaisedAmount + +Retrieves the lifetime raised amount in the treasury (never decreases with refunds). + + +```solidity +function getLifetimeRaisedAmount() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The lifetime raised amount as a uint256 value.| + + +### getRefundedAmount + +Retrieves the total refunded amount in the treasury. + + +```solidity +function getRefundedAmount() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The total refunded amount as a uint256 value.| + + +### getExpectedAmount + +Retrieves the total expected (pending) amount in the treasury. + +This represents payments that have been created but not yet confirmed. + + +```solidity +function getExpectedAmount() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The total expected amount as a uint256 value.| + + +### cancelled + +Checks if the treasury has been cancelled. + + +```solidity +function cancelled() external view returns (bool); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|True if the treasury is cancelled, false otherwise.| + + +## Structs +### PaymentLineItem +Represents a stored line item with its configuration snapshot. + + +```solidity +struct PaymentLineItem { + bytes32 typeId; + uint256 amount; + string label; + bool countsTowardGoal; + bool applyProtocolFee; + bool canRefund; + bool instantTransfer; +} +``` + +**Properties** + +|Name|Type|Description| +|----|----|-----------| +|`typeId`|`bytes32`|The type identifier of the line item.| +|`amount`|`uint256`|The amount of the line item.| +|`label`|`string`|The human-readable label of the line item type.| +|`countsTowardGoal`|`bool`|Whether this line item counts toward the campaign goal.| +|`applyProtocolFee`|`bool`|Whether protocol fee applies to this line item.| +|`canRefund`|`bool`|Whether this line item can be refunded.| +|`instantTransfer`|`bool`|Whether this line item is transferred instantly.| + +### PaymentData +Comprehensive payment data structure containing all payment information. + + +```solidity +struct PaymentData { + address buyerAddress; + bytes32 buyerId; + bytes32 itemId; + uint256 amount; + uint256 expiration; + bool isConfirmed; + bool isCryptoPayment; + uint256 lineItemCount; + address paymentToken; + PaymentLineItem[] lineItems; + ExternalFees[] externalFees; +} +``` + +**Properties** + +|Name|Type|Description| +|----|----|-----------| +|`buyerAddress`|`address`|The address of the buyer who made the payment.| +|`buyerId`|`bytes32`|The ID of the buyer.| +|`itemId`|`bytes32`|The identifier of the item being purchased.| +|`amount`|`uint256`|The amount to be paid for the item (in token's native decimals).| +|`expiration`|`uint256`|The timestamp after which the payment expires.| +|`isConfirmed`|`bool`|Boolean indicating whether the payment has been confirmed.| +|`isCryptoPayment`|`bool`|Boolean indicating whether the payment is made using direct crypto payment.| +|`lineItemCount`|`uint256`|The number of line items associated with this payment.| +|`paymentToken`|`address`|The token address used for this payment.| +|`lineItems`|`PaymentLineItem[]`|Array of stored line items with their configuration snapshots.| +|`externalFees`|`ExternalFees[]`|Array of external fees associated with this payment.| + +### LineItem +Represents a line item in a payment. + + +```solidity +struct LineItem { + bytes32 typeId; + uint256 amount; +} +``` + +**Properties** + +|Name|Type|Description| +|----|----|-----------| +|`typeId`|`bytes32`|The type identifier of the line item (must exist in GlobalParams).| +|`amount`|`uint256`|The amount of the line item (denominated in pledge token).| + +### ExternalFees +Represents external fees associated with a payment. + + +```solidity +struct ExternalFees { + bytes32 feeType; + uint256 feeAmount; +} +``` + +**Properties** + +|Name|Type|Description| +|----|----|-----------| +|`feeType`|`bytes32`|The type identifier of the external fee.| +|`feeAmount`|`uint256`|The amount of the external fee.| + diff --git a/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md b/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md index 792e49ea..d0299c45 100644 --- a/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md +++ b/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md @@ -1,5 +1,5 @@ # ICampaignTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/interfaces/ICampaignTreasury.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/interfaces/ICampaignTreasury.sol) An interface for managing campaign treasury contracts. @@ -83,3 +83,48 @@ function getRaisedAmount() external view returns (uint256); |``|`uint256`|The total raised amount as a uint256 value.| +### getLifetimeRaisedAmount + +Retrieves the lifetime raised amount in the treasury (never decreases with refunds). + + +```solidity +function getLifetimeRaisedAmount() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The lifetime raised amount as a uint256 value.| + + +### getRefundedAmount + +Retrieves the total refunded amount in the treasury. + + +```solidity +function getRefundedAmount() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The total refunded amount as a uint256 value.| + + +### cancelled + +Checks if the treasury has been cancelled. + + +```solidity +function cancelled() external view returns (bool); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|True if the treasury is cancelled, false otherwise.| + + diff --git a/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md b/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md index 227fcfce..b4220271 100644 --- a/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md +++ b/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md @@ -1,5 +1,5 @@ # IGlobalParams -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/interfaces/IGlobalParams.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/interfaces/IGlobalParams.sol) An interface for accessing and managing global parameters of the protocol. @@ -134,6 +134,27 @@ function getPlatformFeePercent(bytes32 platformHash) external view returns (uint |``|`uint256`|The platform fee percentage as a uint256 value.| +### getPlatformClaimDelay + +Retrieves the claim delay (in seconds) for a specific platform. + + +```solidity +function getPlatformClaimDelay(bytes32 platformHash) external view returns (uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`platformHash`|`bytes32`|The unique identifier of the platform.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The claim delay in seconds.| + + ### checkIfPlatformDataKeyValid Checks if a platform-specific data key is valid. @@ -201,6 +222,22 @@ function updatePlatformAdminAddress(bytes32 _platformHash, address _platformAdmi |`_platformAdminAddress`|`address`|The new admin address of the platform.| +### updatePlatformClaimDelay + +Updates the claim delay for a specific platform. + + +```solidity +function updatePlatformClaimDelay(bytes32 platformHash, uint256 claimDelay) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`platformHash`|`bytes32`|The unique identifier of the platform.| +|`claimDelay`|`uint256`|The claim delay in seconds.| + + ### addTokenToCurrency Adds a token to a currency. @@ -254,3 +291,106 @@ function getTokensForCurrency(bytes32 currency) external view returns (address[] |``|`address[]`|An array of token addresses accepted for the currency.| +### getFromRegistry + +Retrieves a value from the data registry. + + +```solidity +function getFromRegistry(bytes32 key) external view returns (bytes32 value); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`key`|`bytes32`|The registry key.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`value`|`bytes32`|The registry value.| + + +### setPlatformLineItemType + +Sets or updates a platform-specific line item type configuration. + + +```solidity +function setPlatformLineItemType( + bytes32 platformHash, + bytes32 typeId, + string calldata label, + bool countsTowardGoal, + bool applyProtocolFee, + bool canRefund, + bool instantTransfer +) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`platformHash`|`bytes32`|The identifier of the platform.| +|`typeId`|`bytes32`|The identifier of the line item type.| +|`label`|`string`|The label identifier for the line item type.| +|`countsTowardGoal`|`bool`|Whether this line item counts toward the campaign goal.| +|`applyProtocolFee`|`bool`|Whether this line item is included in protocol fee calculation.| +|`canRefund`|`bool`|Whether this line item can be refunded.| +|`instantTransfer`|`bool`|Whether this line item amount can be instantly transferred.| + + +### removePlatformLineItemType + +Removes a platform-specific line item type by setting its exists flag to false. + + +```solidity +function removePlatformLineItemType(bytes32 platformHash, bytes32 typeId) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`platformHash`|`bytes32`|The identifier of the platform.| +|`typeId`|`bytes32`|The identifier of the line item type to remove.| + + +### getPlatformLineItemType + +Retrieves a platform-specific line item type configuration. + + +```solidity +function getPlatformLineItemType(bytes32 platformHash, bytes32 typeId) + external + view + returns ( + bool exists, + string memory label, + bool countsTowardGoal, + bool applyProtocolFee, + bool canRefund, + bool instantTransfer + ); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`platformHash`|`bytes32`|The identifier of the platform.| +|`typeId`|`bytes32`|The identifier of the line item type.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`exists`|`bool`|Whether this line item type exists and is active.| +|`label`|`string`|The label identifier for the line item type.| +|`countsTowardGoal`|`bool`|Whether this line item counts toward the campaign goal.| +|`applyProtocolFee`|`bool`|Whether this line item is included in protocol fee calculation.| +|`canRefund`|`bool`|Whether this line item can be refunded.| +|`instantTransfer`|`bool`|Whether this line item amount can be instantly transferred.| + + diff --git a/docs/src/src/interfaces/IItem.sol/interface.IItem.md b/docs/src/src/interfaces/IItem.sol/interface.IItem.md index a1776f4f..1dea077e 100644 --- a/docs/src/src/interfaces/IItem.sol/interface.IItem.md +++ b/docs/src/src/interfaces/IItem.sol/interface.IItem.md @@ -1,5 +1,5 @@ # IItem -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/interfaces/IItem.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/interfaces/IItem.sol) An interface for managing items and their attributes. @@ -50,12 +50,12 @@ Represents the attributes of an item. ```solidity struct Item { - uint256 actualWeight; - uint256 height; - uint256 width; - uint256 length; - bytes32 category; - bytes32 declaredCurrency; + uint256 actualWeight; // The actual weight of the item. + uint256 height; // The height of the item. + uint256 width; // The width of the item. + uint256 length; // The length of the item. + bytes32 category; // The category of the item. + bytes32 declaredCurrency; // The declared currency of the item. } ``` diff --git a/docs/src/src/interfaces/IReward.sol/interface.IReward.md b/docs/src/src/interfaces/IReward.sol/interface.IReward.md index 3320ff59..c97fba76 100644 --- a/docs/src/src/interfaces/IReward.sol/interface.IReward.md +++ b/docs/src/src/interfaces/IReward.sol/interface.IReward.md @@ -1,5 +1,5 @@ # IReward -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/interfaces/IReward.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/interfaces/IReward.sol) An interface for managing rewards in a campaign. diff --git a/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md b/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md index 608b890c..dbb3f29b 100644 --- a/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md +++ b/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md @@ -1,7 +1,7 @@ # ITreasuryFactory -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/interfaces/ITreasuryFactory.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/interfaces/ITreasuryFactory.sol) -*Interface for the TreasuryFactory contract, which registers, approves, and deploys treasury clones.* +Interface for the TreasuryFactory contract, which registers, approves, and deploys treasury clones. ## Functions @@ -9,7 +9,7 @@ Registers a treasury implementation for a given platform. -*Callable only by the platform admin.* +Callable only by the platform admin. ```solidity @@ -29,7 +29,7 @@ function registerTreasuryImplementation(bytes32 platformHash, uint256 implementa Approves a previously registered implementation. -*Callable only by the protocol admin.* +Callable only by the protocol admin. ```solidity @@ -78,17 +78,13 @@ function removeTreasuryImplementation(bytes32 platformHash, uint256 implementati Deploys a treasury clone using an approved implementation. -*Callable only by the platform admin.* +Callable only by the platform admin. ```solidity -function deploy( - bytes32 platformHash, - address infoAddress, - uint256 implementationId, - string calldata name, - string calldata symbol -) external returns (address clone); +function deploy(bytes32 platformHash, address infoAddress, uint256 implementationId) + external + returns (address clone); ``` **Parameters** @@ -97,8 +93,6 @@ function deploy( |`platformHash`|`bytes32`|The platform identifier.| |`infoAddress`|`address`|The address of the campaign info contract.| |`implementationId`|`uint256`|The ID of the implementation to use.| -|`name`|`string`|The name of the treasury token.| -|`symbol`|`string`|The symbol of the treasury token.| **Returns** @@ -109,12 +103,15 @@ function deploy( ## Events ### TreasuryFactoryTreasuryDeployed -*Emitted when a new treasury is deployed.* +Emitted when a new treasury is deployed. ```solidity event TreasuryFactoryTreasuryDeployed( - bytes32 indexed platformHash, uint256 indexed implementationId, address indexed infoAddress, address treasuryAddress + bytes32 indexed platformHash, + uint256 indexed implementationId, + address indexed infoAddress, + address treasuryAddress ); ``` diff --git a/docs/src/src/storage/AdminAccessCheckerStorage.sol/library.AdminAccessCheckerStorage.md b/docs/src/src/storage/AdminAccessCheckerStorage.sol/library.AdminAccessCheckerStorage.md new file mode 100644 index 00000000..99086817 --- /dev/null +++ b/docs/src/src/storage/AdminAccessCheckerStorage.sol/library.AdminAccessCheckerStorage.md @@ -0,0 +1,37 @@ +# AdminAccessCheckerStorage +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/storage/AdminAccessCheckerStorage.sol) + +Storage contract for AdminAccessChecker using ERC-7201 namespaced storage + +This contract contains the storage layout and accessor functions for AdminAccessChecker + + +## State Variables +### ADMIN_ACCESS_CHECKER_STORAGE_LOCATION + +```solidity +bytes32 private constant ADMIN_ACCESS_CHECKER_STORAGE_LOCATION = + 0x7c2f08fa04c2c7c7ab255a45dbf913d4c236b91c59858917e818398e997f8800 +``` + + +## Functions +### _getAdminAccessCheckerStorage + + +```solidity +function _getAdminAccessCheckerStorage() internal pure returns (Storage storage $); +``` + +## Structs +### Storage +**Note:** +storage-location: erc7201:ccprotocol.storage.AdminAccessChecker + + +```solidity +struct Storage { + IGlobalParams globalParams; +} +``` + diff --git a/docs/src/src/storage/CampaignInfoFactoryStorage.sol/library.CampaignInfoFactoryStorage.md b/docs/src/src/storage/CampaignInfoFactoryStorage.sol/library.CampaignInfoFactoryStorage.md new file mode 100644 index 00000000..4c5193c3 --- /dev/null +++ b/docs/src/src/storage/CampaignInfoFactoryStorage.sol/library.CampaignInfoFactoryStorage.md @@ -0,0 +1,41 @@ +# CampaignInfoFactoryStorage +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/storage/CampaignInfoFactoryStorage.sol) + +Storage contract for CampaignInfoFactory using ERC-7201 namespaced storage + +This contract contains the storage layout and accessor functions for CampaignInfoFactory + + +## State Variables +### CAMPAIGN_INFO_FACTORY_STORAGE_LOCATION + +```solidity +bytes32 private constant CAMPAIGN_INFO_FACTORY_STORAGE_LOCATION = + 0x2857858a392b093e1f8b3f368c2276ce911f27cef445605a2932ebe945968d00 +``` + + +## Functions +### _getCampaignInfoFactoryStorage + + +```solidity +function _getCampaignInfoFactoryStorage() internal pure returns (Storage storage $); +``` + +## Structs +### Storage +**Note:** +storage-location: erc7201:ccprotocol.storage.CampaignInfoFactory + + +```solidity +struct Storage { + IGlobalParams globalParams; + address treasuryFactoryAddress; + address implementation; + mapping(address => bool) isValidCampaignInfo; + mapping(bytes32 => address) identifierToCampaignInfo; +} +``` + diff --git a/docs/src/src/storage/GlobalParamsStorage.sol/library.GlobalParamsStorage.md b/docs/src/src/storage/GlobalParamsStorage.sol/library.GlobalParamsStorage.md new file mode 100644 index 00000000..85fee0b3 --- /dev/null +++ b/docs/src/src/storage/GlobalParamsStorage.sol/library.GlobalParamsStorage.md @@ -0,0 +1,75 @@ +# GlobalParamsStorage +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/storage/GlobalParamsStorage.sol) + +Storage contract for GlobalParams using ERC-7201 namespaced storage + +This contract contains the storage layout and accessor functions for GlobalParams + + +## State Variables +### GLOBAL_PARAMS_STORAGE_LOCATION + +```solidity +bytes32 private constant GLOBAL_PARAMS_STORAGE_LOCATION = + 0x83d0145f7c1378f10048390769ec94f999b3ba6d94904b8fd7251512962b1c00 +``` + + +## Functions +### _getGlobalParamsStorage + + +```solidity +function _getGlobalParamsStorage() internal pure returns (Storage storage $); +``` + +## Structs +### LineItemType +Line item type configuration + + +```solidity +struct LineItemType { + bool exists; + string label; + bool countsTowardGoal; + bool applyProtocolFee; + bool canRefund; + bool instantTransfer; +} +``` + +**Properties** + +|Name|Type|Description| +|----|----|-----------| +|`exists`|`bool`|Whether this line item type exists and is active| +|`label`|`string`|The label identifier for the line item type (e.g., "shipping_fee")| +|`countsTowardGoal`|`bool`|Whether this line item counts toward the campaign goal| +|`applyProtocolFee`|`bool`|Whether this line item is included in protocol fee calculation| +|`canRefund`|`bool`|Whether this line item can be refunded| +|`instantTransfer`|`bool`|Whether this line item amount can be instantly transferred| + +### Storage +**Note:** +storage-location: erc7201:ccprotocol.storage.GlobalParams + + +```solidity +struct Storage { + address protocolAdminAddress; + uint256 protocolFeePercent; + mapping(bytes32 => bool) platformIsListed; + mapping(bytes32 => address) platformAdminAddress; + mapping(bytes32 => uint256) platformFeePercent; + mapping(bytes32 => bytes32) platformDataOwner; + mapping(bytes32 => bool) platformData; + mapping(bytes32 => bytes32) dataRegistry; + mapping(bytes32 => address[]) currencyToTokens; + // Platform-specific line item types: mapping(platformHash => mapping(typeId => LineItemType)) + mapping(bytes32 => mapping(bytes32 => LineItemType)) platformLineItemTypes; + mapping(bytes32 => uint256) platformClaimDelay; + Counters.Counter numberOfListedPlatforms; +} +``` + diff --git a/docs/src/src/storage/README.md b/docs/src/src/storage/README.md new file mode 100644 index 00000000..8d689510 --- /dev/null +++ b/docs/src/src/storage/README.md @@ -0,0 +1,7 @@ + + +# Contents +- [AdminAccessCheckerStorage](AdminAccessCheckerStorage.sol/library.AdminAccessCheckerStorage.md) +- [CampaignInfoFactoryStorage](CampaignInfoFactoryStorage.sol/library.CampaignInfoFactoryStorage.md) +- [GlobalParamsStorage](GlobalParamsStorage.sol/library.GlobalParamsStorage.md) +- [TreasuryFactoryStorage](TreasuryFactoryStorage.sol/library.TreasuryFactoryStorage.md) diff --git a/docs/src/src/storage/TreasuryFactoryStorage.sol/library.TreasuryFactoryStorage.md b/docs/src/src/storage/TreasuryFactoryStorage.sol/library.TreasuryFactoryStorage.md new file mode 100644 index 00000000..62a8e562 --- /dev/null +++ b/docs/src/src/storage/TreasuryFactoryStorage.sol/library.TreasuryFactoryStorage.md @@ -0,0 +1,38 @@ +# TreasuryFactoryStorage +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/storage/TreasuryFactoryStorage.sol) + +Storage contract for TreasuryFactory using ERC-7201 namespaced storage + +This contract contains the storage layout and accessor functions for TreasuryFactory + + +## State Variables +### TREASURY_FACTORY_STORAGE_LOCATION + +```solidity +bytes32 private constant TREASURY_FACTORY_STORAGE_LOCATION = + 0x96b7de8c171ef460648aea35787d043e89feb6b6de2623a1e6f17a91b9c9e900 +``` + + +## Functions +### _getTreasuryFactoryStorage + + +```solidity +function _getTreasuryFactoryStorage() internal pure returns (Storage storage $); +``` + +## Structs +### Storage +**Note:** +storage-location: erc7201:ccprotocol.storage.TreasuryFactory + + +```solidity +struct Storage { + mapping(bytes32 => mapping(uint256 => address)) implementationMap; + mapping(address => bool) approvedImplementations; +} +``` + diff --git a/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md b/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md index 3fb14987..d8e5ed1e 100644 --- a/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md +++ b/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md @@ -1,8 +1,8 @@ # AllOrNothing -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/treasuries/AllOrNothing.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/treasuries/AllOrNothing.sol) **Inherits:** -[IReward](/src/interfaces/IReward.sol/interface.IReward.md), [BaseTreasury](/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md), [TimestampChecker](/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), ERC721Burnable +[IReward](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/IReward.sol/interface.IReward.md), [BaseTreasury](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md), [TimestampChecker](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), ReentrancyGuard A contract for handling crowdfunding campaigns with rewards. @@ -11,90 +11,53 @@ A contract for handling crowdfunding campaigns with rewards. ### s_tokenToTotalCollectedAmount ```solidity -mapping(uint256 => uint256) private s_tokenToTotalCollectedAmount; +mapping(uint256 => uint256) private s_tokenToTotalCollectedAmount ``` ### s_tokenToPledgedAmount ```solidity -mapping(uint256 => uint256) private s_tokenToPledgedAmount; +mapping(uint256 => uint256) private s_tokenToPledgedAmount ``` ### s_reward ```solidity -mapping(bytes32 => Reward) private s_reward; +mapping(bytes32 => Reward) private s_reward ``` ### s_tokenIdToPledgeToken ```solidity -mapping(uint256 => address) private s_tokenIdToPledgeToken; -``` - - -### s_tokenIdCounter - -```solidity -Counters.Counter private s_tokenIdCounter; +mapping(uint256 => address) private s_tokenIdToPledgeToken ``` ### s_rewardCounter ```solidity -Counters.Counter private s_rewardCounter; -``` - - -### s_name - -```solidity -string private s_name; -``` - - -### s_symbol - -```solidity -string private s_symbol; +Counters.Counter private s_rewardCounter ``` ## Functions ### constructor -*Constructor for the AllOrNothing contract.* +Constructor for the AllOrNothing contract. ```solidity -constructor() ERC721("", ""); +constructor() ; ``` ### initialize ```solidity -function initialize(bytes32 _platformHash, address _infoAddress, string calldata _name, string calldata _symbol) - external - initializer; -``` - -### name - - -```solidity -function name() public view override returns (string memory); -``` - -### symbol - - -```solidity -function symbol() public view override returns (string memory); +function initialize(bytes32 _platformHash, address _infoAddress) external initializer; ``` ### getReward @@ -133,14 +96,44 @@ function getRaisedAmount() external view override returns (uint256); |``|`uint256`|The total raised amount as a uint256 value.| +### getLifetimeRaisedAmount + +Retrieves the lifetime raised amount in the treasury (never decreases with refunds). + + +```solidity +function getLifetimeRaisedAmount() external view override returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The lifetime raised amount as a uint256 value.| + + +### getRefundedAmount + +Retrieves the total refunded amount in the treasury. + + +```solidity +function getRefundedAmount() external view override returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The total refunded amount as a uint256 value.| + + ### addRewards Adds multiple rewards in a batch. -*This function allows for both reward tiers and non-reward tiers. +This function allows for both reward tiers and non-reward tiers. For both types, rewards must have non-zero value. If items are specified (non-empty arrays), the itemId, itemValue, and itemQuantity arrays must match in length. -Empty arrays are allowed for both reward tiers and non-reward tiers.* +Empty arrays are allowed for both reward tiers and non-reward tiers. ```solidity @@ -185,13 +178,14 @@ function removeReward(bytes32 rewardName) Allows a backer to pledge for a reward. -*The first element of the `reward` array must be a reward tier and the other elements can be either reward tiers or non-reward tiers. -The non-reward tiers cannot be pledged for without a reward.* +The first element of the `reward` array must be a reward tier and the other elements can be either reward tiers or non-reward tiers. +The non-reward tiers cannot be pledged for without a reward. ```solidity function pledgeForAReward(address backer, address pledgeToken, uint256 shippingFee, bytes32[] calldata reward) external + nonReentrant currentTimeIsWithinRange(INFO.getLaunchTime(), INFO.getDeadline()) whenCampaignNotPaused whenNotPaused @@ -216,6 +210,7 @@ Allows a backer to pledge without selecting a reward. ```solidity function pledgeWithoutAReward(address backer, address pledgeToken, uint256 pledgeAmount) external + nonReentrant currentTimeIsWithinRange(INFO.getLaunchTime(), INFO.getDeadline()) whenCampaignNotPaused whenNotPaused @@ -270,7 +265,7 @@ function withdraw() public override whenNotPaused whenNotCancelled; ### cancelTreasury -*This function is overridden to allow the platform admin and the campaign owner to cancel a treasury.* +This function is overridden to allow the platform admin and the campaign owner to cancel a treasury. ```solidity @@ -279,7 +274,7 @@ function cancelTreasury(bytes32 message) public override; ### _checkSuccessCondition -*Internal function to check the success condition for fee disbursement.* +Internal function to check the success condition for fee disbursement. ```solidity @@ -302,21 +297,13 @@ function _pledge( bytes32 reward, uint256 pledgeAmount, uint256 shippingFee, - uint256 tokenId, bytes32[] memory rewards ) private; ``` -### supportsInterface - - -```solidity -function supportsInterface(bytes4 interfaceId) public view override returns (bool); -``` - ## Events ### Receipt -*Emitted when a backer makes a pledge.* +Emitted when a backer makes a pledge. ```solidity @@ -344,7 +331,7 @@ event Receipt( |`rewards`|`bytes32[]`|An array of reward names.| ### RewardsAdded -*Emitted when rewards are added to the campaign.* +Emitted when rewards are added to the campaign. ```solidity @@ -359,7 +346,7 @@ event RewardsAdded(bytes32[] rewardNames, Reward[] rewards); |`rewards`|`Reward[]`|The details of the rewards.| ### RewardRemoved -*Emitted when a reward is removed from the campaign.* +Emitted when a reward is removed from the campaign. ```solidity @@ -373,7 +360,7 @@ event RewardRemoved(bytes32 indexed rewardName); |`rewardName`|`bytes32`|The name of the reward.| ### RefundClaimed -*Emitted when a refund is claimed.* +Emitted when a refund is claimed. ```solidity @@ -390,7 +377,7 @@ event RefundClaimed(uint256 tokenId, uint256 refundAmount, address claimer); ## Errors ### AllOrNothingUnAuthorized -*Emitted when an unauthorized action is attempted.* +Emitted when an unauthorized action is attempted. ```solidity @@ -398,7 +385,7 @@ error AllOrNothingUnAuthorized(); ``` ### AllOrNothingInvalidInput -*Emitted when an invalid input is detected.* +Emitted when an invalid input is detected. ```solidity @@ -406,7 +393,7 @@ error AllOrNothingInvalidInput(); ``` ### AllOrNothingTransferFailed -*Emitted when a token transfer fails.* +Emitted when a token transfer fails. ```solidity @@ -414,7 +401,7 @@ error AllOrNothingTransferFailed(); ``` ### AllOrNothingNotSuccessful -*Emitted when the campaign is not successful.* +Emitted when the campaign is not successful. ```solidity @@ -422,7 +409,7 @@ error AllOrNothingNotSuccessful(); ``` ### AllOrNothingFeeNotDisbursed -*Emitted when fees are not disbursed.* +Emitted when fees are not disbursed. ```solidity @@ -430,7 +417,7 @@ error AllOrNothingFeeNotDisbursed(); ``` ### AllOrNothingFeeAlreadyDisbursed -*Emitted when `disburseFees` after fee is disbursed already.* +Emitted when `disburseFees` after fee is disbursed already. ```solidity @@ -438,7 +425,7 @@ error AllOrNothingFeeAlreadyDisbursed(); ``` ### AllOrNothingRewardExists -*Emitted when a `Reward` already exists for given input.* +Emitted when a `Reward` already exists for given input. ```solidity @@ -446,7 +433,7 @@ error AllOrNothingRewardExists(); ``` ### AllOrNothingTokenNotAccepted -*Emitted when a token is not accepted for the campaign.* +Emitted when a token is not accepted for the campaign. ```solidity @@ -454,7 +441,7 @@ error AllOrNothingTokenNotAccepted(address token); ``` ### AllOrNothingNotClaimable -*Emitted when claiming an unclaimable refund.* +Emitted when claiming an unclaimable refund. ```solidity diff --git a/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md b/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md index f613d90f..51f75f6b 100644 --- a/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md +++ b/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md @@ -1,8 +1,8 @@ # KeepWhatsRaised -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/treasuries/KeepWhatsRaised.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/treasuries/KeepWhatsRaised.sol) **Inherits:** -[IReward](/src/interfaces/IReward.sol/interface.IReward.md), [BaseTreasury](/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md), [TimestampChecker](/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), ERC721Burnable, [ICampaignData](/src/interfaces/ICampaignData.sol/interface.ICampaignData.md) +[IReward](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/IReward.sol/interface.IReward.md), [BaseTreasury](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md), [TimestampChecker](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), [ICampaignData](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md), ReentrancyGuard A contract that keeps all the funds raised, regardless of the success condition. @@ -11,28 +11,28 @@ A contract that keeps all the funds raised, regardless of the success condition. ### s_tokenToPledgedAmount ```solidity -mapping(uint256 => uint256) private s_tokenToPledgedAmount; +mapping(uint256 => uint256) private s_tokenToPledgedAmount ``` ### s_tokenToTippedAmount ```solidity -mapping(uint256 => uint256) private s_tokenToTippedAmount; +mapping(uint256 => uint256) private s_tokenToTippedAmount ``` ### s_tokenToPaymentFee ```solidity -mapping(uint256 => uint256) private s_tokenToPaymentFee; +mapping(uint256 => uint256) private s_tokenToPaymentFee ``` ### s_reward ```solidity -mapping(bytes32 => Reward) private s_reward; +mapping(bytes32 => Reward) private s_reward ``` @@ -41,7 +41,7 @@ Tracks whether a pledge with a specific ID has already been processed ```solidity -mapping(bytes32 => bool) public s_processedPledges; +mapping(bytes32 => bool) public s_processedPledges ``` @@ -50,7 +50,7 @@ Mapping to store payment gateway fees by unique pledge ID ```solidity -mapping(bytes32 => uint256) public s_paymentGatewayFees; +mapping(bytes32 => uint256) public s_paymentGatewayFees ``` @@ -59,186 +59,149 @@ Mapping that stores fee values indexed by their corresponding fee keys. ```solidity -mapping(bytes32 => uint256) private s_feeValues; +mapping(bytes32 => uint256) private s_feeValues ``` ### s_tokenIdToPledgeToken ```solidity -mapping(uint256 => address) private s_tokenIdToPledgeToken; +mapping(uint256 => address) private s_tokenIdToPledgeToken ``` ### s_protocolFeePerToken ```solidity -mapping(address => uint256) private s_protocolFeePerToken; +mapping(address => uint256) private s_protocolFeePerToken ``` ### s_platformFeePerToken ```solidity -mapping(address => uint256) private s_platformFeePerToken; +mapping(address => uint256) private s_platformFeePerToken ``` ### s_tipPerToken ```solidity -mapping(address => uint256) private s_tipPerToken; +mapping(address => uint256) private s_tipPerToken ``` ### s_availablePerToken ```solidity -mapping(address => uint256) private s_availablePerToken; -``` - - -### s_tokenIdCounter - -```solidity -Counters.Counter private s_tokenIdCounter; +mapping(address => uint256) private s_availablePerToken ``` ### s_rewardCounter ```solidity -Counters.Counter private s_rewardCounter; -``` - - -### s_name - -```solidity -string private s_name; -``` - - -### s_symbol - -```solidity -string private s_symbol; +Counters.Counter private s_rewardCounter ``` ### s_cancellationTime ```solidity -uint256 private s_cancellationTime; +uint256 private s_cancellationTime ``` ### s_isWithdrawalApproved ```solidity -bool private s_isWithdrawalApproved; +bool private s_isWithdrawalApproved ``` ### s_tipClaimed ```solidity -bool private s_tipClaimed; +bool private s_tipClaimed ``` ### s_fundClaimed ```solidity -bool private s_fundClaimed; +bool private s_fundClaimed ``` ### s_feeKeys ```solidity -FeeKeys private s_feeKeys; +FeeKeys private s_feeKeys ``` ### s_config ```solidity -Config private s_config; +Config private s_config ``` ### s_campaignData ```solidity -CampaignData private s_campaignData; +CampaignData private s_campaignData ``` ## Functions ### withdrawalEnabled -*Ensures that withdrawals are currently enabled. -Reverts with `KeepWhatsRaisedDisabled` if the withdrawal approval flag is not set.* +Ensures that withdrawals are currently enabled. +Reverts with `KeepWhatsRaisedDisabled` if the withdrawal approval flag is not set. ```solidity -modifier withdrawalEnabled(); +modifier withdrawalEnabled() ; ``` ### onlyBeforeConfigLock -*Restricts execution to only occur before the configuration lock period. +Restricts execution to only occur before the configuration lock period. Reverts with `KeepWhatsRaisedConfigLocked` if called too close to or after the campaign deadline. -The lock period is defined as the duration before the deadline during which configuration changes are not allowed.* +The lock period is defined as the duration before the deadline during which configuration changes are not allowed. ```solidity -modifier onlyBeforeConfigLock(); +modifier onlyBeforeConfigLock() ; ``` ### onlyPlatformAdminOrCampaignOwner Restricts access to only the platform admin or the campaign owner. -*Checks if `_msgSender()` is either the platform admin (via `INFO.getPlatformAdminAddress`) -or the campaign owner (via `INFO.owner()`). Reverts with `KeepWhatsRaisedUnAuthorized` if not authorized.* +Checks if `_msgSender()` is either the platform admin (via `INFO.getPlatformAdminAddress`) +or the campaign owner (via `INFO.owner()`). Reverts with `KeepWhatsRaisedUnAuthorized` if not authorized. ```solidity -modifier onlyPlatformAdminOrCampaignOwner(); +modifier onlyPlatformAdminOrCampaignOwner() ; ``` ### constructor -*Constructor for the KeepWhatsRaised contract.* +Constructor for the KeepWhatsRaised contract. ```solidity -constructor() ERC721("", ""); +constructor() ; ``` ### initialize ```solidity -function initialize(bytes32 _platformHash, address _infoAddress, string calldata _name, string calldata _symbol) - external - initializer; -``` - -### name - - -```solidity -function name() public view override returns (string memory); -``` - -### symbol - - -```solidity -function symbol() public view override returns (string memory); +function initialize(bytes32 _platformHash, address _infoAddress) external initializer; ``` ### getWithdrawalApprovalStatus @@ -286,6 +249,36 @@ function getRaisedAmount() external view override returns (uint256); |``|`uint256`|The total raised amount as a uint256 value.| +### getLifetimeRaisedAmount + +Retrieves the lifetime raised amount in the treasury (never decreases with refunds). + + +```solidity +function getLifetimeRaisedAmount() external view override returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The lifetime raised amount as a uint256 value.| + + +### getRefundedAmount + +Retrieves the total refunded amount in the treasury. + + +```solidity +function getRefundedAmount() external view override returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The total refunded amount as a uint256 value.| + + ### getAvailableRaisedAmount Retrieves the currently available raised amount in the treasury. @@ -369,7 +362,7 @@ function getPaymentGatewayFee(bytes32 pledgeId) public view returns (uint256); ### getFeeValue -*Retrieves the fee value associated with a specific fee key from storage.* +Retrieves the fee value associated with a specific fee key from storage. ```solidity @@ -427,8 +420,8 @@ function approveWithdrawal() ### configureTreasury -*Configures the treasury for a campaign by setting the system parameters, -campaign-specific data, and fee configuration keys.* +Configures the treasury for a campaign by setting the system parameters, +campaign-specific data, and fee configuration keys. ```solidity @@ -457,7 +450,7 @@ function configureTreasury( ### updateDeadline -*Updates the campaign's deadline.* +Updates the campaign's deadline. ```solidity @@ -477,7 +470,7 @@ function updateDeadline(uint256 deadline) ### updateGoalAmount -*Updates the funding goal amount for the campaign.* +Updates the funding goal amount for the campaign. ```solidity @@ -499,10 +492,10 @@ function updateGoalAmount(uint256 goalAmount) Adds multiple rewards in a batch. -*This function allows for both reward tiers and non-reward tiers. +This function allows for both reward tiers and non-reward tiers. For both types, rewards must have non-zero value. If items are specified (non-empty arrays), the itemId, itemValue, and itemQuantity arrays must match in length. -Empty arrays are allowed for both reward tiers and non-reward tiers.* +Empty arrays are allowed for both reward tiers and non-reward tiers. ```solidity @@ -560,6 +553,7 @@ function setFeeAndPledge( bool isPledgeForAReward ) external + nonReentrant onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenNotPaused @@ -584,13 +578,20 @@ function setFeeAndPledge( Allows a backer to pledge for a reward. -*The first element of the `reward` array must be a reward tier and the other elements can be either reward tiers or non-reward tiers. -The non-reward tiers cannot be pledged for without a reward.* +The first element of the `reward` array must be a reward tier and the other elements can be either reward tiers or non-reward tiers. +The non-reward tiers cannot be pledged for without a reward. ```solidity -function pledgeForAReward(bytes32 pledgeId, address backer, address pledgeToken, uint256 tip, bytes32[] calldata reward) +function pledgeForAReward( + bytes32 pledgeId, + address backer, + address pledgeToken, + uint256 tip, + bytes32[] calldata reward +) public + nonReentrant currentTimeIsWithinRange(getLaunchTime(), getDeadline()) whenCampaignNotPaused whenNotPaused @@ -612,10 +613,10 @@ function pledgeForAReward(bytes32 pledgeId, address backer, address pledgeToken, Internal function that allows a backer to pledge for a reward with tokens transferred from a specified source. -*The first element of the `reward` array must be a reward tier and the other elements can be either reward tiers or non-reward tiers. +The first element of the `reward` array must be a reward tier and the other elements can be either reward tiers or non-reward tiers. The non-reward tiers cannot be pledged for without a reward. This function is called internally by both public pledgeForAReward (with backer as token source) and -setFeeAndPledge (with admin as token source).* +setFeeAndPledge (with admin as token source). ```solidity @@ -626,13 +627,7 @@ function _pledgeForAReward( uint256 tip, bytes32[] calldata reward, address tokenSource -) - internal - currentTimeIsWithinRange(getLaunchTime(), getDeadline()) - whenCampaignNotPaused - whenNotPaused - whenCampaignNotCancelled - whenNotCancelled; +) internal; ``` **Parameters** @@ -652,8 +647,15 @@ Allows a backer to pledge without selecting a reward. ```solidity -function pledgeWithoutAReward(bytes32 pledgeId, address backer, address pledgeToken, uint256 pledgeAmount, uint256 tip) +function pledgeWithoutAReward( + bytes32 pledgeId, + address backer, + address pledgeToken, + uint256 pledgeAmount, + uint256 tip +) public + nonReentrant currentTimeIsWithinRange(getLaunchTime(), getDeadline()) whenCampaignNotPaused whenNotPaused @@ -675,8 +677,8 @@ function pledgeWithoutAReward(bytes32 pledgeId, address backer, address pledgeTo Internal function that allows a backer to pledge without selecting a reward with tokens transferred from a specified source. -*This function is called internally by both public pledgeWithoutAReward (with backer as token source) and -setFeeAndPledge (with admin as token source).* +This function is called internally by both public pledgeWithoutAReward (with backer as token source) and +setFeeAndPledge (with admin as token source). ```solidity @@ -687,13 +689,7 @@ function _pledgeWithoutAReward( uint256 pledgeAmount, uint256 tip, address tokenSource -) - internal - currentTimeIsWithinRange(getLaunchTime(), getDeadline()) - whenCampaignNotPaused - whenNotPaused - whenCampaignNotCancelled - whenNotCancelled; +) internal; ``` **Parameters** @@ -718,7 +714,7 @@ function withdraw() public view override whenNotPaused whenNotCancelled; ### withdraw -*Allows the campaign owner or platform admin to withdraw funds, applying required fees and taxes.* +Allows the campaign owner or platform admin to withdraw funds, applying required fees and taxes. ```solidity @@ -740,7 +736,7 @@ function withdraw(address token, uint256 amount) ### claimRefund -*Allows a backer to claim a refund associated with a specific pledge (token ID).* +Allows a backer to claim a refund associated with a specific pledge (token ID). ```solidity @@ -759,9 +755,9 @@ function claimRefund(uint256 tokenId) ### disburseFees -*Disburses all accumulated fees to the appropriate fee collector or treasury. +Disburses all accumulated fees to the appropriate fee collector or treasury. Requirements: -- Only callable when fees are available.* +- Only callable when fees are available. ```solidity @@ -770,10 +766,10 @@ function disburseFees() public override whenNotPaused whenNotCancelled; ### claimTip -*Allows an authorized claimer to collect tips contributed during the campaign. +Allows an authorized claimer to collect tips contributed during the campaign. Requirements: - Caller must be authorized to claim tips. -- Tip amount must be non-zero.* +- Tip amount must be non-zero. ```solidity @@ -782,10 +778,10 @@ function claimTip() external onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPau ### claimFund -*Allows the platform admin to claim the remaining funds from a campaign. +Allows the platform admin to claim the remaining funds from a campaign. Requirements: - Claim period must have started and funds must be available. -- Cannot be previously claimed.* +- Cannot be previously claimed. ```solidity @@ -794,7 +790,7 @@ function claimFund() external onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPa ### cancelTreasury -*This function is overridden to allow the platform admin and the campaign owner to cancel a treasury.* +This function is overridden to allow the platform admin and the campaign owner to cancel a treasury. ```solidity @@ -803,7 +799,7 @@ function cancelTreasury(bytes32 message) public override onlyPlatformAdminOrCamp ### _checkSuccessCondition -*Internal function to check the success condition for fee disbursement.* +Internal function to check the success condition for fee disbursement. ```solidity @@ -827,7 +823,6 @@ function _pledge( bytes32 reward, uint256 pledgeAmount, uint256 tip, - uint256 tokenId, bytes32[] memory rewards, address tokenSource ) private; @@ -838,12 +833,12 @@ function _pledge( Calculates the net amount available from a pledge after deducting all applicable fees. -*The function performs the following: +The function performs the following: - Applies all configured gross percentage-based fees - Applies payment gateway fee for the given pledge - Applies protocol fee based on protocol configuration - Accumulates total platform and protocol fees per token -- Records the total deducted fee for the token* +- Records the total deducted fee for the token ```solidity @@ -874,9 +869,9 @@ Refund period logic: - If campaign is not cancelled: refund period is active until deadline + s_config.refundDelay - Before deadline (non-cancelled): not in refund period -*Checks the refund period status based on campaign state* +Checks the refund period status based on campaign state -*This function handles both cancelled and non-cancelled campaign scenarios* +This function handles both cancelled and non-cancelled campaign scenarios ```solidity @@ -895,16 +890,9 @@ function _checkRefundPeriodStatus(bool checkIfOver) internal view returns (bool) |``|`bool`|bool Status based on checkIfOver parameter| -### supportsInterface - - -```solidity -function supportsInterface(bytes4 interfaceId) public view override returns (bool); -``` - ## Events ### Receipt -*Emitted when a backer makes a pledge.* +Emitted when a backer makes a pledge. ```solidity @@ -932,7 +920,7 @@ event Receipt( |`rewards`|`bytes32[]`|An array of reward names.| ### RewardsAdded -*Emitted when rewards are added to the campaign.* +Emitted when rewards are added to the campaign. ```solidity @@ -947,7 +935,7 @@ event RewardsAdded(bytes32[] rewardNames, Reward[] rewards); |`rewards`|`Reward[]`|The details of the rewards.| ### RewardRemoved -*Emitted when a reward is removed from the campaign.* +Emitted when a reward is removed from the campaign. ```solidity @@ -961,7 +949,7 @@ event RewardRemoved(bytes32 indexed rewardName); |`rewardName`|`bytes32`|The name of the reward.| ### WithdrawalApproved -*Emitted when withdrawal functionality has been approved by the platform admin.* +Emitted when withdrawal functionality has been approved by the platform admin. ```solidity @@ -969,7 +957,7 @@ event WithdrawalApproved(); ``` ### TreasuryConfigured -*Emitted when the treasury configuration is updated.* +Emitted when the treasury configuration is updated. ```solidity @@ -986,7 +974,7 @@ event TreasuryConfigured(Config config, CampaignData campaignData, FeeKeys feeKe |`feeValues`|`FeeValues`|The fee values corresponding to the fee keys.| ### WithdrawalWithFeeSuccessful -*Emitted when a withdrawal is successfully processed along with the applied fee.* +Emitted when a withdrawal is successfully processed along with the applied fee. ```solidity @@ -1002,7 +990,7 @@ event WithdrawalWithFeeSuccessful(address indexed to, uint256 amount, uint256 fe |`fee`|`uint256`|The fee amount deducted from the withdrawal.| ### TipClaimed -*Emitted when a tip is claimed from the contract.* +Emitted when a tip is claimed from the contract. ```solidity @@ -1017,7 +1005,7 @@ event TipClaimed(uint256 amount, address indexed claimer); |`claimer`|`address`|The address that claimed the tip.| ### FundClaimed -*Emitted when campaign or user's remaining funds are successfully claimed by the platform admin.* +Emitted when campaign or user's remaining funds are successfully claimed by the platform admin. ```solidity @@ -1032,7 +1020,7 @@ event FundClaimed(uint256 amount, address indexed claimer); |`claimer`|`address`|The address that claimed the funds.| ### RefundClaimed -*Emitted when a refund is claimed.* +Emitted when a refund is claimed. ```solidity @@ -1048,7 +1036,7 @@ event RefundClaimed(uint256 indexed tokenId, uint256 refundAmount, address index |`claimer`|`address`|The address of the claimer.| ### KeepWhatsRaisedDeadlineUpdated -*Emitted when the deadline of the campaign is updated.* +Emitted when the deadline of the campaign is updated. ```solidity @@ -1062,7 +1050,7 @@ event KeepWhatsRaisedDeadlineUpdated(uint256 newDeadline); |`newDeadline`|`uint256`|The new deadline.| ### KeepWhatsRaisedGoalAmountUpdated -*Emitted when the goal amount for a campaign is updated.* +Emitted when the goal amount for a campaign is updated. ```solidity @@ -1076,7 +1064,7 @@ event KeepWhatsRaisedGoalAmountUpdated(uint256 newGoalAmount); |`newGoalAmount`|`uint256`|The new goal amount set for the campaign.| ### KeepWhatsRaisedPaymentGatewayFeeSet -*Emitted when a gateway fee is set for a specific pledge.* +Emitted when a gateway fee is set for a specific pledge. ```solidity @@ -1092,7 +1080,7 @@ event KeepWhatsRaisedPaymentGatewayFeeSet(bytes32 indexed pledgeId, uint256 fee) ## Errors ### KeepWhatsRaisedUnAuthorized -*Emitted when an unauthorized action is attempted.* +Emitted when an unauthorized action is attempted. ```solidity @@ -1100,7 +1088,7 @@ error KeepWhatsRaisedUnAuthorized(); ``` ### KeepWhatsRaisedInvalidInput -*Emitted when an invalid input is detected.* +Emitted when an invalid input is detected. ```solidity @@ -1108,7 +1096,7 @@ error KeepWhatsRaisedInvalidInput(); ``` ### KeepWhatsRaisedTokenNotAccepted -*Emitted when a token is not accepted for the campaign.* +Emitted when a token is not accepted for the campaign. ```solidity @@ -1116,7 +1104,7 @@ error KeepWhatsRaisedTokenNotAccepted(address token); ``` ### KeepWhatsRaisedRewardExists -*Emitted when a `Reward` already exists for given input.* +Emitted when a `Reward` already exists for given input. ```solidity @@ -1124,7 +1112,7 @@ error KeepWhatsRaisedRewardExists(); ``` ### KeepWhatsRaisedDisabled -*Emitted when anyone called a disabled function.* +Emitted when anyone called a disabled function. ```solidity @@ -1132,7 +1120,7 @@ error KeepWhatsRaisedDisabled(); ``` ### KeepWhatsRaisedAlreadyEnabled -*Emitted when any functionality is already enabled and cannot be re-enabled.* +Emitted when any functionality is already enabled and cannot be re-enabled. ```solidity @@ -1140,7 +1128,7 @@ error KeepWhatsRaisedAlreadyEnabled(); ``` ### KeepWhatsRaisedInsufficientFundsForWithdrawalAndFee -*Emitted when a withdrawal attempt exceeds the available funds after accounting for the fee.* +Emitted when a withdrawal attempt exceeds the available funds after accounting for the fee. ```solidity @@ -1173,7 +1161,7 @@ error KeepWhatsRaisedInsufficientFundsForFee(uint256 withdrawalAmount, uint256 f |`fee`|`uint256`|The calculated fee, which is greater than the withdrawal amount.| ### KeepWhatsRaisedAlreadyWithdrawn -*Emitted when a withdrawal has already been made and cannot be repeated.* +Emitted when a withdrawal has already been made and cannot be repeated. ```solidity @@ -1181,7 +1169,7 @@ error KeepWhatsRaisedAlreadyWithdrawn(); ``` ### KeepWhatsRaisedAlreadyClaimed -*Emitted when funds or rewards have already been claimed for the given context.* +Emitted when funds or rewards have already been claimed for the given context. ```solidity @@ -1189,7 +1177,7 @@ error KeepWhatsRaisedAlreadyClaimed(); ``` ### KeepWhatsRaisedNotClaimable -*Emitted when a token or pledge is not eligible for claiming (e.g., claim period not reached or not valid).* +Emitted when a token or pledge is not eligible for claiming (e.g., claim period not reached or not valid). ```solidity @@ -1203,7 +1191,7 @@ error KeepWhatsRaisedNotClaimable(uint256 tokenId); |`tokenId`|`uint256`|The ID of the token that was attempted to be claimed.| ### KeepWhatsRaisedNotClaimableAdmin -*Emitted when an admin attempts to claim funds that are not yet claimable according to the rules.* +Emitted when an admin attempts to claim funds that are not yet claimable according to the rules. ```solidity @@ -1211,7 +1199,7 @@ error KeepWhatsRaisedNotClaimableAdmin(); ``` ### KeepWhatsRaisedConfigLocked -*Emitted when a configuration change is attempted during the lock period.* +Emitted when a configuration change is attempted during the lock period. ```solidity @@ -1219,7 +1207,7 @@ error KeepWhatsRaisedConfigLocked(); ``` ### KeepWhatsRaisedDisbursementBlocked -*Emitted when a disbursement is attempted before the refund period has ended.* +Emitted when a disbursement is attempted before the refund period has ended. ```solidity @@ -1227,7 +1215,7 @@ error KeepWhatsRaisedDisbursementBlocked(); ``` ### KeepWhatsRaisedPledgeAlreadyProcessed -*Emitted when a pledge is submitted using a pledgeId that has already been processed.* +Emitted when a pledge is submitted using a pledgeId that has already been processed. ```solidity @@ -1242,42 +1230,61 @@ error KeepWhatsRaisedPledgeAlreadyProcessed(bytes32 pledgeId); ## Structs ### FeeKeys -*Represents keys used to reference different fee configurations. -These keys are typically used to look up fee values stored in `s_platformData`.* +Represents keys used to reference different fee configurations. +These keys are typically used to look up fee values stored in `s_platformData`. ```solidity struct FeeKeys { + /// @dev Key for a flat fee applied to an operation. bytes32 flatFeeKey; + + /// @dev Key for a cumulative flat fee, potentially across multiple actions. bytes32 cumulativeFlatFeeKey; + + /// @dev Keys for gross percentage-based fees (calculated before deductions). bytes32[] grossPercentageFeeKeys; } ``` ### FeeValues -*Represents the complete fee structure values for treasury operations. +Represents the complete fee structure values for treasury operations. These values correspond to the fees that will be applied to transactions -and are typically retrieved using keys from `FeeKeys` struct.* +and are typically retrieved using keys from `FeeKeys` struct. ```solidity struct FeeValues { + /// @dev Value for a flat fee applied to an operation. uint256 flatFeeValue; + + /// @dev Value for a cumulative flat fee, potentially across multiple actions. uint256 cumulativeFlatFeeValue; + + /// @dev Values for gross percentage-based fees (calculated before deductions). uint256[] grossPercentageFeeValues; } ``` ### Config -*System configuration parameters related to withdrawal and refund behavior.* +System configuration parameters related to withdrawal and refund behavior. ```solidity struct Config { + /// @dev The minimum withdrawal amount required to qualify for fee exemption. uint256 minimumWithdrawalForFeeExemption; + + /// @dev Time delay (in timestamp) enforced before a withdrawal can be completed. uint256 withdrawalDelay; + + /// @dev Time delay (in timestamp) before a refund becomes claimable or processed. uint256 refundDelay; + + /// @dev Duration (in timestamp) for which config changes are locked to prevent immediate updates. uint256 configLockPeriod; + + /// @dev True if the creator is Colombian, false otherwise. bool isColombianCreator; } ``` diff --git a/docs/src/src/treasuries/PaymentTreasury.sol/contract.PaymentTreasury.md b/docs/src/src/treasuries/PaymentTreasury.sol/contract.PaymentTreasury.md index 6aa15dbe..ccfc93fb 100644 --- a/docs/src/src/treasuries/PaymentTreasury.sol/contract.PaymentTreasury.md +++ b/docs/src/src/treasuries/PaymentTreasury.sol/contract.PaymentTreasury.md @@ -1,56 +1,25 @@ # PaymentTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/treasuries/PaymentTreasury.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/treasuries/PaymentTreasury.sol) **Inherits:** -[BasePaymentTreasury](/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md) - - -## State Variables -### s_name - -```solidity -string private s_name; -``` - - -### s_symbol - -```solidity -string private s_symbol; -``` +[BasePaymentTreasury](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md) ## Functions ### constructor -*Constructor for the PaymentTreasury contract.* +Constructor for the PaymentTreasury contract. ```solidity -constructor(); +constructor() ; ``` ### initialize ```solidity -function initialize(bytes32 _platformHash, address _infoAddress, string calldata _name, string calldata _symbol) - external - initializer; -``` - -### name - - -```solidity -function name() public view returns (string memory); -``` - -### symbol - - -```solidity -function symbol() public view returns (string memory); +function initialize(bytes32 _platformHash, address _infoAddress) external initializer; ``` ### createPayment @@ -65,7 +34,9 @@ function createPayment( bytes32 itemId, address paymentToken, uint256 amount, - uint256 expiration + uint256 expiration, + ICampaignPaymentTreasury.LineItem[] calldata lineItems, + ICampaignPaymentTreasury.ExternalFees[] calldata externalFees ) public override whenNotPaused whenNotCancelled; ``` **Parameters** @@ -78,13 +49,46 @@ function createPayment( |`paymentToken`|`address`|The token to use for the payment.| |`amount`|`uint256`|The amount to be paid for the item.| |`expiration`|`uint256`|The timestamp after which the payment expires.| +|`lineItems`|`ICampaignPaymentTreasury.LineItem[]`|Array of line items associated with this payment.| +|`externalFees`|`ICampaignPaymentTreasury.ExternalFees[]`|Array of external fees associated with this payment.| + + +### createPaymentBatch + +Creates multiple payment entries in a single transaction to prevent nonce conflicts. + + +```solidity +function createPaymentBatch( + bytes32[] calldata paymentIds, + bytes32[] calldata buyerIds, + bytes32[] calldata itemIds, + address[] calldata paymentTokens, + uint256[] calldata amounts, + uint256[] calldata expirations, + ICampaignPaymentTreasury.LineItem[][] calldata lineItemsArray, + ICampaignPaymentTreasury.ExternalFees[][] calldata externalFeesArray +) public override whenNotPaused whenNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentIds`|`bytes32[]`|An array of unique identifiers for the payments.| +|`buyerIds`|`bytes32[]`|An array of buyer IDs corresponding to each payment.| +|`itemIds`|`bytes32[]`|An array of item identifiers corresponding to each payment.| +|`paymentTokens`|`address[]`|An array of tokens corresponding to each payment.| +|`amounts`|`uint256[]`|An array of amounts corresponding to each payment.| +|`expirations`|`uint256[]`|An array of expiration timestamps corresponding to each payment.| +|`lineItemsArray`|`ICampaignPaymentTreasury.LineItem[][]`|An array of line item arrays, one for each payment.| +|`externalFeesArray`|`ICampaignPaymentTreasury.ExternalFees[][]`|An array of external fees arrays, one for each payment.| ### processCryptoPayment Allows a buyer to make a direct crypto payment for an item. -*This function transfers tokens directly from the buyer's wallet and confirms the payment immediately.* +This function transfers tokens directly from the buyer's wallet and confirms the payment immediately. ```solidity @@ -93,7 +97,9 @@ function processCryptoPayment( bytes32 itemId, address buyerAddress, address paymentToken, - uint256 amount + uint256 amount, + ICampaignPaymentTreasury.LineItem[] calldata lineItems, + ICampaignPaymentTreasury.ExternalFees[] calldata externalFees ) public override whenNotPaused whenNotCancelled; ``` **Parameters** @@ -105,6 +111,8 @@ function processCryptoPayment( |`buyerAddress`|`address`|The address of the buyer making the payment.| |`paymentToken`|`address`|The token to use for the payment.| |`amount`|`uint256`|The amount to be paid for the item.| +|`lineItems`|`ICampaignPaymentTreasury.LineItem[]`|Array of line items associated with this payment.| +|`externalFees`|`ICampaignPaymentTreasury.ExternalFees[]`|Array of external fees associated with this payment.| ### cancelPayment @@ -128,13 +136,14 @@ Confirms and finalizes the payment associated with the given payment ID. ```solidity -function confirmPayment(bytes32 paymentId) public override whenNotPaused whenNotCancelled; +function confirmPayment(bytes32 paymentId, address buyerAddress) public override whenNotPaused whenNotCancelled; ``` **Parameters** |Name|Type|Description| |----|----|-----------| |`paymentId`|`bytes32`|The unique identifier of the payment to confirm.| +|`buyerAddress`|`address`|Optional buyer address to mint NFT to. Pass address(0) to skip NFT minting.| ### confirmPaymentBatch @@ -143,18 +152,25 @@ Confirms and finalizes multiple payments in a single transaction. ```solidity -function confirmPaymentBatch(bytes32[] calldata paymentIds) public override whenNotPaused whenNotCancelled; +function confirmPaymentBatch(bytes32[] calldata paymentIds, address[] calldata buyerAddresses) + public + override + whenNotPaused + whenNotCancelled; ``` **Parameters** |Name|Type|Description| |----|----|-----------| |`paymentIds`|`bytes32[]`|An array of unique payment identifiers to be confirmed.| +|`buyerAddresses`|`address[]`|Array of buyer addresses to mint NFTs to. Must match paymentIds length. Pass address(0) to skip NFT minting for specific payments.| ### claimRefund -Claims a refund for a specific payment ID. +Claims a refund for non-NFT payments (payments without minted NFTs). + +Only callable by platform admin. Used for payments confirmed without a buyer address. ```solidity @@ -164,13 +180,15 @@ function claimRefund(bytes32 paymentId, address refundAddress) public override w |Name|Type|Description| |----|----|-----------| -|`paymentId`|`bytes32`|The unique identifier of the refundable payment.| +|`paymentId`|`bytes32`|The unique identifier of the refundable payment (must NOT have an NFT).| |`refundAddress`|`address`|The address where the refunded amount should be sent.| ### claimRefund -Claims a refund for a specific payment ID. +Claims a refund for non-NFT payments (payments without minted NFTs). + +Only callable by platform admin. Used for payments confirmed without a buyer address. ```solidity @@ -180,8 +198,17 @@ function claimRefund(bytes32 paymentId) public override whenNotPaused whenNotCan |Name|Type|Description| |----|----|-----------| -|`paymentId`|`bytes32`|The unique identifier of the refundable payment.| +|`paymentId`|`bytes32`|The unique identifier of the refundable payment (must NOT have an NFT).| + +### claimExpiredFunds + +Allows platform admin to claim all remaining funds once the claim window has opened. + + +```solidity +function claimExpiredFunds() public override whenNotPaused whenNotCancelled; +``` ### disburseFees @@ -203,7 +230,7 @@ function withdraw() public override whenNotPaused whenNotCancelled; ### cancelTreasury -*This function is overridden to allow the platform admin and the campaign owner to cancel a treasury.* +This function is overridden to allow the platform admin and the campaign owner to cancel a treasury. ```solidity @@ -212,7 +239,7 @@ function cancelTreasury(bytes32 message) public override; ### _checkSuccessCondition -*Internal function to check the success condition for fee disbursement.* +Internal function to check the success condition for fee disbursement. ```solidity @@ -227,7 +254,7 @@ function _checkSuccessCondition() internal view virtual override returns (bool); ## Errors ### PaymentTreasuryUnAuthorized -*Emitted when an unauthorized action is attempted.* +Emitted when an unauthorized action is attempted. ```solidity diff --git a/docs/src/src/treasuries/README.md b/docs/src/src/treasuries/README.md index 00a1cf9d..6babb651 100644 --- a/docs/src/src/treasuries/README.md +++ b/docs/src/src/treasuries/README.md @@ -4,3 +4,4 @@ - [AllOrNothing](AllOrNothing.sol/contract.AllOrNothing.md) - [KeepWhatsRaised](KeepWhatsRaised.sol/contract.KeepWhatsRaised.md) - [PaymentTreasury](PaymentTreasury.sol/contract.PaymentTreasury.md) +- [TimeConstrainedPaymentTreasury](TimeConstrainedPaymentTreasury.sol/contract.TimeConstrainedPaymentTreasury.md) diff --git a/docs/src/src/treasuries/TimeConstrainedPaymentTreasury.sol/contract.TimeConstrainedPaymentTreasury.md b/docs/src/src/treasuries/TimeConstrainedPaymentTreasury.sol/contract.TimeConstrainedPaymentTreasury.md new file mode 100644 index 00000000..ae4b4f65 --- /dev/null +++ b/docs/src/src/treasuries/TimeConstrainedPaymentTreasury.sol/contract.TimeConstrainedPaymentTreasury.md @@ -0,0 +1,289 @@ +# TimeConstrainedPaymentTreasury +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/treasuries/TimeConstrainedPaymentTreasury.sol) + +**Inherits:** +[BasePaymentTreasury](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md), [TimestampChecker](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md) + + +## Functions +### constructor + +Constructor for the TimeConstrainedPaymentTreasury contract. + + +```solidity +constructor() ; +``` + +### initialize + + +```solidity +function initialize(bytes32 _platformHash, address _infoAddress) external initializer; +``` + +### _checkTimeWithinRange + +Internal function to check if current time is within the allowed range. + + +```solidity +function _checkTimeWithinRange() internal view; +``` + +### _checkTimeIsGreater + +Internal function to check if current time is greater than launch time. + + +```solidity +function _checkTimeIsGreater() internal view; +``` + +### createPayment + +Creates a new payment entry with the specified details. + + +```solidity +function createPayment( + bytes32 paymentId, + bytes32 buyerId, + bytes32 itemId, + address paymentToken, + uint256 amount, + uint256 expiration, + ICampaignPaymentTreasury.LineItem[] calldata lineItems, + ICampaignPaymentTreasury.ExternalFees[] calldata externalFees +) public override whenCampaignNotPaused whenCampaignNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|A unique identifier for the payment.| +|`buyerId`|`bytes32`|The id of the buyer initiating the payment.| +|`itemId`|`bytes32`|The identifier of the item being purchased.| +|`paymentToken`|`address`|The token to use for the payment.| +|`amount`|`uint256`|The amount to be paid for the item.| +|`expiration`|`uint256`|The timestamp after which the payment expires.| +|`lineItems`|`ICampaignPaymentTreasury.LineItem[]`|Array of line items associated with this payment.| +|`externalFees`|`ICampaignPaymentTreasury.ExternalFees[]`|Array of external fees associated with this payment.| + + +### createPaymentBatch + +Creates multiple payment entries in a single transaction to prevent nonce conflicts. + + +```solidity +function createPaymentBatch( + bytes32[] calldata paymentIds, + bytes32[] calldata buyerIds, + bytes32[] calldata itemIds, + address[] calldata paymentTokens, + uint256[] calldata amounts, + uint256[] calldata expirations, + ICampaignPaymentTreasury.LineItem[][] calldata lineItemsArray, + ICampaignPaymentTreasury.ExternalFees[][] calldata externalFeesArray +) public override whenCampaignNotPaused whenCampaignNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentIds`|`bytes32[]`|An array of unique identifiers for the payments.| +|`buyerIds`|`bytes32[]`|An array of buyer IDs corresponding to each payment.| +|`itemIds`|`bytes32[]`|An array of item identifiers corresponding to each payment.| +|`paymentTokens`|`address[]`|An array of tokens corresponding to each payment.| +|`amounts`|`uint256[]`|An array of amounts corresponding to each payment.| +|`expirations`|`uint256[]`|An array of expiration timestamps corresponding to each payment.| +|`lineItemsArray`|`ICampaignPaymentTreasury.LineItem[][]`|An array of line item arrays, one for each payment.| +|`externalFeesArray`|`ICampaignPaymentTreasury.ExternalFees[][]`|An array of external fees arrays, one for each payment.| + + +### processCryptoPayment + +Allows a buyer to make a direct crypto payment for an item. + +This function transfers tokens directly from the buyer's wallet and confirms the payment immediately. + + +```solidity +function processCryptoPayment( + bytes32 paymentId, + bytes32 itemId, + address buyerAddress, + address paymentToken, + uint256 amount, + ICampaignPaymentTreasury.LineItem[] calldata lineItems, + ICampaignPaymentTreasury.ExternalFees[] calldata externalFees +) public override whenCampaignNotPaused whenCampaignNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the payment.| +|`itemId`|`bytes32`|The identifier of the item being purchased.| +|`buyerAddress`|`address`|The address of the buyer making the payment.| +|`paymentToken`|`address`|The token to use for the payment.| +|`amount`|`uint256`|The amount to be paid for the item.| +|`lineItems`|`ICampaignPaymentTreasury.LineItem[]`|Array of line items associated with this payment.| +|`externalFees`|`ICampaignPaymentTreasury.ExternalFees[]`|Array of external fees associated with this payment.| + + +### cancelPayment + +Cancels an existing payment with the given payment ID. + + +```solidity +function cancelPayment(bytes32 paymentId) public override whenCampaignNotPaused whenCampaignNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the payment to cancel.| + + +### confirmPayment + +Confirms and finalizes the payment associated with the given payment ID. + + +```solidity +function confirmPayment(bytes32 paymentId, address buyerAddress) + public + override + whenCampaignNotPaused + whenCampaignNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the payment to confirm.| +|`buyerAddress`|`address`|Optional buyer address to mint NFT to. Pass address(0) to skip NFT minting.| + + +### confirmPaymentBatch + +Confirms and finalizes multiple payments in a single transaction. + + +```solidity +function confirmPaymentBatch(bytes32[] calldata paymentIds, address[] calldata buyerAddresses) + public + override + whenCampaignNotPaused + whenCampaignNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentIds`|`bytes32[]`|An array of unique payment identifiers to be confirmed.| +|`buyerAddresses`|`address[]`|Array of buyer addresses to mint NFTs to. Must match paymentIds length. Pass address(0) to skip NFT minting for specific payments.| + + +### claimRefund + +Claims a refund for non-NFT payments (payments without minted NFTs). + +Only callable by platform admin. Used for payments confirmed without a buyer address. + + +```solidity +function claimRefund(bytes32 paymentId, address refundAddress) + public + override + whenCampaignNotPaused + whenCampaignNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the refundable payment (must NOT have an NFT).| +|`refundAddress`|`address`|The address where the refunded amount should be sent.| + + +### claimRefund + +Claims a refund for non-NFT payments (payments without minted NFTs). + +Only callable by platform admin. Used for payments confirmed without a buyer address. + + +```solidity +function claimRefund(bytes32 paymentId) public override whenCampaignNotPaused whenCampaignNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the refundable payment (must NOT have an NFT).| + + +### claimExpiredFunds + +Allows platform admin to claim all remaining funds once the claim window has opened. + + +```solidity +function claimExpiredFunds() public override whenCampaignNotPaused whenCampaignNotCancelled; +``` + +### disburseFees + +Disburses fees collected by the treasury. + + +```solidity +function disburseFees() public override whenCampaignNotPaused whenCampaignNotCancelled; +``` + +### withdraw + +Withdraws funds from the treasury. + + +```solidity +function withdraw() public override whenCampaignNotPaused whenCampaignNotCancelled; +``` + +### cancelTreasury + +This function is overridden to allow the platform admin and the campaign owner to cancel a treasury. + + +```solidity +function cancelTreasury(bytes32 message) public override; +``` + +### _checkSuccessCondition + +Internal function to check the success condition for fee disbursement. + + +```solidity +function _checkSuccessCondition() internal view virtual override returns (bool); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|Whether the success condition is met.| + + +## Errors +### TimeConstrainedPaymentTreasuryUnAuthorized +Emitted when an unauthorized action is attempted. + + +```solidity +error TimeConstrainedPaymentTreasuryUnAuthorized(); +``` + diff --git a/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md b/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md index e774d9e3..f5e6cd5d 100644 --- a/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md +++ b/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md @@ -1,35 +1,19 @@ # AdminAccessChecker -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/utils/AdminAccessChecker.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/utils/AdminAccessChecker.sol) **Inherits:** Context -*This abstract contract provides access control mechanisms to restrict the execution of specific functions -to authorized protocol administrators and platform administrators.* +This abstract contract provides access control mechanisms to restrict the execution of specific functions +to authorized protocol administrators and platform administrators. -*Updated to use ERC-7201 namespaced storage for upgradeable contracts* - - -## State Variables -### ADMIN_ACCESS_CHECKER_STORAGE_LOCATION - -```solidity -bytes32 private constant ADMIN_ACCESS_CHECKER_STORAGE_LOCATION = - 0x7c2f08fa04c2c7c7ab255a45dbf913d4c236b91c59858917e818398e997f8800; -``` +Updated to use ERC-7201 namespaced storage for upgradeable contracts ## Functions -### _getAdminAccessCheckerStorage - - -```solidity -function _getAdminAccessCheckerStorage() private pure returns (AdminAccessCheckerStorage storage $); -``` - ### __AccessChecker_init -*Internal initializer function for AdminAccessChecker* +Internal initializer function for AdminAccessChecker ```solidity @@ -44,7 +28,7 @@ function __AccessChecker_init(IGlobalParams globalParams) internal; ### _getGlobalParams -*Returns the stored GLOBAL_PARAMS for internal use* +Returns the stored GLOBAL_PARAMS for internal use ```solidity @@ -53,22 +37,22 @@ function _getGlobalParams() internal view returns (IGlobalParams); ### onlyProtocolAdmin -*Modifier that restricts function access to protocol administrators only. -Users attempting to execute functions with this modifier must be the protocol admin.* +Modifier that restricts function access to protocol administrators only. +Users attempting to execute functions with this modifier must be the protocol admin. ```solidity -modifier onlyProtocolAdmin(); +modifier onlyProtocolAdmin() ; ``` ### onlyPlatformAdmin -*Modifier that restricts function access to platform administrators of a specific platform. -Users attempting to execute functions with this modifier must be the platform admin for the given platform.* +Modifier that restricts function access to platform administrators of a specific platform. +Users attempting to execute functions with this modifier must be the platform admin for the given platform. ```solidity -modifier onlyPlatformAdmin(bytes32 platformHash); +modifier onlyPlatformAdmin(bytes32 platformHash) ; ``` **Parameters** @@ -79,8 +63,8 @@ modifier onlyPlatformAdmin(bytes32 platformHash); ### _onlyProtocolAdmin -*Internal function to check if the sender is the protocol administrator. -If the sender is not the protocol admin, it reverts with AdminAccessCheckerUnauthorized error.* +Internal function to check if the sender is the protocol administrator. +If the sender is not the protocol admin, it reverts with AdminAccessCheckerUnauthorized error. ```solidity @@ -89,8 +73,8 @@ function _onlyProtocolAdmin() private view; ### _onlyPlatformAdmin -*Internal function to check if the sender is the platform administrator for a specific platform. -If the sender is not the platform admin, it reverts with AdminAccessCheckerUnauthorized error.* +Internal function to check if the sender is the platform administrator for a specific platform. +If the sender is not the platform admin, it reverts with AdminAccessCheckerUnauthorized error. ```solidity @@ -105,22 +89,10 @@ function _onlyPlatformAdmin(bytes32 platformHash) private view; ## Errors ### AdminAccessCheckerUnauthorized -*Throws when the caller is not authorized.* +Throws when the caller is not authorized. ```solidity error AdminAccessCheckerUnauthorized(); ``` -## Structs -### AdminAccessCheckerStorage -**Note:** -storage-location: erc7201:ccprotocol.storage.AdminAccessChecker - - -```solidity -struct AdminAccessCheckerStorage { - IGlobalParams globalParams; -} -``` - diff --git a/docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md b/docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md index fa046084..353df14d 100644 --- a/docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md +++ b/docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md @@ -1,134 +1,191 @@ # BasePaymentTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/utils/BasePaymentTreasury.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/utils/BasePaymentTreasury.sol) **Inherits:** -Initializable, [ICampaignPaymentTreasury](/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md), [CampaignAccessChecker](/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md), [PausableCancellable](/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md) +Initializable, [ICampaignPaymentTreasury](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md), [CampaignAccessChecker](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md), [PausableCancellable](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md), ReentrancyGuard ## State Variables ### ZERO_BYTES ```solidity -bytes32 internal constant ZERO_BYTES = 0x0000000000000000000000000000000000000000000000000000000000000000; +bytes32 internal constant ZERO_BYTES = 0x0000000000000000000000000000000000000000000000000000000000000000 ``` ### PERCENT_DIVIDER ```solidity -uint256 internal constant PERCENT_DIVIDER = 10000; +uint256 internal constant PERCENT_DIVIDER = 10000 ``` ### STANDARD_DECIMALS ```solidity -uint256 internal constant STANDARD_DECIMALS = 18; +uint256 internal constant STANDARD_DECIMALS = 18 ``` ### PLATFORM_HASH ```solidity -bytes32 internal PLATFORM_HASH; +bytes32 internal PLATFORM_HASH ``` ### PLATFORM_FEE_PERCENT ```solidity -uint256 internal PLATFORM_FEE_PERCENT; +uint256 internal PLATFORM_FEE_PERCENT ``` ### s_paymentIdToToken ```solidity -mapping(bytes32 => address) internal s_paymentIdToToken; +mapping(bytes32 => address) internal s_paymentIdToToken ``` ### s_platformFeePerToken ```solidity -mapping(address => uint256) internal s_platformFeePerToken; +mapping(address => uint256) internal s_platformFeePerToken ``` ### s_protocolFeePerToken ```solidity -mapping(address => uint256) internal s_protocolFeePerToken; +mapping(address => uint256) internal s_protocolFeePerToken +``` + + +### s_paymentIdToTokenId + +```solidity +mapping(bytes32 => uint256) internal s_paymentIdToTokenId ``` ### s_payment ```solidity -mapping(bytes32 => PaymentInfo) internal s_payment; +mapping(bytes32 => PaymentInfo) internal s_payment +``` + + +### s_paymentLineItems + +```solidity +mapping(bytes32 => ICampaignPaymentTreasury.PaymentLineItem[]) internal s_paymentLineItems +``` + + +### s_paymentExternalFees + +```solidity +mapping(bytes32 => ICampaignPaymentTreasury.ExternalFees[]) internal s_paymentExternalFees ``` ### s_pendingPaymentPerToken ```solidity -mapping(address => uint256) internal s_pendingPaymentPerToken; +mapping(address => uint256) internal s_pendingPaymentPerToken ``` ### s_confirmedPaymentPerToken ```solidity -mapping(address => uint256) internal s_confirmedPaymentPerToken; +mapping(address => uint256) internal s_confirmedPaymentPerToken ``` -### s_availableConfirmedPerToken +### s_lifetimeConfirmedPaymentPerToken ```solidity -mapping(address => uint256) internal s_availableConfirmedPerToken; +mapping(address => uint256) internal s_lifetimeConfirmedPaymentPerToken ``` -## Functions -### __BaseContract_init +### s_availableConfirmedPerToken + +```solidity +mapping(address => uint256) internal s_availableConfirmedPerToken +``` + +### s_nonGoalLineItemPendingPerToken ```solidity -function __BaseContract_init(bytes32 platformHash, address infoAddress) internal; +mapping(address => uint256) internal s_nonGoalLineItemPendingPerToken ``` -### whenCampaignNotPaused -*Modifier that checks if the campaign is not paused.* +### s_nonGoalLineItemConfirmedPerToken + +```solidity +mapping(address => uint256) internal s_nonGoalLineItemConfirmedPerToken +``` + +### s_nonGoalLineItemClaimablePerToken ```solidity -modifier whenCampaignNotPaused(); +mapping(address => uint256) internal s_nonGoalLineItemClaimablePerToken ``` -### whenCampaignNotCancelled +### s_refundableNonGoalLineItemPerToken ```solidity -modifier whenCampaignNotCancelled(); +mapping(address => uint256) internal s_refundableNonGoalLineItemPerToken ``` -### onlyBuyerOrPlatformAdmin -Ensures that the caller is either the payment's buyer or the platform admin. +## Functions +### _getMaxExpirationDuration + +Retrieves the max expiration duration configured for the current platform or globally. ```solidity -modifier onlyBuyerOrPlatformAdmin(bytes32 paymentId); +function _getMaxExpirationDuration() internal view returns (bool hasLimit, uint256 duration); ``` -**Parameters** +**Returns** |Name|Type|Description| |----|----|-----------| -|`paymentId`|`bytes32`|The unique identifier of the payment to validate access for.| +|`hasLimit`|`bool`|Indicates whether a max expiration duration is configured.| +|`duration`|`uint256`|The max expiration duration in seconds.| +### __BaseContract_init + + +```solidity +function __BaseContract_init(bytes32 platformHash, address infoAddress) internal; +``` + +### whenCampaignNotPaused + +Modifier that checks if the campaign is not paused. + + +```solidity +modifier whenCampaignNotPaused() ; +``` + +### whenCampaignNotCancelled + + +```solidity +modifier whenCampaignNotCancelled() ; +``` + ### getplatformHash Retrieves the platform identifier associated with the treasury. @@ -189,9 +246,56 @@ function getAvailableRaisedAmount() external view returns (uint256); |``|`uint256`|The current available raised amount as a uint256 value.| +### getLifetimeRaisedAmount + +Retrieves the lifetime raised amount in the treasury (never decreases with refunds). + + +```solidity +function getLifetimeRaisedAmount() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The lifetime raised amount as a uint256 value.| + + +### getRefundedAmount + +Retrieves the total refunded amount in the treasury. + + +```solidity +function getRefundedAmount() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The total refunded amount as a uint256 value.| + + +### getExpectedAmount + +Retrieves the total expected (pending) amount in the treasury. + +This represents payments that have been created but not yet confirmed. + + +```solidity +function getExpectedAmount() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The total expected amount as a uint256 value.| + + ### _normalizeAmount -*Normalizes token amounts to 18 decimals for consistent comparisons.* +Normalizes token amounts to 18 decimals for consistent comparisons. ```solidity @@ -211,6 +315,27 @@ function _normalizeAmount(address token, uint256 amount) internal view returns ( |``|`uint256`|The normalized amount (scaled to 18 decimals).| +### _validateStoreAndTrackLineItems + +Validates, stores, and tracks line items in a single loop for gas efficiency. + + +```solidity +function _validateStoreAndTrackLineItems( + bytes32 paymentId, + ICampaignPaymentTreasury.LineItem[] calldata lineItems, + address paymentToken +) internal; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The payment ID to store line items for.| +|`lineItems`|`ICampaignPaymentTreasury.LineItem[]`|Array of line items to validate, store, and track.| +|`paymentToken`|`address`|The token used for the payment.| + + ### createPayment Creates a new payment entry with the specified details. @@ -223,7 +348,9 @@ function createPayment( bytes32 itemId, address paymentToken, uint256 amount, - uint256 expiration + uint256 expiration, + ICampaignPaymentTreasury.LineItem[] calldata lineItems, + ICampaignPaymentTreasury.ExternalFees[] calldata externalFees ) public virtual override onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled; ``` **Parameters** @@ -236,13 +363,46 @@ function createPayment( |`paymentToken`|`address`|The token to use for the payment.| |`amount`|`uint256`|The amount to be paid for the item.| |`expiration`|`uint256`|The timestamp after which the payment expires.| +|`lineItems`|`ICampaignPaymentTreasury.LineItem[]`|Array of line items associated with this payment.| +|`externalFees`|`ICampaignPaymentTreasury.ExternalFees[]`|Array of external fees associated with this payment.| + + +### createPaymentBatch + +Creates multiple payment entries in a single transaction to prevent nonce conflicts. + + +```solidity +function createPaymentBatch( + bytes32[] calldata paymentIds, + bytes32[] calldata buyerIds, + bytes32[] calldata itemIds, + address[] calldata paymentTokens, + uint256[] calldata amounts, + uint256[] calldata expirations, + ICampaignPaymentTreasury.LineItem[][] calldata lineItemsArray, + ICampaignPaymentTreasury.ExternalFees[][] calldata externalFeesArray +) public virtual override onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentIds`|`bytes32[]`|An array of unique identifiers for the payments.| +|`buyerIds`|`bytes32[]`|An array of buyer IDs corresponding to each payment.| +|`itemIds`|`bytes32[]`|An array of item identifiers corresponding to each payment.| +|`paymentTokens`|`address[]`|An array of tokens corresponding to each payment.| +|`amounts`|`uint256[]`|An array of amounts corresponding to each payment.| +|`expirations`|`uint256[]`|An array of expiration timestamps corresponding to each payment.| +|`lineItemsArray`|`ICampaignPaymentTreasury.LineItem[][]`|An array of line item arrays, one for each payment.| +|`externalFeesArray`|`ICampaignPaymentTreasury.ExternalFees[][]`|An array of external fees arrays, one for each payment.| ### processCryptoPayment Allows a buyer to make a direct crypto payment for an item. -*This function transfers tokens directly from the buyer's wallet and confirms the payment immediately.* +This function transfers tokens directly from the buyer's wallet and confirms the payment immediately. ```solidity @@ -251,8 +411,10 @@ function processCryptoPayment( bytes32 itemId, address buyerAddress, address paymentToken, - uint256 amount -) public virtual override whenCampaignNotPaused whenCampaignNotCancelled; + uint256 amount, + ICampaignPaymentTreasury.LineItem[] calldata lineItems, + ICampaignPaymentTreasury.ExternalFees[] calldata externalFees +) public virtual override nonReentrant whenCampaignNotPaused whenCampaignNotCancelled; ``` **Parameters** @@ -263,6 +425,8 @@ function processCryptoPayment( |`buyerAddress`|`address`|The address of the buyer making the payment.| |`paymentToken`|`address`|The token to use for the payment.| |`amount`|`uint256`|The amount to be paid for the item.| +|`lineItems`|`ICampaignPaymentTreasury.LineItem[]`|Array of line items associated with this payment.| +|`externalFees`|`ICampaignPaymentTreasury.ExternalFees[]`|Array of external fees associated with this payment.| ### cancelPayment @@ -286,16 +450,88 @@ function cancelPayment(bytes32 paymentId) |`paymentId`|`bytes32`|The unique identifier of the payment to cancel.| +### _calculateLineItemTotals + +Calculates line item totals for balance checking and state updates. + + +```solidity +function _calculateLineItemTotals( + ICampaignPaymentTreasury.PaymentLineItem[] storage lineItems, + uint256 protocolFeePercent +) internal view returns (LineItemTotals memory totals); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`lineItems`|`ICampaignPaymentTreasury.PaymentLineItem[]`|Array of line items to process.| +|`protocolFeePercent`|`uint256`|Protocol fee percentage.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`totals`|`LineItemTotals`|Struct containing all calculated totals.| + + +### _checkBalanceForConfirmation + +Checks if there's sufficient balance for payment confirmation. + + +```solidity +function _checkBalanceForConfirmation(address paymentToken, uint256 paymentAmount, LineItemTotals memory totals) + internal + view; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentToken`|`address`|The token address.| +|`paymentAmount`|`uint256`|The base payment amount.| +|`totals`|`LineItemTotals`|Line item totals struct.| + + +### _updateLineItemsForConfirmation + +Updates state for line items during payment confirmation. + + +```solidity +function _updateLineItemsForConfirmation( + address paymentToken, + ICampaignPaymentTreasury.PaymentLineItem[] storage lineItems, + uint256 protocolFeePercent +) internal returns (uint256 totalInstantTransferAmount); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentToken`|`address`|The token address.| +|`lineItems`|`ICampaignPaymentTreasury.PaymentLineItem[]`|Array of line items to process.| +|`protocolFeePercent`|`uint256`|Protocol fee percentage.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`totalInstantTransferAmount`|`uint256`|Total amount to transfer instantly.| + + ### confirmPayment Confirms and finalizes the payment associated with the given payment ID. ```solidity -function confirmPayment(bytes32 paymentId) +function confirmPayment(bytes32 paymentId, address buyerAddress) public virtual override + nonReentrant onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled; @@ -305,6 +541,7 @@ function confirmPayment(bytes32 paymentId) |Name|Type|Description| |----|----|-----------| |`paymentId`|`bytes32`|The unique identifier of the payment to confirm.| +|`buyerAddress`|`address`|Optional buyer address to mint NFT to. Pass address(0) to skip NFT minting.| ### confirmPaymentBatch @@ -313,10 +550,11 @@ Confirms and finalizes multiple payments in a single transaction. ```solidity -function confirmPaymentBatch(bytes32[] calldata paymentIds) +function confirmPaymentBatch(bytes32[] calldata paymentIds, address[] calldata buyerAddresses) public virtual override + nonReentrant onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled; @@ -326,11 +564,14 @@ function confirmPaymentBatch(bytes32[] calldata paymentIds) |Name|Type|Description| |----|----|-----------| |`paymentIds`|`bytes32[]`|An array of unique payment identifiers to be confirmed.| +|`buyerAddresses`|`address[]`|Array of buyer addresses to mint NFTs to. Must match paymentIds length. Pass address(0) to skip NFT minting for specific payments.| ### claimRefund -Claims a refund for a specific payment ID. +Claims a refund for non-NFT payments (payments without minted NFTs). + +For non-NFT payments only. Verifies that no NFT exists for this payment. ```solidity @@ -346,21 +587,46 @@ function claimRefund(bytes32 paymentId, address refundAddress) |Name|Type|Description| |----|----|-----------| -|`paymentId`|`bytes32`|The unique identifier of the refundable payment.| +|`paymentId`|`bytes32`|The unique identifier of the refundable payment (must NOT have an NFT).| |`refundAddress`|`address`|The address where the refunded amount should be sent.| ### claimRefund -Claims a refund for a specific payment ID. +Claims a refund for non-NFT payments (payments without minted NFTs). + +For NFT payments only. Requires an NFT exists and burns it. Refund is sent to current NFT owner. + + +```solidity +function claimRefund(bytes32 paymentId) public virtual override whenCampaignNotPaused whenCampaignNotCancelled; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the refundable payment (must NOT have an NFT).| + + +### disburseFees + +Disburses fees collected by the treasury. ```solidity -function claimRefund(bytes32 paymentId) +function disburseFees() public virtual override whenCampaignNotPaused whenCampaignNotCancelled; +``` + +### claimNonGoalLineItems + +Allows platform admin to claim non-goal line items that are available for claiming. + + +```solidity +function claimNonGoalLineItems(address token) public virtual - override - onlyBuyerOrPlatformAdmin(paymentId) + onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled; ``` @@ -368,16 +634,21 @@ function claimRefund(bytes32 paymentId) |Name|Type|Description| |----|----|-----------| -|`paymentId`|`bytes32`|The unique identifier of the refundable payment.| +|`token`|`address`|The token address to claim.| -### disburseFees +### claimExpiredFunds -Disburses fees collected by the treasury. +Allows the platform admin to claim all remaining funds once the claim window has opened. ```solidity -function disburseFees() public virtual override whenCampaignNotPaused whenCampaignNotCancelled; +function claimExpiredFunds() + public + virtual + onlyPlatformAdmin(PLATFORM_HASH) + whenCampaignNotPaused + whenCampaignNotCancelled; ``` ### withdraw @@ -391,7 +662,7 @@ function withdraw() public virtual override whenCampaignNotPaused whenCampaignNo ### pauseTreasury -*External function to pause the campaign.* +External function to pause the campaign. ```solidity @@ -400,7 +671,7 @@ function pauseTreasury(bytes32 message) public virtual onlyPlatformAdmin(PLATFOR ### unpauseTreasury -*External function to unpause the campaign.* +External function to unpause the campaign. ```solidity @@ -409,17 +680,32 @@ function unpauseTreasury(bytes32 message) public virtual onlyPlatformAdmin(PLATF ### cancelTreasury -*External function to cancel the campaign.* +External function to cancel the campaign. ```solidity function cancelTreasury(bytes32 message) public virtual onlyPlatformAdmin(PLATFORM_HASH); ``` +### cancelled + +Returns true if the treasury has been cancelled. + + +```solidity +function cancelled() public view virtual override(ICampaignPaymentTreasury, PausableCancellable) returns (bool); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|True if cancelled, false otherwise.| + + ### _revertIfCampaignPaused -*Internal function to check if the campaign is paused. -If the campaign is paused, it reverts with PaymentTreasuryCampaignInfoIsPaused error.* +Internal function to check if the campaign is paused. +If the campaign is paused, it reverts with PaymentTreasuryCampaignInfoIsPaused error. ```solidity @@ -435,12 +721,12 @@ function _revertIfCampaignCancelled() internal view; ### _validatePaymentForAction -*Validates the given payment ID to ensure it is eligible for further action. +Validates the given payment ID to ensure it is eligible for further action. Reverts if: - The payment does not exist. - The payment has already been confirmed. - The payment has already expired. -- The payment is a crypto payment* +- The payment is a crypto payment ```solidity @@ -453,9 +739,34 @@ function _validatePaymentForAction(bytes32 paymentId) internal view; |`paymentId`|`bytes32`|The unique identifier of the payment to validate.| +### getPaymentData + +Retrieves comprehensive payment data including payment info, token, line items, and external fees. + + +```solidity +function getPaymentData(bytes32 paymentId) + public + view + override + returns (ICampaignPaymentTreasury.PaymentData memory); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The unique identifier of the payment.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`ICampaignPaymentTreasury.PaymentData`|A PaymentData struct containing all payment information.| + + ### _checkSuccessCondition -*Internal function to check the success condition for fee disbursement.* +Internal function to check the success condition for fee disbursement. ```solidity @@ -470,7 +781,7 @@ function _checkSuccessCondition() internal view virtual returns (bool); ## Events ### PaymentCreated -*Emitted when a new payment is created.* +Emitted when a new payment is created. ```solidity @@ -500,7 +811,7 @@ event PaymentCreated( |`isCryptoPayment`|`bool`|Boolean indicating whether the payment is made using direct crypto payment.| ### PaymentCancelled -*Emitted when a payment is cancelled and removed from the treasury.* +Emitted when a payment is cancelled and removed from the treasury. ```solidity @@ -514,7 +825,7 @@ event PaymentCancelled(bytes32 indexed paymentId); |`paymentId`|`bytes32`|The unique identifier of the cancelled payment.| ### PaymentConfirmed -*Emitted when a payment is confirmed.* +Emitted when a payment is confirmed. ```solidity @@ -528,7 +839,7 @@ event PaymentConfirmed(bytes32 indexed paymentId); |`paymentId`|`bytes32`|The unique identifier of the cancelled payment.| ### PaymentBatchConfirmed -*Emitted when multiple payments are confirmed in a single batch operation.* +Emitted when multiple payments are confirmed in a single batch operation. ```solidity @@ -541,6 +852,20 @@ event PaymentBatchConfirmed(bytes32[] paymentIds); |----|----|-----------| |`paymentIds`|`bytes32[]`|An array of unique identifiers for the confirmed payments.| +### PaymentBatchCreated +Emitted when multiple payments are created in a single batch operation. + + +```solidity +event PaymentBatchCreated(bytes32[] paymentIds); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentIds`|`bytes32[]`|An array of unique identifiers for the created payments.| + ### FeesDisbursed Emitted when fees are successfully disbursed. @@ -558,7 +883,7 @@ event FeesDisbursed(address indexed token, uint256 protocolShare, uint256 platfo |`platformShare`|`uint256`|The amount of fees sent to the platform.| ### WithdrawalWithFeeSuccessful -*Emitted when a withdrawal is successfully processed along with the applied fee.* +Emitted when a withdrawal is successfully processed along with the applied fee. ```solidity @@ -575,7 +900,7 @@ event WithdrawalWithFeeSuccessful(address indexed token, address indexed to, uin |`fee`|`uint256`|The fee amount deducted from the withdrawal.| ### RefundClaimed -*Emitted when a refund is claimed.* +Emitted when a refund is claimed. ```solidity @@ -590,9 +915,41 @@ event RefundClaimed(bytes32 indexed paymentId, uint256 refundAmount, address ind |`refundAmount`|`uint256`|The refund amount claimed.| |`claimer`|`address`|The address of the claimer.| +### NonGoalLineItemsClaimed +Emitted when non-goal line items are claimed by the platform admin. + + +```solidity +event NonGoalLineItemsClaimed(address indexed token, uint256 amount, address indexed platformAdmin); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`token`|`address`|The token that was claimed.| +|`amount`|`uint256`|The amount claimed.| +|`platformAdmin`|`address`|The address of the platform admin who claimed.| + +### ExpiredFundsClaimed +Emitted when expired funds are claimed by the platform and protocol admins. + + +```solidity +event ExpiredFundsClaimed(address indexed token, uint256 platformAmount, uint256 protocolAmount); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`token`|`address`|The token that was claimed.| +|`platformAmount`|`uint256`|The amount sent to the platform admin.| +|`protocolAmount`|`uint256`|The amount sent to the protocol admin.| + ## Errors ### PaymentTreasuryInvalidInput -*Reverts when one or more provided inputs to the payment treasury are invalid.* +Reverts when one or more provided inputs to the payment treasury are invalid. ```solidity @@ -600,7 +957,7 @@ error PaymentTreasuryInvalidInput(); ``` ### PaymentTreasuryPaymentAlreadyExist -*Throws an error indicating that the payment id already exists.* +Throws an error indicating that the payment id already exists. ```solidity @@ -608,7 +965,7 @@ error PaymentTreasuryPaymentAlreadyExist(bytes32 paymentId); ``` ### PaymentTreasuryPaymentAlreadyConfirmed -*Throws an error indicating that the payment id is already confirmed.* +Throws an error indicating that the payment id is already confirmed. ```solidity @@ -616,7 +973,7 @@ error PaymentTreasuryPaymentAlreadyConfirmed(bytes32 paymentId); ``` ### PaymentTreasuryPaymentAlreadyExpired -*Throws an error indicating that the payment id is already expired.* +Throws an error indicating that the payment id is already expired. ```solidity @@ -624,7 +981,7 @@ error PaymentTreasuryPaymentAlreadyExpired(bytes32 paymentId); ``` ### PaymentTreasuryPaymentNotExist -*Throws an error indicating that the payment id does not exist.* +Throws an error indicating that the payment id does not exist. ```solidity @@ -632,7 +989,7 @@ error PaymentTreasuryPaymentNotExist(bytes32 paymentId); ``` ### PaymentTreasuryCampaignInfoIsPaused -*Throws an error indicating that the campaign is paused.* +Throws an error indicating that the campaign is paused. ```solidity @@ -640,7 +997,7 @@ error PaymentTreasuryCampaignInfoIsPaused(); ``` ### PaymentTreasuryTokenNotAccepted -*Emitted when a token is not accepted for the campaign.* +Emitted when a token is not accepted for the campaign. ```solidity @@ -648,7 +1005,7 @@ error PaymentTreasuryTokenNotAccepted(address token); ``` ### PaymentTreasurySuccessConditionNotFulfilled -*Throws an error indicating that the success condition was not fulfilled.* +Throws an error indicating that the success condition was not fulfilled. ```solidity @@ -656,7 +1013,7 @@ error PaymentTreasurySuccessConditionNotFulfilled(); ``` ### PaymentTreasuryFeeNotDisbursed -*Throws an error indicating that fees have not been disbursed.* +Throws an error indicating that fees have not been disbursed. ```solidity @@ -664,7 +1021,7 @@ error PaymentTreasuryFeeNotDisbursed(); ``` ### PaymentTreasuryPaymentNotConfirmed -*Throws an error indicating that the payment id is not confirmed.* +Throws an error indicating that the payment id is not confirmed. ```solidity @@ -672,7 +1029,7 @@ error PaymentTreasuryPaymentNotConfirmed(bytes32 paymentId); ``` ### PaymentTreasuryPaymentNotClaimable -*Emitted when claiming an unclaimable refund.* +Emitted when claiming an unclaimable refund. ```solidity @@ -686,7 +1043,7 @@ error PaymentTreasuryPaymentNotClaimable(bytes32 paymentId); |`paymentId`|`bytes32`|The unique identifier of the refundable payment.| ### PaymentTreasuryAlreadyWithdrawn -*Emitted when an attempt is made to withdraw funds from the treasury but the payment has already been withdrawn.* +Emitted when an attempt is made to withdraw funds from the treasury but the payment has already been withdrawn. ```solidity @@ -694,7 +1051,7 @@ error PaymentTreasuryAlreadyWithdrawn(); ``` ### PaymentTreasuryCryptoPayment -*This error is thrown when an operation is attempted on a crypto payment that is only valid for non-crypto payments.* +This error is thrown when an operation is attempted on a crypto payment that is only valid for non-crypto payments. ```solidity @@ -723,16 +1080,53 @@ error PaymentTreasuryInsufficientFundsForFee(uint256 withdrawalAmount, uint256 f |`fee`|`uint256`|The calculated fee, which is greater than the withdrawal amount.| ### PaymentTreasuryInsufficientBalance -*Emitted when there are insufficient unallocated tokens for a payment confirmation.* +Emitted when there are insufficient unallocated tokens for a payment confirmation. ```solidity error PaymentTreasuryInsufficientBalance(uint256 required, uint256 available); ``` +### PaymentTreasuryExpirationExceedsMax +Throws an error indicating that the payment expiration exceeds the maximum allowed expiration time. + + +```solidity +error PaymentTreasuryExpirationExceedsMax(uint256 expiration, uint256 maxExpiration); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`expiration`|`uint256`|The requested expiration timestamp.| +|`maxExpiration`|`uint256`|The maximum allowed expiration timestamp.| + +### PaymentTreasuryClaimWindowNotReached +Throws when attempting to claim expired funds before the claim window opens. + + +```solidity +error PaymentTreasuryClaimWindowNotReached(uint256 claimableAt); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`claimableAt`|`uint256`|The timestamp when the claim window opens.| + +### PaymentTreasuryNoFundsToClaim +Throws when there are no funds available to claim. + + +```solidity +error PaymentTreasuryNoFundsToClaim(); +``` + ## Structs ### PaymentInfo -*Stores information about a payment in the treasury.* +Stores information about a payment in the treasury. ```solidity @@ -744,6 +1138,7 @@ struct PaymentInfo { uint256 expiration; bool isConfirmed; bool isCryptoPayment; + uint256 lineItemCount; } ``` @@ -758,4 +1153,20 @@ struct PaymentInfo { |`expiration`|`uint256`|The timestamp after which the payment expires.| |`isConfirmed`|`bool`|Boolean indicating whether the payment has been confirmed.| |`isCryptoPayment`|`bool`|Boolean indicating whether the payment is made using direct crypto payment.| +|`lineItemCount`|`uint256`|The number of line items associated with this payment.| + +### LineItemTotals +Struct to hold line item calculation totals to reduce stack depth. + + +```solidity +struct LineItemTotals { + uint256 totalGoalLineItemAmount; + uint256 totalProtocolFeeFromLineItems; + uint256 totalNonGoalClaimableAmount; + uint256 totalNonGoalRefundableAmount; + uint256 totalInstantTransferAmountForCheck; + uint256 totalInstantTransferAmount; +} +``` diff --git a/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md b/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md index fcffe7fb..58d806ba 100644 --- a/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md +++ b/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md @@ -1,63 +1,70 @@ # BaseTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/utils/BaseTreasury.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/utils/BaseTreasury.sol) **Inherits:** -Initializable, [ICampaignTreasury](/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md), [CampaignAccessChecker](/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md), [PausableCancellable](/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md) +Initializable, [ICampaignTreasury](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md), [CampaignAccessChecker](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md), [PausableCancellable](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md) A base contract for creating and managing treasuries in crowdfunding campaigns. -*This contract defines common functionality and storage for campaign treasuries.* +This contract defines common functionality and storage for campaign treasuries. -*Contracts implementing this base contract should provide specific success conditions.* +Contracts implementing this base contract should provide specific success conditions. ## State Variables ### ZERO_BYTES ```solidity -bytes32 internal constant ZERO_BYTES = 0x0000000000000000000000000000000000000000000000000000000000000000; +bytes32 internal constant ZERO_BYTES = 0x0000000000000000000000000000000000000000000000000000000000000000 ``` ### PERCENT_DIVIDER ```solidity -uint256 internal constant PERCENT_DIVIDER = 10000; +uint256 internal constant PERCENT_DIVIDER = 10000 ``` ### STANDARD_DECIMALS ```solidity -uint256 internal constant STANDARD_DECIMALS = 18; +uint256 internal constant STANDARD_DECIMALS = 18 ``` ### PLATFORM_HASH ```solidity -bytes32 internal PLATFORM_HASH; +bytes32 internal PLATFORM_HASH ``` ### PLATFORM_FEE_PERCENT ```solidity -uint256 internal PLATFORM_FEE_PERCENT; +uint256 internal PLATFORM_FEE_PERCENT ``` ### s_feesDisbursed ```solidity -bool internal s_feesDisbursed; +bool internal s_feesDisbursed ``` ### s_tokenRaisedAmounts ```solidity -mapping(address => uint256) internal s_tokenRaisedAmounts; +mapping(address => uint256) internal s_tokenRaisedAmounts +``` + + +### s_tokenLifetimeRaisedAmounts + +```solidity +mapping(address => uint256) internal s_tokenLifetimeRaisedAmounts ``` @@ -71,18 +78,18 @@ function __BaseContract_init(bytes32 platformHash, address infoAddress) internal ### whenCampaignNotPaused -*Modifier that checks if the campaign is not paused.* +Modifier that checks if the campaign is not paused. ```solidity -modifier whenCampaignNotPaused(); +modifier whenCampaignNotPaused() ; ``` ### whenCampaignNotCancelled ```solidity -modifier whenCampaignNotCancelled(); +modifier whenCampaignNotCancelled() ; ``` ### getplatformHash @@ -117,7 +124,7 @@ function getplatformFeePercent() external view override returns (uint256); ### _normalizeAmount -*Normalizes token amount to 18 decimals for consistent comparison.* +Normalizes token amount to 18 decimals for consistent comparison. ```solidity @@ -139,7 +146,7 @@ function _normalizeAmount(address token, uint256 amount) internal view returns ( ### _denormalizeAmount -*Denormalizes an amount from 18 decimals to the token's actual decimals.* +Denormalizes an amount from 18 decimals to the token's actual decimals. ```solidity @@ -179,7 +186,7 @@ function withdraw() public virtual override whenCampaignNotPaused whenCampaignNo ### pauseTreasury -*External function to pause the campaign.* +External function to pause the campaign. ```solidity @@ -188,7 +195,7 @@ function pauseTreasury(bytes32 message) public virtual onlyPlatformAdmin(PLATFOR ### unpauseTreasury -*External function to unpause the campaign.* +External function to unpause the campaign. ```solidity @@ -197,17 +204,32 @@ function unpauseTreasury(bytes32 message) public virtual onlyPlatformAdmin(PLATF ### cancelTreasury -*External function to cancel the campaign.* +External function to cancel the campaign. ```solidity function cancelTreasury(bytes32 message) public virtual onlyPlatformAdmin(PLATFORM_HASH); ``` +### cancelled + +Returns true if the treasury has been cancelled. + + +```solidity +function cancelled() public view virtual override(ICampaignTreasury, PausableCancellable) returns (bool); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|True if cancelled, false otherwise.| + + ### _revertIfCampaignPaused -*Internal function to check if the campaign is paused. -If the campaign is paused, it reverts with TreasuryCampaignInfoIsPaused error.* +Internal function to check if the campaign is paused. +If the campaign is paused, it reverts with TreasuryCampaignInfoIsPaused error. ```solidity @@ -223,7 +245,7 @@ function _revertIfCampaignCancelled() internal view; ### _checkSuccessCondition -*Internal function to check the success condition for fee disbursement.* +Internal function to check the success condition for fee disbursement. ```solidity @@ -279,7 +301,7 @@ event SuccessConditionNotFulfilled(); ## Errors ### TreasuryTransferFailed -*Throws an error indicating a failed treasury transfer.* +Throws an error indicating a failed treasury transfer. ```solidity @@ -287,7 +309,7 @@ error TreasuryTransferFailed(); ``` ### TreasurySuccessConditionNotFulfilled -*Throws an error indicating that the success condition was not fulfilled.* +Throws an error indicating that the success condition was not fulfilled. ```solidity @@ -295,7 +317,7 @@ error TreasurySuccessConditionNotFulfilled(); ``` ### TreasuryFeeNotDisbursed -*Throws an error indicating that fees have not been disbursed.* +Throws an error indicating that fees have not been disbursed. ```solidity @@ -303,7 +325,7 @@ error TreasuryFeeNotDisbursed(); ``` ### TreasuryCampaignInfoIsPaused -*Throws an error indicating that the campaign is paused.* +Throws an error indicating that the campaign is paused. ```solidity diff --git a/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md b/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md index 36a1d59a..af3c66c7 100644 --- a/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md +++ b/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md @@ -1,25 +1,25 @@ # CampaignAccessChecker -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/utils/CampaignAccessChecker.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/utils/CampaignAccessChecker.sol) **Inherits:** Context -*This abstract contract provides access control mechanisms to restrict the execution of specific functions -to authorized protocol administrators, platform administrators, and campaign owners.* +This abstract contract provides access control mechanisms to restrict the execution of specific functions +to authorized protocol administrators, platform administrators, and campaign owners. ## State Variables ### INFO ```solidity -ICampaignInfo internal INFO; +ICampaignInfo internal INFO ``` ## Functions ### __CampaignAccessChecker_init -*Constructor to initialize the contract with the address of the campaign information contract.* +Constructor to initialize the contract with the address of the campaign information contract. ```solidity @@ -34,22 +34,22 @@ function __CampaignAccessChecker_init(address campaignInfo) internal; ### onlyProtocolAdmin -*Modifier that restricts function access to protocol administrators only. -Users attempting to execute functions with this modifier must be the protocol admin.* +Modifier that restricts function access to protocol administrators only. +Users attempting to execute functions with this modifier must be the protocol admin. ```solidity -modifier onlyProtocolAdmin(); +modifier onlyProtocolAdmin() ; ``` ### onlyPlatformAdmin -*Modifier that restricts function access to platform administrators of a specific platform. -Users attempting to execute functions with this modifier must be the platform admin for the given platform.* +Modifier that restricts function access to platform administrators of a specific platform. +Users attempting to execute functions with this modifier must be the platform admin for the given platform. ```solidity -modifier onlyPlatformAdmin(bytes32 platformHash); +modifier onlyPlatformAdmin(bytes32 platformHash) ; ``` **Parameters** @@ -60,18 +60,18 @@ modifier onlyPlatformAdmin(bytes32 platformHash); ### onlyCampaignOwner -*Modifier that restricts function access to the owner of the campaign. -Users attempting to execute functions with this modifier must be the owner of the campaign.* +Modifier that restricts function access to the owner of the campaign. +Users attempting to execute functions with this modifier must be the owner of the campaign. ```solidity -modifier onlyCampaignOwner(); +modifier onlyCampaignOwner() ; ``` ### _onlyProtocolAdmin -*Internal function to check if the sender is the protocol administrator. -If the sender is not the protocol admin, it reverts with AccessCheckerUnauthorized error.* +Internal function to check if the sender is the protocol administrator. +If the sender is not the protocol admin, it reverts with AccessCheckerUnauthorized error. ```solidity @@ -80,8 +80,8 @@ function _onlyProtocolAdmin() private view; ### _onlyPlatformAdmin -*Internal function to check if the sender is the platform administrator for a specific platform. -If the sender is not the platform admin, it reverts with AccessCheckerUnauthorized error.* +Internal function to check if the sender is the platform administrator for a specific platform. +If the sender is not the platform admin, it reverts with AccessCheckerUnauthorized error. ```solidity @@ -96,8 +96,8 @@ function _onlyPlatformAdmin(bytes32 platformHash) private view; ### _onlyCampaignOwner -*Internal function to check if the sender is the owner of the campaign. -If the sender is not the owner, it reverts with AccessCheckerUnauthorized error.* +Internal function to check if the sender is the owner of the campaign. +If the sender is not the owner, it reverts with AccessCheckerUnauthorized error. ```solidity @@ -106,7 +106,7 @@ function _onlyCampaignOwner() private view; ## Errors ### AccessCheckerUnauthorized -*Throws when the caller is not authorized.* +Throws when the caller is not authorized. ```solidity diff --git a/docs/src/src/utils/Counters.sol/library.Counters.md b/docs/src/src/utils/Counters.sol/library.Counters.md index 098bac17..1ea5d9b2 100644 --- a/docs/src/src/utils/Counters.sol/library.Counters.md +++ b/docs/src/src/utils/Counters.sol/library.Counters.md @@ -1,5 +1,5 @@ # Counters -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/utils/Counters.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/utils/Counters.sol) ## Functions @@ -33,7 +33,7 @@ function reset(Counter storage counter) internal; ## Errors ### CounterDecrementOverflow -*Error thrown when attempting to decrement a counter with value 0.* +Error thrown when attempting to decrement a counter with value 0. ```solidity @@ -45,7 +45,10 @@ error CounterDecrementOverflow(); ```solidity struct Counter { - uint256 _value; + // This variable should never be directly accessed by users of the library: interactions must be restricted to + // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add + // this feature: see https://github.com/ethereum/solidity/issues/4637 + uint256 _value; // default: 0 } ``` diff --git a/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md b/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md index 27856466..da886cac 100644 --- a/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md +++ b/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md @@ -1,5 +1,5 @@ # FiatEnabled -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/utils/FiatEnabled.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/utils/FiatEnabled.sol) A contract that provides functionality for tracking and managing fiat transactions. This contract allows tracking the amount of fiat raised, individual fiat transactions, and the state of fiat fee disbursement. @@ -9,21 +9,21 @@ This contract allows tracking the amount of fiat raised, individual fiat transac ### s_fiatRaisedAmount ```solidity -uint256 internal s_fiatRaisedAmount; +uint256 internal s_fiatRaisedAmount ``` ### s_fiatFeeIsDisbursed ```solidity -bool internal s_fiatFeeIsDisbursed; +bool internal s_fiatFeeIsDisbursed ``` ### s_fiatAmountById ```solidity -mapping(bytes32 => uint256) internal s_fiatAmountById; +mapping(bytes32 => uint256) internal s_fiatAmountById ``` @@ -97,7 +97,7 @@ function _updateFiatTransaction(bytes32 fiatTransactionId, uint256 fiatTransacti ### _updateFiatFeeDisbursementState -*Update the state of fiat fee disbursement.* +Update the state of fiat fee disbursement. ```solidity @@ -147,7 +147,7 @@ event FiatFeeDisbusementStateUpdated(bool isDisbursed, uint256 protocolFeeAmount ## Errors ### FiatEnabledAlreadySet -*Throws an error indicating that the fiat enabled functionality is already set.* +Throws an error indicating that the fiat enabled functionality is already set. ```solidity @@ -155,7 +155,7 @@ error FiatEnabledAlreadySet(); ``` ### FiatEnabledDisallowedState -*Throws an error indicating that the fiat enabled functionality is in an invalid state.* +Throws an error indicating that the fiat enabled functionality is in an invalid state. ```solidity @@ -163,7 +163,7 @@ error FiatEnabledDisallowedState(); ``` ### FiatEnabledInvalidTransaction -*Throws an error indicating that the fiat transaction is invalid.* +Throws an error indicating that the fiat transaction is invalid. ```solidity diff --git a/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md b/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md index b6d9c909..ed66a3e1 100644 --- a/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md +++ b/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md @@ -1,17 +1,17 @@ # ItemRegistry -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/utils/ItemRegistry.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/utils/ItemRegistry.sol) **Inherits:** -[IItem](/src/interfaces/IItem.sol/interface.IItem.md), Context +[IItem](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/IItem.sol/interface.IItem.md), Context -*A contract that manages the registration and retrieval of items.* +A contract that manages the registration and retrieval of items. ## State Variables ### Items ```solidity -mapping(address => mapping(bytes32 => Item)) private Items; +mapping(address => mapping(bytes32 => Item)) private Items ``` @@ -72,7 +72,7 @@ function addItemsBatch(bytes32[] calldata itemIds, Item[] calldata items) extern ## Events ### ItemAdded -*Emitted when a new item is added to the registry.* +Emitted when a new item is added to the registry. ```solidity @@ -89,7 +89,7 @@ event ItemAdded(address indexed owner, bytes32 indexed itemId, Item item); ## Errors ### ItemRegistryMismatchedArraysLength -*Thrown when the input arrays have mismatched lengths.* +Thrown when the input arrays have mismatched lengths. ```solidity diff --git a/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md b/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md index 06a9e518..4dbbcd6d 100644 --- a/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md +++ b/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md @@ -1,5 +1,5 @@ # PausableCancellable -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/utils/PausableCancellable.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/utils/PausableCancellable.sol) **Inherits:** Context @@ -11,14 +11,14 @@ Abstract contract providing pause and cancel state management with events and mo ### _paused ```solidity -bool private _paused; +bool private _paused ``` ### _cancelled ```solidity -bool private _cancelled; +bool private _cancelled ``` @@ -29,7 +29,7 @@ Modifier to allow function only when not paused ```solidity -modifier whenNotPaused(); +modifier whenNotPaused() ; ``` ### whenPaused @@ -38,7 +38,7 @@ Modifier to allow function only when paused ```solidity -modifier whenPaused(); +modifier whenPaused() ; ``` ### whenNotCancelled @@ -47,7 +47,7 @@ Modifier to allow function only when not cancelled ```solidity -modifier whenNotCancelled(); +modifier whenNotCancelled() ; ``` ### whenCancelled @@ -56,7 +56,7 @@ Modifier to allow function only when cancelled ```solidity -modifier whenCancelled(); +modifier whenCancelled() ; ``` ### paused @@ -81,7 +81,7 @@ function cancelled() public view virtual returns (bool); Pauses the contract -*Can only pause if not already paused or cancelled* +Can only pause if not already paused or cancelled ```solidity @@ -98,7 +98,7 @@ function _pause(bytes32 reason) internal virtual whenNotPaused whenNotCancelled; Unpauses the contract -*Can only unpause if currently paused* +Can only unpause if currently paused ```solidity @@ -115,7 +115,7 @@ function _unpause(bytes32 reason) internal virtual whenPaused; Cancels the contract permanently -*Auto-unpauses if paused, and cannot be undone* +Auto-unpauses if paused, and cannot be undone ```solidity @@ -155,7 +155,7 @@ event Cancelled(address indexed account, bytes32 reason); ## Errors ### PausedError -*Reverts if contract is paused* +Reverts if contract is paused ```solidity @@ -163,7 +163,7 @@ error PausedError(); ``` ### NotPausedError -*Reverts if contract is not paused* +Reverts if contract is not paused ```solidity @@ -171,7 +171,7 @@ error NotPausedError(); ``` ### CancelledError -*Reverts if contract is cancelled* +Reverts if contract is cancelled ```solidity @@ -179,7 +179,7 @@ error CancelledError(); ``` ### NotCancelledError -*Reverts if contract is not cancelled* +Reverts if contract is not cancelled ```solidity @@ -187,7 +187,7 @@ error NotCancelledError(); ``` ### CannotCancel -*Reverts if contract is already cancelled* +Reverts if contract is already cancelled ```solidity diff --git a/docs/src/src/utils/PledgeNFT.sol/abstract.PledgeNFT.md b/docs/src/src/utils/PledgeNFT.sol/abstract.PledgeNFT.md new file mode 100644 index 00000000..cd8fc289 --- /dev/null +++ b/docs/src/src/utils/PledgeNFT.sol/abstract.PledgeNFT.md @@ -0,0 +1,383 @@ +# PledgeNFT +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/utils/PledgeNFT.sol) + +**Inherits:** +ERC721Burnable, AccessControl + +Abstract contract for NFTs representing pledges with on-chain metadata + +Contains counter logic and NFT metadata storage + + +## State Variables +### MINTER_ROLE + +```solidity +bytes32 public constant MINTER_ROLE = 0x9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6 +``` + + +### s_nftName + +```solidity +string internal s_nftName +``` + + +### s_nftSymbol + +```solidity +string internal s_nftSymbol +``` + + +### s_imageURI + +```solidity +string internal s_imageURI +``` + + +### s_contractURI + +```solidity +string internal s_contractURI +``` + + +### s_tokenIdCounter + +```solidity +Counters.Counter internal s_tokenIdCounter +``` + + +### s_pledgeData + +```solidity +mapping(uint256 => PledgeData) internal s_pledgeData +``` + + +## Functions +### _initializeNFT + +Initialize NFT metadata + +Called by CampaignInfo during initialization + + +```solidity +function _initializeNFT( + string calldata _nftName, + string calldata _nftSymbol, + string calldata _imageURI, + string calldata _contractURI +) internal; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_nftName`|`string`|NFT collection name| +|`_nftSymbol`|`string`|NFT collection symbol| +|`_imageURI`|`string`|NFT image URI for individual tokens| +|`_contractURI`|`string`|IPFS URI for contract-level metadata| + + +### mintNFTForPledge + +Mints a pledge NFT (auto-increments counter) + +Called by treasuries - returns the new token ID to use as pledge ID + + +```solidity +function mintNFTForPledge( + address backer, + bytes32 reward, + address tokenAddress, + uint256 amount, + uint256 shippingFee, + uint256 tipAmount +) public virtual onlyRole(MINTER_ROLE) returns (uint256 tokenId); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`backer`|`address`|The backer address| +|`reward`|`bytes32`|The reward identifier| +|`tokenAddress`|`address`|The address of the token used for the pledge| +|`amount`|`uint256`|The pledge amount| +|`shippingFee`|`uint256`|The shipping fee| +|`tipAmount`|`uint256`|The tip amount| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|The minted token ID (to be used as pledge ID in treasury)| + + +### burn + +Burns a pledge NFT + + +```solidity +function burn(uint256 tokenId) public virtual override; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|The token ID to burn| + + +### name + +Override name to return initialized name + + +```solidity +function name() public view virtual override returns (string memory); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`string`|The NFT collection name| + + +### symbol + +Override symbol to return initialized symbol + + +```solidity +function symbol() public view virtual override returns (string memory); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`string`|The NFT collection symbol| + + +### setImageURI + +Sets the image URI for all NFTs + +Must be overridden by inheriting contracts to implement access control + + +```solidity +function setImageURI(string calldata newImageURI) external virtual; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`newImageURI`|`string`|The new image URI| + + +### contractURI + +Returns contract-level metadata URI + + +```solidity +function contractURI() external view virtual returns (string memory); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`string`|The contract URI| + + +### updateContractURI + +Update contract-level metadata URI + +Must be overridden by inheriting contracts to implement access control + + +```solidity +function updateContractURI(string calldata newContractURI) external virtual; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`newContractURI`|`string`|The new contract URI| + + +### getPledgeCount + +Gets current total number of pledges + + +```solidity +function getPledgeCount() external view virtual returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The current pledge count| + + +### tokenURI + +Returns the token URI with on-chain metadata + + +```solidity +function tokenURI(uint256 tokenId) public view virtual override returns (string memory); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|The token ID| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`string`|The base64 encoded JSON metadata| + + +### getImageURI + +Gets the image URI + + +```solidity +function getImageURI() external view returns (string memory); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`string`|The current image URI| + + +### getPledgeData + +Gets the pledge data for a token + + +```solidity +function getPledgeData(uint256 tokenId) external view returns (PledgeData memory); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|The token ID| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`PledgeData`|The pledge data| + + +### supportsInterface + +Override supportsInterface for multiple inheritance + +Internal function to set pledge data for a token + + +```solidity +function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, AccessControl) returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`interfaceId`|`bytes4`|The interface ID| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|True if the interface is supported| + + +## Events +### ImageURIUpdated +Emitted when the image URI is updated + + +```solidity +event ImageURIUpdated(string newImageURI); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`newImageURI`|`string`|The new image URI| + +### ContractURIUpdated +Emitted when the contract URI is updated + + +```solidity +event ContractURIUpdated(string newContractURI); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`newContractURI`|`string`|The new contract URI| + +### PledgeNFTMinted +Emitted when a pledge NFT is minted + + +```solidity +event PledgeNFTMinted(uint256 indexed tokenId, address indexed backer, address indexed treasury, bytes32 reward); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|The token ID| +|`backer`|`address`|The backer address| +|`treasury`|`address`|The treasury address| +|`reward`|`bytes32`|The reward identifier| + +## Errors +### PledgeNFTUnAuthorized +Emitted when unauthorized access is attempted + + +```solidity +error PledgeNFTUnAuthorized(); +``` + +## Structs +### PledgeData +Struct to store pledge data for each token + + +```solidity +struct PledgeData { + address backer; + bytes32 reward; + address treasury; + address tokenAddress; + uint256 amount; + uint256 shippingFee; + uint256 tipAmount; +} +``` + diff --git a/docs/src/src/utils/README.md b/docs/src/src/utils/README.md index d1fb1063..41911c59 100644 --- a/docs/src/src/utils/README.md +++ b/docs/src/src/utils/README.md @@ -9,4 +9,5 @@ - [FiatEnabled](FiatEnabled.sol/abstract.FiatEnabled.md) - [ItemRegistry](ItemRegistry.sol/contract.ItemRegistry.md) - [PausableCancellable](PausableCancellable.sol/abstract.PausableCancellable.md) +- [PledgeNFT](PledgeNFT.sol/abstract.PledgeNFT.md) - [TimestampChecker](TimestampChecker.sol/abstract.TimestampChecker.md) diff --git a/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md b/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md index b9a0d412..bf1a08ba 100644 --- a/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md +++ b/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md @@ -1,5 +1,5 @@ # TimestampChecker -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/08a57a0930f80d6f45ee44fa43ce6ad3e6c3c5c5/src/utils/TimestampChecker.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/utils/TimestampChecker.sol) A contract that provides timestamp-related checks for contract functions. @@ -11,7 +11,7 @@ Modifier that checks if the current timestamp is greater than a specified time. ```solidity -modifier currentTimeIsGreater(uint256 inputTime); +modifier currentTimeIsGreater(uint256 inputTime) ; ``` **Parameters** @@ -26,7 +26,7 @@ Modifier that checks if the current timestamp is less than a specified time. ```solidity -modifier currentTimeIsLess(uint256 inputTime); +modifier currentTimeIsLess(uint256 inputTime) ; ``` **Parameters** @@ -41,7 +41,7 @@ Modifier that checks if the current timestamp is within a specified time range. ```solidity -modifier currentTimeIsWithinRange(uint256 initialTime, uint256 finalTime); +modifier currentTimeIsWithinRange(uint256 initialTime, uint256 finalTime) ; ``` **Parameters** @@ -53,7 +53,7 @@ modifier currentTimeIsWithinRange(uint256 initialTime, uint256 finalTime); ### _revertIfCurrentTimeIsNotLess -*Internal function to revert if the current timestamp is less than or equal a specified time.* +Internal function to revert if the current timestamp is less than or equal a specified time. ```solidity @@ -68,7 +68,7 @@ function _revertIfCurrentTimeIsNotLess(uint256 inputTime) internal view virtual; ### _revertIfCurrentTimeIsNotGreater -*Internal function to revert if the current timestamp is not greater than or equal a specified time.* +Internal function to revert if the current timestamp is not greater than or equal a specified time. ```solidity @@ -83,7 +83,7 @@ function _revertIfCurrentTimeIsNotGreater(uint256 inputTime) internal view virtu ### _revertIfCurrentTimeIsNotWithinRange -*Internal function to revert if the current timestamp is not within a specified time range.* +Internal function to revert if the current timestamp is not within a specified time range. ```solidity @@ -99,7 +99,7 @@ function _revertIfCurrentTimeIsNotWithinRange(uint256 initialTime, uint256 final ## Errors ### CurrentTimeIsGreater -*Error: The current timestamp is greater than the specified input time.* +Error: The current timestamp is greater than the specified input time. ```solidity @@ -114,7 +114,7 @@ error CurrentTimeIsGreater(uint256 inputTime, uint256 currentTime); |`currentTime`|`uint256`|The current block timestamp.| ### CurrentTimeIsLess -*Error: The current timestamp is less than the specified input time.* +Error: The current timestamp is less than the specified input time. ```solidity @@ -129,7 +129,7 @@ error CurrentTimeIsLess(uint256 inputTime, uint256 currentTime); |`currentTime`|`uint256`|The current block timestamp.| ### CurrentTimeIsNotWithinRange -*Error: The current timestamp is not within the specified range.* +Error: The current timestamp is not within the specified range. ```solidity From 520b31fc063f6ba0614f3ce927544989c9136197 Mon Sep 17 00:00:00 2001 From: mahabubAlahi <32974385+mahabubAlahi@users.noreply.github.com> Date: Wed, 12 Nov 2025 16:05:32 +0600 Subject: [PATCH 52/63] Clarify Payment Treasury Metadata and Lifetime Totals and Updated the documentation (#44) * Refactor external fees handling in PaymentTreasury - Updated documentation in ICampaignPaymentTreasury to clarify that external fees are metadata only and do not impact financial transactions. - Renamed internal mappings and variables in BasePaymentTreasury to reflect the change to external fee metadata, enhancing clarity and maintainability. * Update documentation links and clarify external fees handling in PaymentTreasury - Updated Git source links in various contract documentation to reflect the latest commit. - Enhanced clarity in the PaymentTreasury documentation regarding external fees, specifying that they are metadata only and do not impact financial transactions. --- .../CampaignInfo.sol/contract.CampaignInfo.md | 2 +- .../contract.CampaignInfoFactory.md | 2 +- .../GlobalParams.sol/contract.GlobalParams.md | 2 +- .../contract.TreasuryFactory.md | 2 +- .../library.DataRegistryKeys.md | 2 +- .../interface.ICampaignData.md | 2 +- .../interface.ICampaignInfo.md | 2 +- .../interface.ICampaignInfoFactory.md | 2 +- .../interface.ICampaignPaymentTreasury.md | 14 ++++---- .../interface.ICampaignTreasury.md | 2 +- .../interface.IGlobalParams.md | 2 +- .../interfaces/IItem.sol/interface.IItem.md | 2 +- .../IReward.sol/interface.IReward.md | 2 +- .../interface.ITreasuryFactory.md | 2 +- .../library.AdminAccessCheckerStorage.md | 2 +- .../library.CampaignInfoFactoryStorage.md | 2 +- .../library.GlobalParamsStorage.md | 2 +- .../library.TreasuryFactoryStorage.md | 2 +- .../AllOrNothing.sol/contract.AllOrNothing.md | 2 +- .../contract.KeepWhatsRaised.md | 2 +- .../contract.PaymentTreasury.md | 8 ++--- ...contract.TimeConstrainedPaymentTreasury.md | 8 ++--- .../abstract.AdminAccessChecker.md | 2 +- .../abstract.BasePaymentTreasury.md | 14 ++++---- .../BaseTreasury.sol/abstract.BaseTreasury.md | 2 +- .../abstract.CampaignAccessChecker.md | 2 +- .../utils/Counters.sol/library.Counters.md | 2 +- .../FiatEnabled.sol/abstract.FiatEnabled.md | 2 +- .../ItemRegistry.sol/contract.ItemRegistry.md | 2 +- .../abstract.PausableCancellable.md | 2 +- .../utils/PledgeNFT.sol/abstract.PledgeNFT.md | 2 +- .../abstract.TimestampChecker.md | 2 +- src/interfaces/ICampaignPaymentTreasury.sol | 11 ++++--- src/utils/BasePaymentTreasury.sol | 32 +++++++++---------- 34 files changed, 73 insertions(+), 70 deletions(-) diff --git a/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md b/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md index e3a41f4e..2797c314 100644 --- a/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md +++ b/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md @@ -1,5 +1,5 @@ # CampaignInfo -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/CampaignInfo.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/CampaignInfo.sol) **Inherits:** [ICampaignData](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md), [ICampaignInfo](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md), Ownable, [PausableCancellable](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md), [TimestampChecker](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), [AdminAccessChecker](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md), [PledgeNFT](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/PledgeNFT.sol/abstract.PledgeNFT.md), Initializable diff --git a/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md b/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md index 3c019b4e..eaa3cb69 100644 --- a/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md +++ b/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md @@ -1,5 +1,5 @@ # CampaignInfoFactory -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/CampaignInfoFactory.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/CampaignInfoFactory.sol) **Inherits:** Initializable, [ICampaignInfoFactory](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md), OwnableUpgradeable, UUPSUpgradeable diff --git a/docs/src/src/GlobalParams.sol/contract.GlobalParams.md b/docs/src/src/GlobalParams.sol/contract.GlobalParams.md index 900cb777..a3665165 100644 --- a/docs/src/src/GlobalParams.sol/contract.GlobalParams.md +++ b/docs/src/src/GlobalParams.sol/contract.GlobalParams.md @@ -1,5 +1,5 @@ # GlobalParams -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/GlobalParams.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/GlobalParams.sol) **Inherits:** Initializable, [IGlobalParams](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md), OwnableUpgradeable, UUPSUpgradeable diff --git a/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md b/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md index 4d9818de..c635fd1f 100644 --- a/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md +++ b/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md @@ -1,5 +1,5 @@ # TreasuryFactory -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/TreasuryFactory.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/TreasuryFactory.sol) **Inherits:** Initializable, [ITreasuryFactory](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md), [AdminAccessChecker](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md), UUPSUpgradeable diff --git a/docs/src/src/constants/DataRegistryKeys.sol/library.DataRegistryKeys.md b/docs/src/src/constants/DataRegistryKeys.sol/library.DataRegistryKeys.md index 8ab78b0e..54dcf73d 100644 --- a/docs/src/src/constants/DataRegistryKeys.sol/library.DataRegistryKeys.md +++ b/docs/src/src/constants/DataRegistryKeys.sol/library.DataRegistryKeys.md @@ -1,5 +1,5 @@ # DataRegistryKeys -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/constants/DataRegistryKeys.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/constants/DataRegistryKeys.sol) Centralized storage for all dataRegistry keys used in GlobalParams diff --git a/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md b/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md index 92bc95df..1cea83cd 100644 --- a/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md +++ b/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md @@ -1,5 +1,5 @@ # ICampaignData -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/interfaces/ICampaignData.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/interfaces/ICampaignData.sol) An interface for managing campaign data in a CCP. diff --git a/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md b/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md index b4d83e83..47b5b45f 100644 --- a/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md +++ b/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md @@ -1,5 +1,5 @@ # ICampaignInfo -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/interfaces/ICampaignInfo.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/interfaces/ICampaignInfo.sol) **Inherits:** IERC721 diff --git a/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md b/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md index 9340fba5..f79aab64 100644 --- a/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md +++ b/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md @@ -1,5 +1,5 @@ # ICampaignInfoFactory -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/interfaces/ICampaignInfoFactory.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/interfaces/ICampaignInfoFactory.sol) **Inherits:** [ICampaignData](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md) diff --git a/docs/src/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md b/docs/src/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md index 790e0a65..4335385e 100644 --- a/docs/src/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md +++ b/docs/src/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md @@ -1,5 +1,5 @@ # ICampaignPaymentTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/interfaces/ICampaignPaymentTreasury.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/interfaces/ICampaignPaymentTreasury.sol) An interface for managing campaign payment treasury contracts. @@ -33,7 +33,7 @@ function createPayment( |`amount`|`uint256`|The amount to be paid for the item.| |`expiration`|`uint256`|The timestamp after which the payment expires.| |`lineItems`|`LineItem[]`|Array of line items associated with this payment.| -|`externalFees`|`ExternalFees[]`|Array of external fees associated with this payment.| +|`externalFees`|`ExternalFees[]`|Array of external fee metadata captured for this payment (informational only).| ### createPaymentBatch @@ -64,7 +64,7 @@ function createPaymentBatch( |`amounts`|`uint256[]`|An array of amounts corresponding to each payment.| |`expirations`|`uint256[]`|An array of expiration timestamps corresponding to each payment.| |`lineItemsArray`|`LineItem[][]`|An array of line item arrays, one for each payment.| -|`externalFeesArray`|`ExternalFees[][]`|An array of external fees arrays, one for each payment.| +|`externalFeesArray`|`ExternalFees[][]`|An array of external fee metadata arrays, one for each payment (informational only).| ### processCryptoPayment @@ -95,7 +95,7 @@ function processCryptoPayment( |`paymentToken`|`address`|The token to use for the payment.| |`amount`|`uint256`|The amount to be paid for the item.| |`lineItems`|`LineItem[]`|Array of line items associated with this payment.| -|`externalFees`|`ExternalFees[]`|Array of external fees associated with this payment.| +|`externalFees`|`ExternalFees[]`|Array of external fee metadata captured for this payment (informational only).| ### cancelPayment @@ -414,7 +414,7 @@ struct PaymentData { |`lineItemCount`|`uint256`|The number of line items associated with this payment.| |`paymentToken`|`address`|The token address used for this payment.| |`lineItems`|`PaymentLineItem[]`|Array of stored line items with their configuration snapshots.| -|`externalFees`|`ExternalFees[]`|Array of external fees associated with this payment.| +|`externalFees`|`ExternalFees[]`|Array of external fee metadata associated with this payment (informational only).| ### LineItem Represents a line item in a payment. @@ -435,7 +435,9 @@ struct LineItem { |`amount`|`uint256`|The amount of the line item (denominated in pledge token).| ### ExternalFees -Represents external fees associated with a payment. +Represents metadata about external fees associated with a payment. + +These values are informational only and do not affect treasury balances or transfers. ```solidity diff --git a/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md b/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md index d0299c45..e4951516 100644 --- a/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md +++ b/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md @@ -1,5 +1,5 @@ # ICampaignTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/interfaces/ICampaignTreasury.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/interfaces/ICampaignTreasury.sol) An interface for managing campaign treasury contracts. diff --git a/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md b/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md index b4220271..b1a61bb8 100644 --- a/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md +++ b/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md @@ -1,5 +1,5 @@ # IGlobalParams -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/interfaces/IGlobalParams.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/interfaces/IGlobalParams.sol) An interface for accessing and managing global parameters of the protocol. diff --git a/docs/src/src/interfaces/IItem.sol/interface.IItem.md b/docs/src/src/interfaces/IItem.sol/interface.IItem.md index 1dea077e..611b26f6 100644 --- a/docs/src/src/interfaces/IItem.sol/interface.IItem.md +++ b/docs/src/src/interfaces/IItem.sol/interface.IItem.md @@ -1,5 +1,5 @@ # IItem -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/interfaces/IItem.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/interfaces/IItem.sol) An interface for managing items and their attributes. diff --git a/docs/src/src/interfaces/IReward.sol/interface.IReward.md b/docs/src/src/interfaces/IReward.sol/interface.IReward.md index c97fba76..044f068a 100644 --- a/docs/src/src/interfaces/IReward.sol/interface.IReward.md +++ b/docs/src/src/interfaces/IReward.sol/interface.IReward.md @@ -1,5 +1,5 @@ # IReward -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/interfaces/IReward.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/interfaces/IReward.sol) An interface for managing rewards in a campaign. diff --git a/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md b/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md index dbb3f29b..528c2857 100644 --- a/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md +++ b/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md @@ -1,5 +1,5 @@ # ITreasuryFactory -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/interfaces/ITreasuryFactory.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/interfaces/ITreasuryFactory.sol) Interface for the TreasuryFactory contract, which registers, approves, and deploys treasury clones. diff --git a/docs/src/src/storage/AdminAccessCheckerStorage.sol/library.AdminAccessCheckerStorage.md b/docs/src/src/storage/AdminAccessCheckerStorage.sol/library.AdminAccessCheckerStorage.md index 99086817..841a0654 100644 --- a/docs/src/src/storage/AdminAccessCheckerStorage.sol/library.AdminAccessCheckerStorage.md +++ b/docs/src/src/storage/AdminAccessCheckerStorage.sol/library.AdminAccessCheckerStorage.md @@ -1,5 +1,5 @@ # AdminAccessCheckerStorage -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/storage/AdminAccessCheckerStorage.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/storage/AdminAccessCheckerStorage.sol) Storage contract for AdminAccessChecker using ERC-7201 namespaced storage diff --git a/docs/src/src/storage/CampaignInfoFactoryStorage.sol/library.CampaignInfoFactoryStorage.md b/docs/src/src/storage/CampaignInfoFactoryStorage.sol/library.CampaignInfoFactoryStorage.md index 4c5193c3..8c5c7a25 100644 --- a/docs/src/src/storage/CampaignInfoFactoryStorage.sol/library.CampaignInfoFactoryStorage.md +++ b/docs/src/src/storage/CampaignInfoFactoryStorage.sol/library.CampaignInfoFactoryStorage.md @@ -1,5 +1,5 @@ # CampaignInfoFactoryStorage -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/storage/CampaignInfoFactoryStorage.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/storage/CampaignInfoFactoryStorage.sol) Storage contract for CampaignInfoFactory using ERC-7201 namespaced storage diff --git a/docs/src/src/storage/GlobalParamsStorage.sol/library.GlobalParamsStorage.md b/docs/src/src/storage/GlobalParamsStorage.sol/library.GlobalParamsStorage.md index 85fee0b3..0144834d 100644 --- a/docs/src/src/storage/GlobalParamsStorage.sol/library.GlobalParamsStorage.md +++ b/docs/src/src/storage/GlobalParamsStorage.sol/library.GlobalParamsStorage.md @@ -1,5 +1,5 @@ # GlobalParamsStorage -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/storage/GlobalParamsStorage.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/storage/GlobalParamsStorage.sol) Storage contract for GlobalParams using ERC-7201 namespaced storage diff --git a/docs/src/src/storage/TreasuryFactoryStorage.sol/library.TreasuryFactoryStorage.md b/docs/src/src/storage/TreasuryFactoryStorage.sol/library.TreasuryFactoryStorage.md index 62a8e562..be39f3c7 100644 --- a/docs/src/src/storage/TreasuryFactoryStorage.sol/library.TreasuryFactoryStorage.md +++ b/docs/src/src/storage/TreasuryFactoryStorage.sol/library.TreasuryFactoryStorage.md @@ -1,5 +1,5 @@ # TreasuryFactoryStorage -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/storage/TreasuryFactoryStorage.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/storage/TreasuryFactoryStorage.sol) Storage contract for TreasuryFactory using ERC-7201 namespaced storage diff --git a/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md b/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md index d8e5ed1e..aa64c7bf 100644 --- a/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md +++ b/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md @@ -1,5 +1,5 @@ # AllOrNothing -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/treasuries/AllOrNothing.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/treasuries/AllOrNothing.sol) **Inherits:** [IReward](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/IReward.sol/interface.IReward.md), [BaseTreasury](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md), [TimestampChecker](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), ReentrancyGuard diff --git a/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md b/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md index 51f75f6b..5afa5461 100644 --- a/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md +++ b/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md @@ -1,5 +1,5 @@ # KeepWhatsRaised -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/treasuries/KeepWhatsRaised.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/treasuries/KeepWhatsRaised.sol) **Inherits:** [IReward](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/IReward.sol/interface.IReward.md), [BaseTreasury](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md), [TimestampChecker](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), [ICampaignData](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md), ReentrancyGuard diff --git a/docs/src/src/treasuries/PaymentTreasury.sol/contract.PaymentTreasury.md b/docs/src/src/treasuries/PaymentTreasury.sol/contract.PaymentTreasury.md index ccfc93fb..fb7cf9ad 100644 --- a/docs/src/src/treasuries/PaymentTreasury.sol/contract.PaymentTreasury.md +++ b/docs/src/src/treasuries/PaymentTreasury.sol/contract.PaymentTreasury.md @@ -1,5 +1,5 @@ # PaymentTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/treasuries/PaymentTreasury.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/treasuries/PaymentTreasury.sol) **Inherits:** [BasePaymentTreasury](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md) @@ -50,7 +50,7 @@ function createPayment( |`amount`|`uint256`|The amount to be paid for the item.| |`expiration`|`uint256`|The timestamp after which the payment expires.| |`lineItems`|`ICampaignPaymentTreasury.LineItem[]`|Array of line items associated with this payment.| -|`externalFees`|`ICampaignPaymentTreasury.ExternalFees[]`|Array of external fees associated with this payment.| +|`externalFees`|`ICampaignPaymentTreasury.ExternalFees[]`|Array of external fee metadata captured for this payment (informational only).| ### createPaymentBatch @@ -81,7 +81,7 @@ function createPaymentBatch( |`amounts`|`uint256[]`|An array of amounts corresponding to each payment.| |`expirations`|`uint256[]`|An array of expiration timestamps corresponding to each payment.| |`lineItemsArray`|`ICampaignPaymentTreasury.LineItem[][]`|An array of line item arrays, one for each payment.| -|`externalFeesArray`|`ICampaignPaymentTreasury.ExternalFees[][]`|An array of external fees arrays, one for each payment.| +|`externalFeesArray`|`ICampaignPaymentTreasury.ExternalFees[][]`|An array of external fee metadata arrays, one for each payment (informational only).| ### processCryptoPayment @@ -112,7 +112,7 @@ function processCryptoPayment( |`paymentToken`|`address`|The token to use for the payment.| |`amount`|`uint256`|The amount to be paid for the item.| |`lineItems`|`ICampaignPaymentTreasury.LineItem[]`|Array of line items associated with this payment.| -|`externalFees`|`ICampaignPaymentTreasury.ExternalFees[]`|Array of external fees associated with this payment.| +|`externalFees`|`ICampaignPaymentTreasury.ExternalFees[]`|Array of external fee metadata captured for this payment (informational only).| ### cancelPayment diff --git a/docs/src/src/treasuries/TimeConstrainedPaymentTreasury.sol/contract.TimeConstrainedPaymentTreasury.md b/docs/src/src/treasuries/TimeConstrainedPaymentTreasury.sol/contract.TimeConstrainedPaymentTreasury.md index ae4b4f65..4e7fd79f 100644 --- a/docs/src/src/treasuries/TimeConstrainedPaymentTreasury.sol/contract.TimeConstrainedPaymentTreasury.md +++ b/docs/src/src/treasuries/TimeConstrainedPaymentTreasury.sol/contract.TimeConstrainedPaymentTreasury.md @@ -1,5 +1,5 @@ # TimeConstrainedPaymentTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/treasuries/TimeConstrainedPaymentTreasury.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/treasuries/TimeConstrainedPaymentTreasury.sol) **Inherits:** [BasePaymentTreasury](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md), [TimestampChecker](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md) @@ -68,7 +68,7 @@ function createPayment( |`amount`|`uint256`|The amount to be paid for the item.| |`expiration`|`uint256`|The timestamp after which the payment expires.| |`lineItems`|`ICampaignPaymentTreasury.LineItem[]`|Array of line items associated with this payment.| -|`externalFees`|`ICampaignPaymentTreasury.ExternalFees[]`|Array of external fees associated with this payment.| +|`externalFees`|`ICampaignPaymentTreasury.ExternalFees[]`|Array of external fee metadata captured for this payment (informational only).| ### createPaymentBatch @@ -99,7 +99,7 @@ function createPaymentBatch( |`amounts`|`uint256[]`|An array of amounts corresponding to each payment.| |`expirations`|`uint256[]`|An array of expiration timestamps corresponding to each payment.| |`lineItemsArray`|`ICampaignPaymentTreasury.LineItem[][]`|An array of line item arrays, one for each payment.| -|`externalFeesArray`|`ICampaignPaymentTreasury.ExternalFees[][]`|An array of external fees arrays, one for each payment.| +|`externalFeesArray`|`ICampaignPaymentTreasury.ExternalFees[][]`|An array of external fee metadata arrays, one for each payment (informational only).| ### processCryptoPayment @@ -130,7 +130,7 @@ function processCryptoPayment( |`paymentToken`|`address`|The token to use for the payment.| |`amount`|`uint256`|The amount to be paid for the item.| |`lineItems`|`ICampaignPaymentTreasury.LineItem[]`|Array of line items associated with this payment.| -|`externalFees`|`ICampaignPaymentTreasury.ExternalFees[]`|Array of external fees associated with this payment.| +|`externalFees`|`ICampaignPaymentTreasury.ExternalFees[]`|Array of external fee metadata captured for this payment (informational only).| ### cancelPayment diff --git a/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md b/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md index f5e6cd5d..6548aae2 100644 --- a/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md +++ b/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md @@ -1,5 +1,5 @@ # AdminAccessChecker -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/utils/AdminAccessChecker.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/utils/AdminAccessChecker.sol) **Inherits:** Context diff --git a/docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md b/docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md index 353df14d..0e533596 100644 --- a/docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md +++ b/docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md @@ -1,5 +1,5 @@ # BasePaymentTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/utils/BasePaymentTreasury.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/utils/BasePaymentTreasury.sol) **Inherits:** Initializable, [ICampaignPaymentTreasury](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md), [CampaignAccessChecker](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md), [PausableCancellable](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md), ReentrancyGuard @@ -83,10 +83,10 @@ mapping(bytes32 => ICampaignPaymentTreasury.PaymentLineItem[]) internal s_paymen ``` -### s_paymentExternalFees +### s_paymentExternalFeeMetadata ```solidity -mapping(bytes32 => ICampaignPaymentTreasury.ExternalFees[]) internal s_paymentExternalFees +mapping(bytes32 => ICampaignPaymentTreasury.ExternalFees[]) internal s_paymentExternalFeeMetadata ``` @@ -364,7 +364,7 @@ function createPayment( |`amount`|`uint256`|The amount to be paid for the item.| |`expiration`|`uint256`|The timestamp after which the payment expires.| |`lineItems`|`ICampaignPaymentTreasury.LineItem[]`|Array of line items associated with this payment.| -|`externalFees`|`ICampaignPaymentTreasury.ExternalFees[]`|Array of external fees associated with this payment.| +|`externalFees`|`ICampaignPaymentTreasury.ExternalFees[]`|Array of external fee metadata captured for this payment (informational only).| ### createPaymentBatch @@ -395,7 +395,7 @@ function createPaymentBatch( |`amounts`|`uint256[]`|An array of amounts corresponding to each payment.| |`expirations`|`uint256[]`|An array of expiration timestamps corresponding to each payment.| |`lineItemsArray`|`ICampaignPaymentTreasury.LineItem[][]`|An array of line item arrays, one for each payment.| -|`externalFeesArray`|`ICampaignPaymentTreasury.ExternalFees[][]`|An array of external fees arrays, one for each payment.| +|`externalFeesArray`|`ICampaignPaymentTreasury.ExternalFees[][]`|An array of external fee metadata arrays, one for each payment (informational only).| ### processCryptoPayment @@ -426,7 +426,7 @@ function processCryptoPayment( |`paymentToken`|`address`|The token to use for the payment.| |`amount`|`uint256`|The amount to be paid for the item.| |`lineItems`|`ICampaignPaymentTreasury.LineItem[]`|Array of line items associated with this payment.| -|`externalFees`|`ICampaignPaymentTreasury.ExternalFees[]`|Array of external fees associated with this payment.| +|`externalFees`|`ICampaignPaymentTreasury.ExternalFees[]`|Array of external fee metadata captured for this payment (informational only).| ### cancelPayment @@ -836,7 +836,7 @@ event PaymentConfirmed(bytes32 indexed paymentId); |Name|Type|Description| |----|----|-----------| -|`paymentId`|`bytes32`|The unique identifier of the cancelled payment.| +|`paymentId`|`bytes32`|The unique identifier of the confirmed payment.| ### PaymentBatchConfirmed Emitted when multiple payments are confirmed in a single batch operation. diff --git a/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md b/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md index 58d806ba..ed924313 100644 --- a/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md +++ b/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md @@ -1,5 +1,5 @@ # BaseTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/utils/BaseTreasury.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/utils/BaseTreasury.sol) **Inherits:** Initializable, [ICampaignTreasury](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md), [CampaignAccessChecker](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md), [PausableCancellable](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md) diff --git a/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md b/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md index af3c66c7..4fed8a0a 100644 --- a/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md +++ b/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md @@ -1,5 +1,5 @@ # CampaignAccessChecker -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/utils/CampaignAccessChecker.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/utils/CampaignAccessChecker.sol) **Inherits:** Context diff --git a/docs/src/src/utils/Counters.sol/library.Counters.md b/docs/src/src/utils/Counters.sol/library.Counters.md index 1ea5d9b2..d907ccf6 100644 --- a/docs/src/src/utils/Counters.sol/library.Counters.md +++ b/docs/src/src/utils/Counters.sol/library.Counters.md @@ -1,5 +1,5 @@ # Counters -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/utils/Counters.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/utils/Counters.sol) ## Functions diff --git a/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md b/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md index da886cac..0ae6098b 100644 --- a/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md +++ b/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md @@ -1,5 +1,5 @@ # FiatEnabled -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/utils/FiatEnabled.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/utils/FiatEnabled.sol) A contract that provides functionality for tracking and managing fiat transactions. This contract allows tracking the amount of fiat raised, individual fiat transactions, and the state of fiat fee disbursement. diff --git a/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md b/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md index ed66a3e1..3901ed4d 100644 --- a/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md +++ b/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md @@ -1,5 +1,5 @@ # ItemRegistry -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/utils/ItemRegistry.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/utils/ItemRegistry.sol) **Inherits:** [IItem](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/IItem.sol/interface.IItem.md), Context diff --git a/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md b/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md index 4dbbcd6d..f672b4ac 100644 --- a/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md +++ b/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md @@ -1,5 +1,5 @@ # PausableCancellable -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/utils/PausableCancellable.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/utils/PausableCancellable.sol) **Inherits:** Context diff --git a/docs/src/src/utils/PledgeNFT.sol/abstract.PledgeNFT.md b/docs/src/src/utils/PledgeNFT.sol/abstract.PledgeNFT.md index cd8fc289..ae3bf19d 100644 --- a/docs/src/src/utils/PledgeNFT.sol/abstract.PledgeNFT.md +++ b/docs/src/src/utils/PledgeNFT.sol/abstract.PledgeNFT.md @@ -1,5 +1,5 @@ # PledgeNFT -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/utils/PledgeNFT.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/utils/PledgeNFT.sol) **Inherits:** ERC721Burnable, AccessControl diff --git a/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md b/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md index bf1a08ba..2fc29743 100644 --- a/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md +++ b/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md @@ -1,5 +1,5 @@ # TimestampChecker -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/fbdbad195ebe6c636608bb8168723963b1f37dd9/src/utils/TimestampChecker.sol) +[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/utils/TimestampChecker.sol) A contract that provides timestamp-related checks for contract functions. diff --git a/src/interfaces/ICampaignPaymentTreasury.sol b/src/interfaces/ICampaignPaymentTreasury.sol index ee40d404..d43ade4a 100644 --- a/src/interfaces/ICampaignPaymentTreasury.sol +++ b/src/interfaces/ICampaignPaymentTreasury.sol @@ -39,7 +39,7 @@ interface ICampaignPaymentTreasury { * @param lineItemCount The number of line items associated with this payment. * @param paymentToken The token address used for this payment. * @param lineItems Array of stored line items with their configuration snapshots. - * @param externalFees Array of external fees associated with this payment. + * @param externalFees Array of external fee metadata associated with this payment (informational only). */ struct PaymentData { address buyerAddress; @@ -66,7 +66,8 @@ interface ICampaignPaymentTreasury { } /** - * @notice Represents external fees associated with a payment. + * @notice Represents metadata about external fees associated with a payment. + * @dev These values are informational only and do not affect treasury balances or transfers. * @param feeType The type identifier of the external fee. * @param feeAmount The amount of the external fee. */ @@ -84,7 +85,7 @@ interface ICampaignPaymentTreasury { * @param amount The amount to be paid for the item. * @param expiration The timestamp after which the payment expires. * @param lineItems Array of line items associated with this payment. - * @param externalFees Array of external fees associated with this payment. + * @param externalFees Array of external fee metadata captured for this payment (informational only). */ function createPayment( bytes32 paymentId, @@ -106,7 +107,7 @@ interface ICampaignPaymentTreasury { * @param amounts An array of amounts corresponding to each payment. * @param expirations An array of expiration timestamps corresponding to each payment. * @param lineItemsArray An array of line item arrays, one for each payment. - * @param externalFeesArray An array of external fees arrays, one for each payment. + * @param externalFeesArray An array of external fee metadata arrays, one for each payment (informational only). */ function createPaymentBatch( bytes32[] calldata paymentIds, @@ -128,7 +129,7 @@ interface ICampaignPaymentTreasury { * @param paymentToken The token to use for the payment. * @param amount The amount to be paid for the item. * @param lineItems Array of line items associated with this payment. - * @param externalFees Array of external fees associated with this payment. + * @param externalFees Array of external fee metadata captured for this payment (informational only). */ function processCryptoPayment( bytes32 paymentId, diff --git a/src/utils/BasePaymentTreasury.sol b/src/utils/BasePaymentTreasury.sol index 6124cc85..feee6e77 100644 --- a/src/utils/BasePaymentTreasury.sol +++ b/src/utils/BasePaymentTreasury.sol @@ -61,8 +61,8 @@ abstract contract BasePaymentTreasury is // Combined line items with their configuration snapshots per payment ID mapping (bytes32 => ICampaignPaymentTreasury.PaymentLineItem[]) internal s_paymentLineItems; // paymentId => array of stored line items - // External fees per payment ID - mapping (bytes32 => ICampaignPaymentTreasury.ExternalFees[]) internal s_paymentExternalFees; // paymentId => array of external fees + // External fee metadata per payment ID (information only, no financial impact) + mapping (bytes32 => ICampaignPaymentTreasury.ExternalFees[]) internal s_paymentExternalFeeMetadata; // paymentId => array of external fee metadata // Multi-token balances (all in token's native decimals) mapping(address => uint256) internal s_pendingPaymentPerToken; // Pending payment amounts per token @@ -108,7 +108,7 @@ abstract contract BasePaymentTreasury is /** * @dev Emitted when a payment is confirmed. - * @param paymentId The unique identifier of the cancelled payment. + * @param paymentId The unique identifier of the confirmed payment. */ event PaymentConfirmed( bytes32 indexed paymentId @@ -570,10 +570,10 @@ abstract contract BasePaymentTreasury is // Validate, store, and track line items _validateStoreAndTrackLineItems(paymentId, lineItems, paymentToken); - // Store external fees - ICampaignPaymentTreasury.ExternalFees[] storage storedExternalFees = s_paymentExternalFees[paymentId]; + // Store external fee metadata for informational purposes only + ICampaignPaymentTreasury.ExternalFees[] storage externalFeeMetadata = s_paymentExternalFeeMetadata[paymentId]; for (uint256 i = 0; i < externalFees.length; ) { - storedExternalFees.push(externalFees[i]); + externalFeeMetadata.push(externalFees[i]); unchecked { ++i; } @@ -679,11 +679,11 @@ abstract contract BasePaymentTreasury is // Validate, store, and track line items in a single loop _validateStoreAndTrackLineItems(paymentId, lineItems, paymentToken); - // Store external fees + // Store external fee metadata for informational purposes only ICampaignPaymentTreasury.ExternalFees[] calldata externalFees = externalFeesArray[i]; - ICampaignPaymentTreasury.ExternalFees[] storage storedExternalFees = s_paymentExternalFees[paymentId]; + ICampaignPaymentTreasury.ExternalFees[] storage externalFeeMetadata = s_paymentExternalFeeMetadata[paymentId]; for (uint256 j = 0; j < externalFees.length; ) { - storedExternalFees.push(externalFees[j]); + externalFeeMetadata.push(externalFees[j]); unchecked { ++j; } @@ -816,10 +816,10 @@ abstract contract BasePaymentTreasury is } } - // Store external fees - ICampaignPaymentTreasury.ExternalFees[] storage storedExternalFees = s_paymentExternalFees[paymentId]; + // Store external fee metadata for informational purposes only + ICampaignPaymentTreasury.ExternalFees[] storage externalFeeMetadata = s_paymentExternalFeeMetadata[paymentId]; for (uint256 i = 0; i < externalFees.length; ) { - storedExternalFees.push(externalFees[i]); + externalFeeMetadata.push(externalFees[i]); unchecked { ++i; } @@ -897,7 +897,7 @@ abstract contract BasePaymentTreasury is delete s_payment[paymentId]; delete s_paymentIdToToken[paymentId]; delete s_paymentLineItems[paymentId]; - delete s_paymentExternalFees[paymentId]; + delete s_paymentExternalFeeMetadata[paymentId]; s_pendingPaymentPerToken[paymentToken] -= amount; @@ -1292,7 +1292,7 @@ abstract contract BasePaymentTreasury is delete s_payment[paymentId]; delete s_paymentIdToToken[paymentId]; delete s_paymentLineItems[paymentId]; - delete s_paymentExternalFees[paymentId]; + delete s_paymentExternalFeeMetadata[paymentId]; s_confirmedPaymentPerToken[paymentToken] -= amountToRefund; s_availableConfirmedPerToken[paymentToken] -= amountToRefund; @@ -1435,7 +1435,7 @@ abstract contract BasePaymentTreasury is delete s_payment[paymentId]; delete s_paymentIdToToken[paymentId]; delete s_paymentLineItems[paymentId]; - delete s_paymentExternalFees[paymentId]; + delete s_paymentExternalFeeMetadata[paymentId]; delete s_paymentIdToTokenId[paymentId]; s_confirmedPaymentPerToken[paymentToken] -= amountToRefund; @@ -1744,7 +1744,7 @@ abstract contract BasePaymentTreasury is PaymentInfo memory payment = s_payment[paymentId]; address paymentToken = s_paymentIdToToken[paymentId]; ICampaignPaymentTreasury.PaymentLineItem[] storage lineItemsStorage = s_paymentLineItems[paymentId]; - ICampaignPaymentTreasury.ExternalFees[] storage externalFeesStorage = s_paymentExternalFees[paymentId]; + ICampaignPaymentTreasury.ExternalFees[] storage externalFeesStorage = s_paymentExternalFeeMetadata[paymentId]; // Copy line items from storage to memory (required: cannot directly assign storage array to memory array) ICampaignPaymentTreasury.PaymentLineItem[] memory lineItems = new ICampaignPaymentTreasury.PaymentLineItem[](lineItemsStorage.length); From a4103d35582be413042c594200ad7d2303238f96 Mon Sep 17 00:00:00 2001 From: mahabubAlahi <32974385+mahabubAlahi@users.noreply.github.com> Date: Tue, 2 Dec 2025 17:05:07 +0600 Subject: [PATCH 53/63] Update deployment scripts (#45) * Add time-related constraints and currency/token configuration to env.example * Refactor deployment scripts to extend DeployBase and streamline currency/token handling - Updated DeployAll, DeployAllAndSetupAllOrNothing, DeployAllAndSetupKeepWhatsRaised, and DeployAllAndSetupPaymentTreasury scripts to inherit from DeployBase for improved code reuse. - Introduced loadCurrenciesAndTokens function in DeployBase to handle currency and token configurations dynamically. - Enhanced initialization data preparation for GlobalParams and TreasuryFactory deployments, reducing redundancy in contract setup. - Added buffer time, campaign launch buffer, and minimum campaign duration parameters to relevant deployment scripts for better configurability. * refactor multi-token deployment and add uups tracking to deployment logs --------- Co-authored-by: AdnanHKx --- env.example | 15 + script/DeployAll.s.sol | 137 ++++--- script/DeployAllAndSetupAllOrNothing.s.sol | 325 ++++++++-------- script/DeployAllAndSetupKeepWhatsRaised.s.sol | 289 +++++++++------ script/DeployAllAndSetupPaymentTreasury.s.sol | 348 +++++++++--------- script/DeployGlobalParams.s.sol | 54 +-- script/DeployKeepWhatsRaised.s.sol | 22 +- script/UpgradeCampaignInfoFactory.s.sol | 1 - script/UpgradeGlobalParams.s.sol | 1 - script/UpgradeTreasuryFactory.s.sol | 1 - script/lib/DeployBase.s.sol | 150 +++++++- 11 files changed, 767 insertions(+), 576 deletions(-) diff --git a/env.example b/env.example index 84bf4aea..11883c7d 100644 --- a/env.example +++ b/env.example @@ -69,3 +69,18 @@ SIMULATE= # ========================= ETHERSCAN_API_KEY= + +# ============================= +# Time Related Constraints +# ============================= +BUFFER_TIME= +CAMPAIGN_LAUNCH_BUFFER= +MINIMUM_CAMPAIGN_DURATION= +MAX_PAYMENT_EXPIRATION= + +# ============================= +# Currency + token matrix +# ============================= + +CURRENCIES=USD,EUR +TOKENS_PER_CURRENCY=0xUsdt...,0xUsdc...,0xDai...;0xEurt...,0xEurc... diff --git a/script/DeployAll.s.sol b/script/DeployAll.s.sol index bd1fe04f..5180e7c9 100644 --- a/script/DeployAll.s.sol +++ b/script/DeployAll.s.sol @@ -1,7 +1,6 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.22; -import {Script} from "forge-std/Script.sol"; import {console2} from "forge-std/console2.sol"; import {TestToken} from "../test/mocks/TestToken.sol"; import {GlobalParams} from "src/GlobalParams.sol"; @@ -10,8 +9,10 @@ import {CampaignInfo} from "src/CampaignInfo.sol"; import {TreasuryFactory} from "src/TreasuryFactory.sol"; import {IGlobalParams} from "src/interfaces/IGlobalParams.sol"; import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; +import {DataRegistryKeys} from "src/constants/DataRegistryKeys.sol"; +import {DeployBase} from "./lib/DeployBase.s.sol"; -contract DeployAll is Script { +contract DeployAll is DeployBase { function run() external { bool simulate = vm.envOr("SIMULATE", false); uint256 deployerKey = vm.envUint("PRIVATE_KEY"); @@ -21,58 +22,52 @@ contract DeployAll is Script { vm.startBroadcast(deployerKey); } - // Deploy TestToken - string memory tokenName = vm.envOr("TOKEN_NAME", string("TestToken")); - string memory tokenSymbol = vm.envOr("TOKEN_SYMBOL", string("TST")); - uint8 decimals = uint8(vm.envOr("TOKEN_DECIMALS", uint256(18))); + // Deploy TestToken only if needed + address testTokenAddress; + bool testTokenDeployed = false; - TestToken testToken = new TestToken(tokenName, tokenSymbol, decimals); - console2.log("TestToken deployed at:", address(testToken)); + if (shouldDeployTestToken()) { + string memory tokenName = vm.envOr("TOKEN_NAME", string("TestToken")); + string memory tokenSymbol = vm.envOr("TOKEN_SYMBOL", string("TST")); + uint8 decimals = uint8(vm.envOr("TOKEN_DECIMALS", uint256(18))); + + TestToken testToken = new TestToken(tokenName, tokenSymbol, decimals); + testTokenAddress = address(testToken); + testTokenDeployed = true; + console2.log("TestToken deployed at:", testTokenAddress); + } else { + console2.log("Skipping TestToken deployment - using custom tokens for currencies"); + } // Deploy GlobalParams with UUPS proxy uint256 protocolFeePercent = vm.envOr("PROTOCOL_FEE_PERCENT", uint256(100)); - - bytes32[] memory currencies = new bytes32[](1); - address[][] memory tokensPerCurrency = new address[][](1); - currencies[0] = keccak256(abi.encodePacked("USD")); - tokensPerCurrency[0] = new address[](1); - tokensPerCurrency[0][0] = address(testToken); - + + (bytes32[] memory currencies, address[][] memory tokensPerCurrency) = + loadCurrenciesAndTokens(testTokenAddress); + // Deploy GlobalParams implementation GlobalParams globalParamsImpl = new GlobalParams(); console2.log("GlobalParams implementation deployed at:", address(globalParamsImpl)); - + // Prepare initialization data for GlobalParams bytes memory globalParamsInitData = abi.encodeWithSelector( - GlobalParams.initialize.selector, - deployerAddress, - protocolFeePercent, - currencies, - tokensPerCurrency + GlobalParams.initialize.selector, deployerAddress, protocolFeePercent, currencies, tokensPerCurrency ); - + // Deploy GlobalParams proxy - ERC1967Proxy globalParamsProxy = new ERC1967Proxy( - address(globalParamsImpl), - globalParamsInitData - ); + ERC1967Proxy globalParamsProxy = new ERC1967Proxy(address(globalParamsImpl), globalParamsInitData); console2.log("GlobalParams proxy deployed at:", address(globalParamsProxy)); // Deploy TreasuryFactory with UUPS proxy TreasuryFactory treasuryFactoryImpl = new TreasuryFactory(); console2.log("TreasuryFactory implementation deployed at:", address(treasuryFactoryImpl)); - + // Prepare initialization data for TreasuryFactory - bytes memory treasuryFactoryInitData = abi.encodeWithSelector( - TreasuryFactory.initialize.selector, - IGlobalParams(address(globalParamsProxy)) - ); - + bytes memory treasuryFactoryInitData = + abi.encodeWithSelector(TreasuryFactory.initialize.selector, IGlobalParams(address(globalParamsProxy))); + // Deploy TreasuryFactory proxy - ERC1967Proxy treasuryFactoryProxy = new ERC1967Proxy( - address(treasuryFactoryImpl), - treasuryFactoryInitData - ); + ERC1967Proxy treasuryFactoryProxy = new ERC1967Proxy(address(treasuryFactoryImpl), treasuryFactoryInitData); console2.log("TreasuryFactory proxy deployed at:", address(treasuryFactoryProxy)); // Deploy CampaignInfo implementation @@ -82,7 +77,7 @@ contract DeployAll is Script { // Deploy CampaignInfoFactory with UUPS proxy CampaignInfoFactory campaignFactoryImpl = new CampaignInfoFactory(); console2.log("CampaignInfoFactory implementation deployed at:", address(campaignFactoryImpl)); - + // Prepare initialization data for CampaignInfoFactory bytes memory campaignFactoryInitData = abi.encodeWithSelector( CampaignInfoFactory.initialize.selector, @@ -91,26 +86,68 @@ contract DeployAll is Script { address(campaignInfoImplementation), address(treasuryFactoryProxy) ); - + // Deploy CampaignInfoFactory proxy - ERC1967Proxy campaignFactoryProxy = new ERC1967Proxy( - address(campaignFactoryImpl), - campaignFactoryInitData - ); + ERC1967Proxy campaignFactoryProxy = new ERC1967Proxy(address(campaignFactoryImpl), campaignFactoryInitData); console2.log("CampaignInfoFactory proxy deployed at:", address(campaignFactoryProxy)); + // Configure registry values + uint256 bufferTime = vm.envOr("BUFFER_TIME", uint256(0)); + uint256 campaignLaunchBuffer = vm.envOr("CAMPAIGN_LAUNCH_BUFFER", uint256(0)); + uint256 minimumCampaignDuration = vm.envOr("MINIMUM_CAMPAIGN_DURATION", uint256(0)); + + GlobalParams(address(globalParamsProxy)).addToRegistry(DataRegistryKeys.BUFFER_TIME, bytes32(bufferTime)); + GlobalParams(address(globalParamsProxy)) + .addToRegistry(DataRegistryKeys.CAMPAIGN_LAUNCH_BUFFER, bytes32(campaignLaunchBuffer)); + GlobalParams(address(globalParamsProxy)) + .addToRegistry(DataRegistryKeys.MINIMUM_CAMPAIGN_DURATION, bytes32(minimumCampaignDuration)); + if (!simulate) { vm.stopBroadcast(); } // Summary - console2.log("\n--- Deployment Summary ---"); - console2.log("TOKEN_ADDRESS", address(testToken)); - console2.log("GLOBAL_PARAMS_ADDRESS", address(globalParamsProxy)); - console2.log("GLOBAL_PARAMS_IMPLEMENTATION", address(globalParamsImpl)); - console2.log("TREASURY_FACTORY_ADDRESS", address(treasuryFactoryProxy)); - console2.log("TREASURY_FACTORY_IMPLEMENTATION", address(treasuryFactoryImpl)); - console2.log("CAMPAIGN_INFO_FACTORY_ADDRESS", address(campaignFactoryProxy)); - console2.log("CAMPAIGN_INFO_FACTORY_IMPLEMENTATION", address(campaignFactoryImpl)); + console2.log("\n==========================================="); + console2.log(" Deployment Summary"); + console2.log("==========================================="); + + console2.log("\n--- Core Protocol Contracts (UUPS Proxies) ---"); + console2.log("GLOBAL_PARAMS_PROXY:", address(globalParamsProxy)); + console2.log(" Implementation:", address(globalParamsImpl)); + console2.log("TREASURY_FACTORY_PROXY:", address(treasuryFactoryProxy)); + console2.log(" Implementation:", address(treasuryFactoryImpl)); + console2.log("CAMPAIGN_INFO_FACTORY_PROXY:", address(campaignFactoryProxy)); + console2.log(" Implementation:", address(campaignFactoryImpl)); + + console2.log("\n--- Implementation Contracts ---"); + console2.log("CAMPAIGN_INFO_IMPLEMENTATION:", address(campaignInfoImplementation)); + + console2.log("\n--- Supported Currencies & Tokens ---"); + string memory currenciesConfig = vm.envOr("CURRENCIES", string("")); + if (bytes(currenciesConfig).length > 0) { + string[] memory currencyStrings = _split(currenciesConfig, ","); + string memory tokensConfig = vm.envOr("TOKENS_PER_CURRENCY", string("")); + string[] memory perCurrencyConfigs = _split(tokensConfig, ";"); + + for (uint256 i = 0; i < currencyStrings.length; i++) { + string memory currency = _trimWhitespace(currencyStrings[i]); + console2.log(string(abi.encodePacked("Currency: ", currency))); + + string[] memory tokenStrings = _split(perCurrencyConfigs[i], ","); + for (uint256 j = 0; j < tokenStrings.length; j++) { + console2.log(" Token:", _trimWhitespace(tokenStrings[j])); + } + } + } else { + console2.log("Currency: USD (default)"); + if (testTokenDeployed) { + console2.log(" Token:", testTokenAddress); + console2.log(" (TestToken deployed for testing)"); + } + } + + console2.log("\n==========================================="); + console2.log("Deployment completed successfully!"); + console2.log("==========================================="); } } diff --git a/script/DeployAllAndSetupAllOrNothing.s.sol b/script/DeployAllAndSetupAllOrNothing.s.sol index ef75988c..7acec53a 100644 --- a/script/DeployAllAndSetupAllOrNothing.s.sol +++ b/script/DeployAllAndSetupAllOrNothing.s.sol @@ -1,7 +1,6 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.22; -import {Script} from "forge-std/Script.sol"; import {console2} from "forge-std/console2.sol"; import {TestToken} from "../test/mocks/TestToken.sol"; import {GlobalParams} from "src/GlobalParams.sol"; @@ -11,24 +10,32 @@ import {TreasuryFactory} from "src/TreasuryFactory.sol"; import {AllOrNothing} from "src/treasuries/AllOrNothing.sol"; import {IGlobalParams} from "src/interfaces/IGlobalParams.sol"; import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; +import {DataRegistryKeys} from "src/constants/DataRegistryKeys.sol"; +import {DeployBase} from "./lib/DeployBase.s.sol"; /** * @notice Script to deploy and setup all needed contracts for the protocol */ -contract DeployAllAndSetupAllOrNothing is Script { +contract DeployAllAndSetupAllOrNothing is DeployBase { // Customizable values (set through environment variables) bytes32 platformHash; uint256 protocolFeePercent; uint256 platformFeePercent; uint256 tokenMintAmount; bool simulate; + uint256 bufferTime; + uint256 campaignLaunchBuffer; + uint256 minimumCampaignDuration; // Contract addresses address testToken; address globalParams; + address globalParamsImplementation; address campaignInfoImplementation; address treasuryFactory; + address treasuryFactoryImplementation; address campaignInfoFactory; + address campaignInfoFactoryImplementation; address allOrNothingImplementation; // User addresses @@ -58,30 +65,24 @@ contract DeployAllAndSetupAllOrNothing is Script { // Configure parameters based on environment variables function setupParams() internal { // Get customizable values - string memory platformName = vm.envOr( - "PLATFORM_NAME", - string("MiniFunder") - ); + string memory platformName = vm.envOr("PLATFORM_NAME", string("MiniFunder")); platformHash = keccak256(abi.encodePacked(platformName)); protocolFeePercent = vm.envOr("PROTOCOL_FEE_PERCENT", uint256(100)); // Default 1% platformFeePercent = vm.envOr("PLATFORM_FEE_PERCENT", uint256(400)); // Default 4% tokenMintAmount = vm.envOr("TOKEN_MINT_AMOUNT", uint256(10000000e18)); simulate = vm.envOr("SIMULATE", false); + bufferTime = vm.envOr("BUFFER_TIME", uint256(0)); + campaignLaunchBuffer = vm.envOr("CAMPAIGN_LAUNCH_BUFFER", uint256(0)); + minimumCampaignDuration = vm.envOr("MINIMUM_CAMPAIGN_DURATION", uint256(0)); // Get user addresses uint256 deployerKey = vm.envUint("PRIVATE_KEY"); deployerAddress = vm.addr(deployerKey); // These are the final admin addresses that will receive control - finalProtocolAdmin = vm.envOr( - "PROTOCOL_ADMIN_ADDRESS", - deployerAddress - ); - finalPlatformAdmin = vm.envOr( - "PLATFORM_ADMIN_ADDRESS", - deployerAddress - ); + finalProtocolAdmin = vm.envOr("PROTOCOL_ADMIN_ADDRESS", deployerAddress); + finalPlatformAdmin = vm.envOr("PLATFORM_ADMIN_ADDRESS", deployerAddress); backer1 = vm.envOr("BACKER1_ADDRESS", address(0)); backer2 = vm.envOr("BACKER2_ADDRESS", address(0)); @@ -89,14 +90,8 @@ contract DeployAllAndSetupAllOrNothing is Script { testToken = vm.envOr("TOKEN_ADDRESS", address(0)); globalParams = vm.envOr("GLOBAL_PARAMS_ADDRESS", address(0)); treasuryFactory = vm.envOr("TREASURY_FACTORY_ADDRESS", address(0)); - campaignInfoFactory = vm.envOr( - "CAMPAIGN_INFO_FACTORY_ADDRESS", - address(0) - ); - allOrNothingImplementation = vm.envOr( - "ALL_OR_NOTHING_IMPLEMENTATION_ADDRESS", - address(0) - ); + campaignInfoFactory = vm.envOr("CAMPAIGN_INFO_FACTORY_ADDRESS", address(0)); + allOrNothingImplementation = vm.envOr("ALL_OR_NOTHING_IMPLEMENTATION_ADDRESS", address(0)); console2.log("Using platform hash for:", platformName); console2.log("Protocol fee percent:", protocolFeePercent); @@ -105,6 +100,22 @@ contract DeployAllAndSetupAllOrNothing is Script { console2.log("Deployer address:", deployerAddress); console2.log("Final protocol admin:", finalProtocolAdmin); console2.log("Final platform admin:", finalPlatformAdmin); + console2.log("Buffer time (seconds):", bufferTime); + console2.log("Campaign launch buffer (seconds):", campaignLaunchBuffer); + console2.log("Minimum campaign duration (seconds):", minimumCampaignDuration); + } + + function setRegistryValues() internal { + if (!globalParamsDeployed) { + console2.log("Skipping setRegistryValues - using existing GlobalParams"); + return; + } + + console2.log("Setting registry values on GlobalParams"); + GlobalParams(globalParams).addToRegistry(DataRegistryKeys.BUFFER_TIME, bytes32(bufferTime)); + GlobalParams(globalParams).addToRegistry(DataRegistryKeys.CAMPAIGN_LAUNCH_BUFFER, bytes32(campaignLaunchBuffer)); + GlobalParams(globalParams) + .addToRegistry(DataRegistryKeys.MINIMUM_CAMPAIGN_DURATION, bytes32(minimumCampaignDuration)); } // Deploy or reuse contracts @@ -112,79 +123,61 @@ contract DeployAllAndSetupAllOrNothing is Script { console2.log("Setting up contracts..."); // Deploy or reuse TestToken - + // Only deploy TestToken if CURRENCIES is not provided (backward compatibility) string memory tokenName = vm.envOr("TOKEN_NAME", string("TestToken")); string memory tokenSymbol = vm.envOr("TOKEN_SYMBOL", string("TST")); - if (testToken == address(0)) { + if (testToken == address(0) && shouldDeployTestToken()) { uint8 decimals = uint8(vm.envOr("TOKEN_DECIMALS", uint256(18))); testToken = address(new TestToken(tokenName, tokenSymbol, decimals)); testTokenDeployed = true; console2.log("TestToken deployed at:", testToken); - } else { + } else if (testToken != address(0)) { console2.log("Reusing TestToken at:", testToken); + } else { + console2.log("Skipping TestToken deployment - using custom tokens for currencies"); } // Deploy or reuse GlobalParams if (globalParams == address(0)) { - // Setup currencies and tokens for multi-token support - bytes32[] memory currencies = new bytes32[](1); - address[][] memory tokensPerCurrency = new address[][](1); - - currencies[0] = keccak256(abi.encodePacked("USD")); - tokensPerCurrency[0] = new address[](1); - tokensPerCurrency[0][0] = testToken; - + (bytes32[] memory currencies, address[][] memory tokensPerCurrency) = loadCurrenciesAndTokens(testToken); + // Deploy GlobalParams with UUPS proxy GlobalParams globalParamsImpl = new GlobalParams(); + globalParamsImplementation = address(globalParamsImpl); bytes memory globalParamsInitData = abi.encodeWithSelector( - GlobalParams.initialize.selector, - deployerAddress, - protocolFeePercent, - currencies, - tokensPerCurrency - ); - ERC1967Proxy globalParamsProxy = new ERC1967Proxy( - address(globalParamsImpl), - globalParamsInitData + GlobalParams.initialize.selector, deployerAddress, protocolFeePercent, currencies, tokensPerCurrency ); + ERC1967Proxy globalParamsProxy = new ERC1967Proxy(address(globalParamsImpl), globalParamsInitData); globalParams = address(globalParamsProxy); globalParamsDeployed = true; - console2.log("GlobalParams deployed at:", globalParams); + console2.log("GlobalParams proxy deployed at:", globalParams); + console2.log(" Implementation:", globalParamsImplementation); } else { console2.log("Reusing GlobalParams at:", globalParams); } - // We need at least TestToken and GlobalParams to continue - require(testToken != address(0), "TestToken address is required"); + // GlobalParams is required to continue require(globalParams != address(0), "GlobalParams address is required"); // Deploy CampaignInfo implementation if needed for new deployments if (campaignInfoFactory == address(0)) { - campaignInfoImplementation = address( - new CampaignInfo() - ); - console2.log( - "CampaignInfo implementation deployed at:", - campaignInfoImplementation - ); + campaignInfoImplementation = address(new CampaignInfo()); + console2.log("CampaignInfo implementation deployed at:", campaignInfoImplementation); } // Deploy or reuse TreasuryFactory if (treasuryFactory == address(0)) { // Deploy TreasuryFactory with UUPS proxy TreasuryFactory treasuryFactoryImpl = new TreasuryFactory(); - bytes memory treasuryFactoryInitData = abi.encodeWithSelector( - TreasuryFactory.initialize.selector, - IGlobalParams(globalParams) - ); - ERC1967Proxy treasuryFactoryProxy = new ERC1967Proxy( - address(treasuryFactoryImpl), - treasuryFactoryInitData - ); + treasuryFactoryImplementation = address(treasuryFactoryImpl); + bytes memory treasuryFactoryInitData = + abi.encodeWithSelector(TreasuryFactory.initialize.selector, IGlobalParams(globalParams)); + ERC1967Proxy treasuryFactoryProxy = new ERC1967Proxy(address(treasuryFactoryImpl), treasuryFactoryInitData); treasuryFactory = address(treasuryFactoryProxy); treasuryFactoryDeployed = true; - console2.log("TreasuryFactory deployed at:", treasuryFactory); + console2.log("TreasuryFactory proxy deployed at:", treasuryFactory); + console2.log(" Implementation:", treasuryFactoryImplementation); } else { console2.log("Reusing TreasuryFactory at:", treasuryFactory); } @@ -193,6 +186,7 @@ contract DeployAllAndSetupAllOrNothing is Script { if (campaignInfoFactory == address(0)) { // Deploy CampaignInfoFactory with UUPS proxy CampaignInfoFactory campaignFactoryImpl = new CampaignInfoFactory(); + campaignInfoFactoryImplementation = address(campaignFactoryImpl); bytes memory campaignFactoryInitData = abi.encodeWithSelector( CampaignInfoFactory.initialize.selector, deployerAddress, @@ -200,36 +194,22 @@ contract DeployAllAndSetupAllOrNothing is Script { campaignInfoImplementation, treasuryFactory ); - ERC1967Proxy campaignFactoryProxy = new ERC1967Proxy( - address(campaignFactoryImpl), - campaignFactoryInitData - ); + ERC1967Proxy campaignFactoryProxy = new ERC1967Proxy(address(campaignFactoryImpl), campaignFactoryInitData); campaignInfoFactory = address(campaignFactoryProxy); campaignInfoFactoryDeployed = true; - console2.log( - "CampaignInfoFactory deployed and initialized at:", - campaignInfoFactory - ); + console2.log("CampaignInfoFactory proxy deployed at:", campaignInfoFactory); + console2.log(" Implementation:", campaignInfoFactoryImplementation); } else { - console2.log( - "Reusing CampaignInfoFactory at:", - campaignInfoFactory - ); + console2.log("Reusing CampaignInfoFactory at:", campaignInfoFactory); } // Deploy or reuse AllOrNothing implementation if (allOrNothingImplementation == address(0)) { allOrNothingImplementation = address(new AllOrNothing()); allOrNothingDeployed = true; - console2.log( - "AllOrNothing implementation deployed at:", - allOrNothingImplementation - ); + console2.log("AllOrNothing implementation deployed at:", allOrNothingImplementation); } else { - console2.log( - "Reusing AllOrNothing implementation at:", - allOrNothingImplementation - ); + console2.log("Reusing AllOrNothing implementation at:", allOrNothingImplementation); } } @@ -237,9 +217,7 @@ contract DeployAllAndSetupAllOrNothing is Script { function enlistPlatform() internal { // Skip if we didn't deploy GlobalParams (assuming it's already set up) if (!globalParamsDeployed) { - console2.log( - "Skipping enlistPlatform - using existing GlobalParams" - ); + console2.log("Skipping enlistPlatform - using existing GlobalParams"); platformEnlisted = true; return; } @@ -250,11 +228,12 @@ contract DeployAllAndSetupAllOrNothing is Script { vm.startPrank(deployerAddress); } - GlobalParams(globalParams).enlistPlatform( - platformHash, - deployerAddress, // Initially deployer is platform admin - platformFeePercent - ); + GlobalParams(globalParams) + .enlistPlatform( + platformHash, + deployerAddress, // Initially deployer is platform admin + platformFeePercent + ); if (simulate) { vm.stopPrank(); @@ -266,9 +245,7 @@ contract DeployAllAndSetupAllOrNothing is Script { function registerTreasuryImplementation() internal { // Skip if we didn't deploy TreasuryFactory (assuming it's already set up) if (!treasuryFactoryDeployed || !allOrNothingDeployed) { - console2.log( - "Skipping registerTreasuryImplementation - using existing contracts" - ); + console2.log("Skipping registerTreasuryImplementation - using existing contracts"); implementationRegistered = true; return; } @@ -279,11 +256,12 @@ contract DeployAllAndSetupAllOrNothing is Script { vm.startPrank(deployerAddress); } - TreasuryFactory(treasuryFactory).registerTreasuryImplementation( - platformHash, - 0, // Implementation ID - allOrNothingImplementation - ); + TreasuryFactory(treasuryFactory) + .registerTreasuryImplementation( + platformHash, + 0, // Implementation ID + allOrNothingImplementation + ); if (simulate) { vm.stopPrank(); @@ -295,9 +273,7 @@ contract DeployAllAndSetupAllOrNothing is Script { function approveTreasuryImplementation() internal { // Skip if we didn't deploy TreasuryFactory (assuming it's already set up) if (!treasuryFactoryDeployed || !allOrNothingDeployed) { - console2.log( - "Skipping approveTreasuryImplementation - using existing contracts" - ); + console2.log("Skipping approveTreasuryImplementation - using existing contracts"); implementationApproved = true; return; } @@ -308,10 +284,11 @@ contract DeployAllAndSetupAllOrNothing is Script { vm.startPrank(deployerAddress); } - TreasuryFactory(treasuryFactory).approveTreasuryImplementation( - platformHash, - 0 // Implementation ID - ); + TreasuryFactory(treasuryFactory) + .approveTreasuryImplementation( + platformHash, + 0 // Implementation ID + ); if (simulate) { vm.stopPrank(); @@ -341,9 +318,7 @@ contract DeployAllAndSetupAllOrNothing is Script { function transferAdminRights() internal { // Skip if we didn't deploy GlobalParams (assuming it's already set up) if (!globalParamsDeployed) { - console2.log( - "Skipping transferAdminRights - using existing GlobalParams" - ); + console2.log("Skipping transferAdminRights - using existing GlobalParams"); adminRightsTransferred = true; return; } @@ -352,24 +327,13 @@ contract DeployAllAndSetupAllOrNothing is Script { // Only transfer if the final addresses are different from deployer if (finalPlatformAdmin != deployerAddress) { - console2.log( - "Updating platform admin address for platform hash:", - vm.toString(platformHash) - ); - GlobalParams(globalParams).updatePlatformAdminAddress( - platformHash, - finalPlatformAdmin - ); + console2.log("Updating platform admin address for platform hash:", vm.toString(platformHash)); + GlobalParams(globalParams).updatePlatformAdminAddress(platformHash, finalPlatformAdmin); } if (finalProtocolAdmin != deployerAddress) { - console2.log( - "Transferring protocol admin rights to:", - finalProtocolAdmin - ); - GlobalParams(globalParams).updateProtocolAdminAddress( - finalProtocolAdmin - ); + console2.log("Transferring protocol admin rights to:", finalProtocolAdmin); + GlobalParams(globalParams).updateProtocolAdminAddress(finalProtocolAdmin); //Transfer admin rights to the final protocol admin GlobalParams(globalParams).transferOwnership(finalProtocolAdmin); @@ -393,6 +357,7 @@ contract DeployAllAndSetupAllOrNothing is Script { // Deploy or reuse contracts deployContracts(); + setRegistryValues(); // Setup the protocol with individual transactions in the correct order // Since deployer is both protocol and platform admin initially, we can do all steps @@ -410,68 +375,74 @@ contract DeployAllAndSetupAllOrNothing is Script { vm.stopBroadcast(); // Output summary - console2.log("\n--- Deployment & Setup Summary ---"); - console2.log("Platform Name Hash:", vm.toString(platformHash)); - console2.log("TOKEN_ADDRESS:", testToken); - console2.log("GLOBAL_PARAMS_ADDRESS:", globalParams); + console2.log("\n==========================================="); + console2.log(" Deployment & Setup Summary"); + console2.log("==========================================="); + console2.log("\n--- Core Protocol Contracts (UUPS Proxies) ---"); + console2.log("GLOBAL_PARAMS_PROXY:", globalParams); + if (globalParamsImplementation != address(0)) { + console2.log(" Implementation:", globalParamsImplementation); + } + console2.log("TREASURY_FACTORY_PROXY:", treasuryFactory); + if (treasuryFactoryImplementation != address(0)) { + console2.log(" Implementation:", treasuryFactoryImplementation); + } + console2.log("CAMPAIGN_INFO_FACTORY_PROXY:", campaignInfoFactory); + if (campaignInfoFactoryImplementation != address(0)) { + console2.log(" Implementation:", campaignInfoFactoryImplementation); + } + + console2.log("\n--- Treasury Implementation Contracts ---"); if (campaignInfoImplementation != address(0)) { - console2.log( - "CAMPAIGN_INFO_IMPLEMENTATION_ADDRESS:", - campaignInfoImplementation - ); + console2.log("CAMPAIGN_INFO_IMPLEMENTATION:", campaignInfoImplementation); } - console2.log("TREASURY_FACTORY_ADDRESS:", treasuryFactory); - console2.log("CAMPAIGN_INFO_FACTORY_ADDRESS:", campaignInfoFactory); - console2.log( - "ALL_OR_NOTHING_IMPLEMENTATION_ADDRESS:", - allOrNothingImplementation - ); + console2.log("ALL_OR_NOTHING_IMPLEMENTATION:", allOrNothingImplementation); + + console2.log("\n--- Platform Configuration ---"); + console2.log("Platform Name Hash:", vm.toString(platformHash)); console2.log("Protocol Admin:", finalProtocolAdmin); console2.log("Platform Admin:", finalPlatformAdmin); - console2.log("GlobalParams owner:", GlobalParams(globalParams).owner()); - console2.log("CampaignInfoFactory owner:", CampaignInfoFactory(campaignInfoFactory).owner()); - if (backer1 != address(0)) { - console2.log("Backer1 (tokens minted):", backer1); + console2.log("\n--- Supported Currencies & Tokens ---"); + string memory currenciesConfig = vm.envOr("CURRENCIES", string("")); + if (bytes(currenciesConfig).length > 0) { + string[] memory currencyStrings = _split(currenciesConfig, ","); + string memory tokensConfig = vm.envOr("TOKENS_PER_CURRENCY", string("")); + string[] memory perCurrencyConfigs = _split(tokensConfig, ";"); + + for (uint256 i = 0; i < currencyStrings.length; i++) { + string memory currency = _trimWhitespace(currencyStrings[i]); + console2.log(string(abi.encodePacked("Currency: ", currency))); + + string[] memory tokenStrings = _split(perCurrencyConfigs[i], ","); + for (uint256 j = 0; j < tokenStrings.length; j++) { + console2.log(" Token:", _trimWhitespace(tokenStrings[j])); + } + } + } else { + console2.log("Currency: USD (default)"); + console2.log(" Token:", testToken); + if (testTokenDeployed) { + console2.log(" (TestToken deployed for testing)"); + } } - if (backer2 != address(0) && backer1 != backer2) { - console2.log("Backer2 (tokens minted):", backer2); + + if (backer1 != address(0)) { + console2.log("\n--- Test Backers (Tokens Minted) ---"); + console2.log("Backer1:", backer1); + if (backer2 != address(0) && backer1 != backer2) { + console2.log("Backer2:", backer2); + } } - console2.log("\nDeployment status:"); - console2.log( - "- TestToken:", - testTokenDeployed ? "Newly deployed" : "Reused existing" - ); - console2.log( - "- GlobalParams:", - globalParamsDeployed ? "Newly deployed" : "Reused existing" - ); - console2.log( - "- TreasuryFactory:", - treasuryFactoryDeployed ? "Newly deployed" : "Reused existing" - ); - console2.log( - "- CampaignInfoFactory:", - campaignInfoFactoryDeployed ? "Newly deployed" : "Reused existing" - ); - console2.log( - "- AllOrNothing Implementation:", - allOrNothingDeployed ? "Newly deployed" : "Reused existing" - ); - - console2.log("\nSetup steps:"); - console2.log("1. Platform enlisted:", platformEnlisted); - console2.log( - "2. Treasury implementation registered:", - implementationRegistered - ); - console2.log( - "3. Treasury implementation approved:", - implementationApproved - ); - console2.log("4. Admin rights transferred:", adminRightsTransferred); - - console2.log("\nDeployment and setup completed successfully!"); + console2.log("\n--- Setup Steps ---"); + console2.log("Platform enlisted:", platformEnlisted); + console2.log("Treasury implementation registered:", implementationRegistered); + console2.log("Treasury implementation approved:", implementationApproved); + console2.log("Admin rights transferred:", adminRightsTransferred); + + console2.log("\n==========================================="); + console2.log("Deployment and setup completed successfully!"); + console2.log("==========================================="); } } diff --git a/script/DeployAllAndSetupKeepWhatsRaised.s.sol b/script/DeployAllAndSetupKeepWhatsRaised.s.sol index 59b5ce4b..31281917 100644 --- a/script/DeployAllAndSetupKeepWhatsRaised.s.sol +++ b/script/DeployAllAndSetupKeepWhatsRaised.s.sol @@ -1,7 +1,6 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.22; -import {Script} from "forge-std/Script.sol"; import {console2} from "forge-std/console2.sol"; import {TestToken} from "../test/mocks/TestToken.sol"; import {GlobalParams} from "src/GlobalParams.sol"; @@ -11,40 +10,48 @@ import {TreasuryFactory} from "src/TreasuryFactory.sol"; import {KeepWhatsRaised} from "src/treasuries/KeepWhatsRaised.sol"; import {IGlobalParams} from "src/interfaces/IGlobalParams.sol"; import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; +import {DataRegistryKeys} from "src/constants/DataRegistryKeys.sol"; +import {DeployBase} from "./lib/DeployBase.s.sol"; /** * @notice Script to deploy and setup all needed contracts for the keepWhatsRaised * @dev Updated for the new KeepWhatsRaised contract that stores fees locally */ -contract DeployAllAndSetupKeepWhatsRaised is Script { +contract DeployAllAndSetupKeepWhatsRaised is DeployBase { // Customizable values (set through environment variables) bytes32 platformHash; uint256 protocolFeePercent; uint256 platformFeePercent; uint256 tokenMintAmount; bool simulate; - + uint256 bufferTime; + uint256 campaignLaunchBuffer; + uint256 minimumCampaignDuration; + // Contract addresses address testToken; address globalParams; + address globalParamsImplementation; address campaignInfo; address treasuryFactory; + address treasuryFactoryImplementation; address campaignInfoFactory; + address campaignInfoFactoryImplementation; address keepWhatsRaisedImplementation; - + // User addresses address deployerAddress; address finalProtocolAdmin; address finalPlatformAdmin; address backer1; address backer2; - + // Flags to track what was completed bool platformEnlisted = false; bool implementationRegistered = false; bool implementationApproved = false; bool adminRightsTransferred = false; - + // Flags for contract deployment or reuse bool testTokenDeployed = false; bool globalParamsDeployed = false; @@ -61,24 +68,27 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { platformFeePercent = vm.envOr("PLATFORM_FEE_PERCENT", uint256(600)); // Default 6% tokenMintAmount = vm.envOr("TOKEN_MINT_AMOUNT", uint256(10000000e18)); simulate = vm.envOr("SIMULATE", false); - + bufferTime = vm.envOr("BUFFER_TIME", uint256(0)); + campaignLaunchBuffer = vm.envOr("CAMPAIGN_LAUNCH_BUFFER", uint256(0)); + minimumCampaignDuration = vm.envOr("MINIMUM_CAMPAIGN_DURATION", uint256(0)); + // Get user addresses uint256 deployerKey = vm.envUint("PRIVATE_KEY"); deployerAddress = vm.addr(deployerKey); - + // These are the final admin addresses that will receive control finalProtocolAdmin = vm.envOr("PROTOCOL_ADMIN_ADDRESS", deployerAddress); finalPlatformAdmin = vm.envOr("PLATFORM_ADMIN_ADDRESS", deployerAddress); backer1 = vm.envOr("BACKER1_ADDRESS", address(0)); backer2 = vm.envOr("BACKER2_ADDRESS", address(0)); - + // Check for existing contract addresses testToken = vm.envOr("TOKEN_ADDRESS", address(0)); globalParams = vm.envOr("GLOBAL_PARAMS_ADDRESS", address(0)); treasuryFactory = vm.envOr("TREASURY_FACTORY_ADDRESS", address(0)); campaignInfoFactory = vm.envOr("CAMPAIGN_INFO_FACTORY_ADDRESS", address(0)); keepWhatsRaisedImplementation = vm.envOr("KEEP_WHATS_RAISED_IMPLEMENTATION_ADDRESS", address(0)); - + console2.log("Using platform hash for:", platformName); console2.log("Protocol fee percent:", protocolFeePercent); console2.log("Platform fee percent:", platformFeePercent); @@ -86,88 +96,93 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { console2.log("Deployer address:", deployerAddress); console2.log("Final protocol admin:", finalProtocolAdmin); console2.log("Final platform admin:", finalPlatformAdmin); + console2.log("Buffer time (seconds):", bufferTime); + console2.log("Campaign launch buffer (seconds):", campaignLaunchBuffer); + console2.log("Minimum campaign duration (seconds):", minimumCampaignDuration); + } + + function setRegistryValues() internal { + if (!globalParamsDeployed) { + console2.log("Skipping setRegistryValues - using existing GlobalParams"); + return; + } + + console2.log("Setting registry values on GlobalParams"); + GlobalParams(globalParams).addToRegistry(DataRegistryKeys.BUFFER_TIME, bytes32(bufferTime)); + GlobalParams(globalParams).addToRegistry(DataRegistryKeys.CAMPAIGN_LAUNCH_BUFFER, bytes32(campaignLaunchBuffer)); + GlobalParams(globalParams) + .addToRegistry(DataRegistryKeys.MINIMUM_CAMPAIGN_DURATION, bytes32(minimumCampaignDuration)); } // Deploy or reuse contracts function deployContracts() internal { console2.log("Setting up contracts..."); - + // Deploy or reuse TestToken + // Only deploy TestToken if CURRENCIES is not provided (backward compatibility) string memory tokenName = vm.envOr("TOKEN_NAME", string("TestToken")); string memory tokenSymbol = vm.envOr("TOKEN_SYMBOL", string("TST")); - if (testToken == address(0)) { + if (testToken == address(0) && shouldDeployTestToken()) { uint8 decimals = uint8(vm.envOr("TOKEN_DECIMALS", uint256(18))); testToken = address(new TestToken(tokenName, tokenSymbol, decimals)); testTokenDeployed = true; console2.log("TestToken deployed at:", testToken); - } else { + } else if (testToken != address(0)) { console2.log("Reusing TestToken at:", testToken); + } else { + console2.log("Skipping TestToken deployment - using custom tokens for currencies"); } - + // Deploy or reuse GlobalParams if (globalParams == address(0)) { - // Setup currencies and tokens for multi-token support - bytes32[] memory currencies = new bytes32[](1); - address[][] memory tokensPerCurrency = new address[][](1); - - currencies[0] = keccak256(abi.encodePacked("USD")); - tokensPerCurrency[0] = new address[](1); - tokensPerCurrency[0][0] = testToken; - + (bytes32[] memory currencies, address[][] memory tokensPerCurrency) = loadCurrenciesAndTokens(testToken); + // Deploy GlobalParams with UUPS proxy GlobalParams globalParamsImpl = new GlobalParams(); + globalParamsImplementation = address(globalParamsImpl); bytes memory globalParamsInitData = abi.encodeWithSelector( - GlobalParams.initialize.selector, - deployerAddress, - protocolFeePercent, - currencies, - tokensPerCurrency - ); - ERC1967Proxy globalParamsProxy = new ERC1967Proxy( - address(globalParamsImpl), - globalParamsInitData + GlobalParams.initialize.selector, deployerAddress, protocolFeePercent, currencies, tokensPerCurrency ); + ERC1967Proxy globalParamsProxy = new ERC1967Proxy(address(globalParamsImpl), globalParamsInitData); globalParams = address(globalParamsProxy); globalParamsDeployed = true; - console2.log("GlobalParams deployed at:", globalParams); + console2.log("GlobalParams proxy deployed at:", globalParams); + console2.log(" Implementation:", globalParamsImplementation); } else { console2.log("Reusing GlobalParams at:", globalParams); } - - // We need at least TestToken and GlobalParams to continue - require(testToken != address(0), "TestToken address is required"); + + // GlobalParams is required to continue require(globalParams != address(0), "GlobalParams address is required"); - + // Deploy CampaignInfo implementation if needed for new deployments if (campaignInfoFactory == address(0)) { campaignInfo = address(new CampaignInfo()); console2.log("CampaignInfo deployed at:", campaignInfo); } - + // Deploy or reuse TreasuryFactory if (treasuryFactory == address(0)) { // Deploy TreasuryFactory with UUPS proxy TreasuryFactory treasuryFactoryImpl = new TreasuryFactory(); - bytes memory treasuryFactoryInitData = abi.encodeWithSelector( - TreasuryFactory.initialize.selector, - IGlobalParams(globalParams) - ); - ERC1967Proxy treasuryFactoryProxy = new ERC1967Proxy( - address(treasuryFactoryImpl), - treasuryFactoryInitData - ); + treasuryFactoryImplementation = address(treasuryFactoryImpl); + bytes memory treasuryFactoryInitData = + abi.encodeWithSelector(TreasuryFactory.initialize.selector, IGlobalParams(globalParams)); + ERC1967Proxy treasuryFactoryProxy = new ERC1967Proxy(address(treasuryFactoryImpl), treasuryFactoryInitData); treasuryFactory = address(treasuryFactoryProxy); treasuryFactoryDeployed = true; - console2.log("TreasuryFactory deployed at:", treasuryFactory); + console2.log("TreasuryFactory proxy deployed at:", treasuryFactory); + console2.log(" Implementation:", treasuryFactoryImplementation); } else { console2.log("Reusing TreasuryFactory at:", treasuryFactory); } - + // Deploy or reuse CampaignInfoFactory if (campaignInfoFactory == address(0)) { // Deploy CampaignInfoFactory with UUPS proxy CampaignInfoFactory campaignFactoryImpl = new CampaignInfoFactory(); + campaignInfoFactoryImplementation = address(campaignFactoryImpl); bytes memory campaignFactoryInitData = abi.encodeWithSelector( CampaignInfoFactory.initialize.selector, deployerAddress, @@ -175,17 +190,15 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { campaignInfo, treasuryFactory ); - ERC1967Proxy campaignFactoryProxy = new ERC1967Proxy( - address(campaignFactoryImpl), - campaignFactoryInitData - ); + ERC1967Proxy campaignFactoryProxy = new ERC1967Proxy(address(campaignFactoryImpl), campaignFactoryInitData); campaignInfoFactory = address(campaignFactoryProxy); campaignInfoFactoryDeployed = true; - console2.log("CampaignInfoFactory deployed and initialized at:", campaignInfoFactory); + console2.log("CampaignInfoFactory proxy deployed at:", campaignInfoFactory); + console2.log(" Implementation:", campaignInfoFactoryImplementation); } else { console2.log("Reusing CampaignInfoFactory at:", campaignInfoFactory); } - + // Deploy or reuse KeepWhatsRaised implementation if (keepWhatsRaisedImplementation == address(0)) { keepWhatsRaisedImplementation = address(new KeepWhatsRaised()); @@ -204,26 +217,27 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { platformEnlisted = true; return; } - + console2.log("Setting up: enlistPlatform"); // Only use startPrank in simulation mode if (simulate) { vm.startPrank(deployerAddress); } - - GlobalParams(globalParams).enlistPlatform( - platformHash, - deployerAddress, // Initially deployer is platform admin - platformFeePercent - ); - + + GlobalParams(globalParams) + .enlistPlatform( + platformHash, + deployerAddress, // Initially deployer is platform admin + platformFeePercent + ); + if (simulate) { vm.stopPrank(); } platformEnlisted = true; console2.log("Platform enlisted successfully"); } - + function registerTreasuryImplementation() internal { // Skip if we didn't deploy TreasuryFactory (assuming it's already set up) if (!treasuryFactoryDeployed || !keepWhatsRaisedDeployed) { @@ -231,26 +245,27 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { implementationRegistered = true; return; } - + console2.log("Setting up: registerTreasuryImplementation"); // Only use startPrank in simulation mode if (simulate) { vm.startPrank(deployerAddress); } - - TreasuryFactory(treasuryFactory).registerTreasuryImplementation( - platformHash, - 0, // Implementation ID - keepWhatsRaisedImplementation - ); - + + TreasuryFactory(treasuryFactory) + .registerTreasuryImplementation( + platformHash, + 0, // Implementation ID + keepWhatsRaisedImplementation + ); + if (simulate) { vm.stopPrank(); } implementationRegistered = true; console2.log("Treasury implementation registered successfully"); } - + function approveTreasuryImplementation() internal { // Skip if we didn't deploy TreasuryFactory (assuming it's already set up) if (!treasuryFactoryDeployed || !keepWhatsRaisedDeployed) { @@ -258,32 +273,33 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { implementationApproved = true; return; } - + console2.log("Setting up: approveTreasuryImplementation"); // Only use startPrank in simulation mode if (simulate) { vm.startPrank(deployerAddress); } - - TreasuryFactory(treasuryFactory).approveTreasuryImplementation( - platformHash, - 0 // Implementation ID - ); - + + TreasuryFactory(treasuryFactory) + .approveTreasuryImplementation( + platformHash, + 0 // Implementation ID + ); + if (simulate) { vm.stopPrank(); } implementationApproved = true; console2.log("Treasury implementation approved successfully"); } - + function mintTokens() internal { // Only mint tokens if we deployed TestToken if (!testTokenDeployed) { console2.log("Skipping mintTokens - using existing TestToken"); return; } - + if (backer1 != address(0) && backer2 != address(0)) { console2.log("Minting tokens to test backers"); TestToken(testToken).mint(backer1, tokenMintAmount); @@ -293,7 +309,7 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { console2.log("Tokens minted successfully"); } } - + // Transfer admin rights to final addresses function transferAdminRights() internal { // Skip if we didn't deploy GlobalParams (assuming it's already set up) @@ -302,7 +318,7 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { adminRightsTransferred = true; return; } - + console2.log("Transferring admin rights to final addresses..."); // Only transfer if the final addresses are different from deployer @@ -310,7 +326,7 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { console2.log("Updating platform admin address for platform hash:", vm.toString(platformHash)); GlobalParams(globalParams).updatePlatformAdminAddress(platformHash, finalPlatformAdmin); } - + if (finalProtocolAdmin != deployerAddress) { console2.log("Transferring protocol admin rights to:", finalProtocolAdmin); GlobalParams(globalParams).updateProtocolAdminAddress(finalProtocolAdmin); @@ -321,7 +337,7 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { CampaignInfoFactory(campaignInfoFactory).transferOwnership(finalProtocolAdmin); console2.log("CampaignInfoFactory transferred to:", finalProtocolAdmin); } - + adminRightsTransferred = true; console2.log("Admin rights transferred successfully"); } @@ -331,63 +347,98 @@ contract DeployAllAndSetupKeepWhatsRaised is Script { setupParams(); uint256 deployerKey = vm.envUint("PRIVATE_KEY"); - + // Start broadcast with deployer key vm.startBroadcast(deployerKey); // Deploy or reuse contracts deployContracts(); - + setRegistryValues(); + // Setup the protocol with individual transactions in the correct order // Since deployer is both protocol and platform admin initially, we can do all steps enlistPlatform(); registerTreasuryImplementation(); approveTreasuryImplementation(); - + // Mint tokens if needed mintTokens(); - + // Finally, transfer admin rights to the final addresses transferAdminRights(); - + // Stop broadcast vm.stopBroadcast(); // Output summary - console2.log("\n--- Deployment & Setup Summary ---"); - console2.log("Platform Name Hash:", vm.toString(platformHash)); - console2.log("TOKEN_ADDRESS:", testToken); - console2.log("GLOBAL_PARAMS_ADDRESS:", globalParams); + console2.log("\n==========================================="); + console2.log(" Deployment & Setup Summary"); + console2.log("==========================================="); + console2.log("\n--- Core Protocol Contracts (UUPS Proxies) ---"); + console2.log("GLOBAL_PARAMS_PROXY:", globalParams); + if (globalParamsImplementation != address(0)) { + console2.log(" Implementation:", globalParamsImplementation); + } + console2.log("TREASURY_FACTORY_PROXY:", treasuryFactory); + if (treasuryFactoryImplementation != address(0)) { + console2.log(" Implementation:", treasuryFactoryImplementation); + } + console2.log("CAMPAIGN_INFO_FACTORY_PROXY:", campaignInfoFactory); + if (campaignInfoFactoryImplementation != address(0)) { + console2.log(" Implementation:", campaignInfoFactoryImplementation); + } + + console2.log("\n--- Treasury Implementation Contracts ---"); if (campaignInfo != address(0)) { - console2.log("CAMPAIGN_INFO_ADDRESS:", campaignInfo); + console2.log("CAMPAIGN_INFO_IMPLEMENTATION:", campaignInfo); } - console2.log("TREASURY_FACTORY_ADDRESS:", treasuryFactory); - console2.log("CAMPAIGN_INFO_FACTORY_ADDRESS:", campaignInfoFactory); - console2.log("KEEP_WHATS_RAISED_IMPLEMENTATION_ADDRESS:", keepWhatsRaisedImplementation); + console2.log("KEEP_WHATS_RAISED_IMPLEMENTATION:", keepWhatsRaisedImplementation); + + console2.log("\n--- Platform Configuration ---"); + console2.log("Platform Name Hash:", vm.toString(platformHash)); console2.log("Protocol Admin:", finalProtocolAdmin); console2.log("Platform Admin:", finalPlatformAdmin); - console2.log("GlobalParams owner:", GlobalParams(globalParams).owner()); - console2.log("CampaignInfoFactory owner:", CampaignInfoFactory(campaignInfoFactory).owner()); - - if (backer1 != address(0)) { - console2.log("Backer1 (tokens minted):", backer1); + + console2.log("\n--- Supported Currencies & Tokens ---"); + string memory currenciesConfig = vm.envOr("CURRENCIES", string("")); + if (bytes(currenciesConfig).length > 0) { + string[] memory currencyStrings = _split(currenciesConfig, ","); + string memory tokensConfig = vm.envOr("TOKENS_PER_CURRENCY", string("")); + string[] memory perCurrencyConfigs = _split(tokensConfig, ";"); + + for (uint256 i = 0; i < currencyStrings.length; i++) { + string memory currency = _trimWhitespace(currencyStrings[i]); + console2.log(string(abi.encodePacked("Currency: ", currency))); + + string[] memory tokenStrings = _split(perCurrencyConfigs[i], ","); + for (uint256 j = 0; j < tokenStrings.length; j++) { + console2.log(" Token:", _trimWhitespace(tokenStrings[j])); + } + } + } else { + console2.log("Currency: USD (default)"); + console2.log(" Token:", testToken); + if (testTokenDeployed) { + console2.log(" (TestToken deployed for testing)"); + } } - if (backer2 != address(0) && backer1 != backer2) { - console2.log("Backer2 (tokens minted):", backer2); + + if (backer1 != address(0)) { + console2.log("\n--- Test Backers (Tokens Minted) ---"); + console2.log("Backer1:", backer1); + if (backer2 != address(0) && backer1 != backer2) { + console2.log("Backer2:", backer2); + } } - - console2.log("\nDeployment status:"); - console2.log("- TestToken:", testTokenDeployed ? "Newly deployed" : "Reused existing"); - console2.log("- GlobalParams:", globalParamsDeployed ? "Newly deployed" : "Reused existing"); - console2.log("- TreasuryFactory:", treasuryFactoryDeployed ? "Newly deployed" : "Reused existing"); - console2.log("- CampaignInfoFactory:", campaignInfoFactoryDeployed ? "Newly deployed" : "Reused existing"); - console2.log("- KeepWhatsRaised Implementation:", keepWhatsRaisedDeployed ? "Newly deployed" : "Reused existing"); - - console2.log("\nSetup steps:"); - console2.log("1. Platform enlisted:", platformEnlisted); - console2.log("2. Treasury implementation registered:", implementationRegistered); - console2.log("3. Treasury implementation approved:", implementationApproved); - console2.log("4. Admin rights transferred:", adminRightsTransferred); - console2.log("\nDeployment and setup completed successfully!"); + + console2.log("\n--- Setup Steps ---"); + console2.log("Platform enlisted:", platformEnlisted); + console2.log("Treasury implementation registered:", implementationRegistered); + console2.log("Treasury implementation approved:", implementationApproved); + console2.log("Admin rights transferred:", adminRightsTransferred); + + console2.log("\n==========================================="); + console2.log("Deployment and setup completed successfully!"); + console2.log("==========================================="); } -} \ No newline at end of file +} diff --git a/script/DeployAllAndSetupPaymentTreasury.s.sol b/script/DeployAllAndSetupPaymentTreasury.s.sol index 9c364b74..f772594e 100644 --- a/script/DeployAllAndSetupPaymentTreasury.s.sol +++ b/script/DeployAllAndSetupPaymentTreasury.s.sol @@ -1,7 +1,6 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.22; -import {Script} from "forge-std/Script.sol"; import {console2} from "forge-std/console2.sol"; import {TestToken} from "../test/mocks/TestToken.sol"; import {GlobalParams} from "src/GlobalParams.sol"; @@ -11,24 +10,33 @@ import {TreasuryFactory} from "src/TreasuryFactory.sol"; import {PaymentTreasury} from "src/treasuries/PaymentTreasury.sol"; import {IGlobalParams} from "src/interfaces/IGlobalParams.sol"; import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; +import {DataRegistryKeys} from "src/constants/DataRegistryKeys.sol"; +import {DeployBase} from "./lib/DeployBase.s.sol"; /** * @notice Script to deploy and setup all needed contracts for the protocol */ -contract DeployAllAndSetupPaymentTreasury is Script { +contract DeployAllAndSetupPaymentTreasury is DeployBase { // Customizable values (set through environment variables) bytes32 platformHash; uint256 protocolFeePercent; uint256 platformFeePercent; uint256 tokenMintAmount; bool simulate; + uint256 bufferTime; + uint256 campaignLaunchBuffer; + uint256 minimumCampaignDuration; + uint256 maxPaymentExpiration; // Contract addresses address testToken; address globalParams; + address globalParamsImplementation; address campaignInfoImplementation; address treasuryFactory; + address treasuryFactoryImplementation; address campaignInfoFactory; + address campaignInfoFactoryImplementation; address paymentTreasuryImplementation; // User addresses @@ -58,30 +66,25 @@ contract DeployAllAndSetupPaymentTreasury is Script { // Configure parameters based on environment variables function setupParams() internal { // Get customizable values - string memory platformName = vm.envOr( - "PLATFORM_NAME", - string("E-Commerce") - ); + string memory platformName = vm.envOr("PLATFORM_NAME", string("E-Commerce")); platformHash = keccak256(abi.encodePacked(platformName)); protocolFeePercent = vm.envOr("PROTOCOL_FEE_PERCENT", uint256(100)); // Default 1% platformFeePercent = vm.envOr("PLATFORM_FEE_PERCENT", uint256(400)); // Default 4% tokenMintAmount = vm.envOr("TOKEN_MINT_AMOUNT", uint256(10000000e18)); simulate = vm.envOr("SIMULATE", false); + bufferTime = vm.envOr("BUFFER_TIME", uint256(0)); + campaignLaunchBuffer = vm.envOr("CAMPAIGN_LAUNCH_BUFFER", uint256(0)); + minimumCampaignDuration = vm.envOr("MINIMUM_CAMPAIGN_DURATION", uint256(0)); + maxPaymentExpiration = vm.envOr("MAX_PAYMENT_EXPIRATION", uint256(0)); // Get user addresses uint256 deployerKey = vm.envUint("PRIVATE_KEY"); deployerAddress = vm.addr(deployerKey); // These are the final admin addresses that will receive control - finalProtocolAdmin = vm.envOr( - "PROTOCOL_ADMIN_ADDRESS", - deployerAddress - ); - finalPlatformAdmin = vm.envOr( - "PLATFORM_ADMIN_ADDRESS", - deployerAddress - ); + finalProtocolAdmin = vm.envOr("PROTOCOL_ADMIN_ADDRESS", deployerAddress); + finalPlatformAdmin = vm.envOr("PLATFORM_ADMIN_ADDRESS", deployerAddress); backer1 = vm.envOr("BACKER1_ADDRESS", address(0)); backer2 = vm.envOr("BACKER2_ADDRESS", address(0)); @@ -89,14 +92,8 @@ contract DeployAllAndSetupPaymentTreasury is Script { testToken = vm.envOr("TOKEN_ADDRESS", address(0)); globalParams = vm.envOr("GLOBAL_PARAMS_ADDRESS", address(0)); treasuryFactory = vm.envOr("TREASURY_FACTORY_ADDRESS", address(0)); - campaignInfoFactory = vm.envOr( - "CAMPAIGN_INFO_FACTORY_ADDRESS", - address(0) - ); - paymentTreasuryImplementation = vm.envOr( - "PAYMENT_TREASURY_IMPLEMENTATION_ADDRESS", - address(0) - ); + campaignInfoFactory = vm.envOr("CAMPAIGN_INFO_FACTORY_ADDRESS", address(0)); + paymentTreasuryImplementation = vm.envOr("PAYMENT_TREASURY_IMPLEMENTATION_ADDRESS", address(0)); console2.log("Using platform hash for:", platformName); console2.log("Protocol fee percent:", protocolFeePercent); @@ -105,6 +102,42 @@ contract DeployAllAndSetupPaymentTreasury is Script { console2.log("Deployer address:", deployerAddress); console2.log("Final protocol admin:", finalProtocolAdmin); console2.log("Final platform admin:", finalPlatformAdmin); + console2.log("Buffer time (seconds):", bufferTime); + console2.log("Campaign launch buffer (seconds):", campaignLaunchBuffer); + console2.log("Minimum campaign duration (seconds):", minimumCampaignDuration); + console2.log("Max payment expiration (seconds):", maxPaymentExpiration); + } + + function setRegistryValues() internal { + if (!globalParamsDeployed) { + console2.log("Skipping setRegistryValues - using existing GlobalParams"); + return; + } + + console2.log("Setting registry values on GlobalParams"); + GlobalParams(globalParams).addToRegistry(DataRegistryKeys.BUFFER_TIME, bytes32(bufferTime)); + GlobalParams(globalParams).addToRegistry(DataRegistryKeys.CAMPAIGN_LAUNCH_BUFFER, bytes32(campaignLaunchBuffer)); + GlobalParams(globalParams) + .addToRegistry(DataRegistryKeys.MINIMUM_CAMPAIGN_DURATION, bytes32(minimumCampaignDuration)); + } + + function setPlatformScopedMaxPaymentExpiration() internal { + if (maxPaymentExpiration == 0) { + console2.log("Skipping setPlatformScopedMaxPaymentExpiration - value is 0"); + return; + } + + if (!platformEnlisted) { + console2.log("Skipping setPlatformScopedMaxPaymentExpiration - platform not enlisted"); + return; + } + + console2.log("Setting platform-scoped MAX_PAYMENT_EXPIRATION"); + bytes32 platformScopedKey = + DataRegistryKeys.scopedToPlatform(DataRegistryKeys.MAX_PAYMENT_EXPIRATION, platformHash); + + GlobalParams(globalParams).addToRegistry(platformScopedKey, bytes32(maxPaymentExpiration)); + console2.log("Platform-scoped MAX_PAYMENT_EXPIRATION set successfully"); } // Deploy or reuse contracts @@ -112,79 +145,61 @@ contract DeployAllAndSetupPaymentTreasury is Script { console2.log("Setting up contracts..."); // Deploy or reuse TestToken - + // Only deploy TestToken if CURRENCIES is not provided (backward compatibility) string memory tokenName = vm.envOr("TOKEN_NAME", string("TestToken")); string memory tokenSymbol = vm.envOr("TOKEN_SYMBOL", string("TST")); - if (testToken == address(0)) { + if (testToken == address(0) && shouldDeployTestToken()) { uint8 decimals = uint8(vm.envOr("TOKEN_DECIMALS", uint256(18))); testToken = address(new TestToken(tokenName, tokenSymbol, decimals)); testTokenDeployed = true; console2.log("TestToken deployed at:", testToken); - } else { + } else if (testToken != address(0)) { console2.log("Reusing TestToken at:", testToken); + } else { + console2.log("Skipping TestToken deployment - using custom tokens for currencies"); } // Deploy or reuse GlobalParams if (globalParams == address(0)) { - // Setup currencies and tokens for multi-token support - bytes32[] memory currencies = new bytes32[](1); - address[][] memory tokensPerCurrency = new address[][](1); - - currencies[0] = keccak256(abi.encodePacked("USD")); - tokensPerCurrency[0] = new address[](1); - tokensPerCurrency[0][0] = testToken; - + (bytes32[] memory currencies, address[][] memory tokensPerCurrency) = loadCurrenciesAndTokens(testToken); + // Deploy GlobalParams with UUPS proxy GlobalParams globalParamsImpl = new GlobalParams(); + globalParamsImplementation = address(globalParamsImpl); bytes memory globalParamsInitData = abi.encodeWithSelector( - GlobalParams.initialize.selector, - deployerAddress, - protocolFeePercent, - currencies, - tokensPerCurrency - ); - ERC1967Proxy globalParamsProxy = new ERC1967Proxy( - address(globalParamsImpl), - globalParamsInitData + GlobalParams.initialize.selector, deployerAddress, protocolFeePercent, currencies, tokensPerCurrency ); + ERC1967Proxy globalParamsProxy = new ERC1967Proxy(address(globalParamsImpl), globalParamsInitData); globalParams = address(globalParamsProxy); globalParamsDeployed = true; - console2.log("GlobalParams deployed at:", globalParams); + console2.log("GlobalParams proxy deployed at:", globalParams); + console2.log(" Implementation:", globalParamsImplementation); } else { console2.log("Reusing GlobalParams at:", globalParams); } - // We need at least TestToken and GlobalParams to continue - require(testToken != address(0), "TestToken address is required"); + // GlobalParams is required to continue require(globalParams != address(0), "GlobalParams address is required"); // Deploy CampaignInfo implementation if needed for new deployments if (campaignInfoFactory == address(0)) { - campaignInfoImplementation = address( - new CampaignInfo() - ); - console2.log( - "CampaignInfo implementation deployed at:", - campaignInfoImplementation - ); + campaignInfoImplementation = address(new CampaignInfo()); + console2.log("CampaignInfo implementation deployed at:", campaignInfoImplementation); } // Deploy or reuse TreasuryFactory if (treasuryFactory == address(0)) { // Deploy TreasuryFactory with UUPS proxy TreasuryFactory treasuryFactoryImpl = new TreasuryFactory(); - bytes memory treasuryFactoryInitData = abi.encodeWithSelector( - TreasuryFactory.initialize.selector, - IGlobalParams(globalParams) - ); - ERC1967Proxy treasuryFactoryProxy = new ERC1967Proxy( - address(treasuryFactoryImpl), - treasuryFactoryInitData - ); + treasuryFactoryImplementation = address(treasuryFactoryImpl); + bytes memory treasuryFactoryInitData = + abi.encodeWithSelector(TreasuryFactory.initialize.selector, IGlobalParams(globalParams)); + ERC1967Proxy treasuryFactoryProxy = new ERC1967Proxy(address(treasuryFactoryImpl), treasuryFactoryInitData); treasuryFactory = address(treasuryFactoryProxy); treasuryFactoryDeployed = true; - console2.log("TreasuryFactory deployed at:", treasuryFactory); + console2.log("TreasuryFactory proxy deployed at:", treasuryFactory); + console2.log(" Implementation:", treasuryFactoryImplementation); } else { console2.log("Reusing TreasuryFactory at:", treasuryFactory); } @@ -193,6 +208,7 @@ contract DeployAllAndSetupPaymentTreasury is Script { if (campaignInfoFactory == address(0)) { // Deploy CampaignInfoFactory with UUPS proxy CampaignInfoFactory campaignFactoryImpl = new CampaignInfoFactory(); + campaignInfoFactoryImplementation = address(campaignFactoryImpl); bytes memory campaignFactoryInitData = abi.encodeWithSelector( CampaignInfoFactory.initialize.selector, deployerAddress, @@ -200,36 +216,22 @@ contract DeployAllAndSetupPaymentTreasury is Script { campaignInfoImplementation, treasuryFactory ); - ERC1967Proxy campaignFactoryProxy = new ERC1967Proxy( - address(campaignFactoryImpl), - campaignFactoryInitData - ); + ERC1967Proxy campaignFactoryProxy = new ERC1967Proxy(address(campaignFactoryImpl), campaignFactoryInitData); campaignInfoFactory = address(campaignFactoryProxy); campaignInfoFactoryDeployed = true; - console2.log( - "CampaignInfoFactory deployed and initialized at:", - campaignInfoFactory - ); + console2.log("CampaignInfoFactory proxy deployed at:", campaignInfoFactory); + console2.log(" Implementation:", campaignInfoFactoryImplementation); } else { - console2.log( - "Reusing CampaignInfoFactory at:", - campaignInfoFactory - ); + console2.log("Reusing CampaignInfoFactory at:", campaignInfoFactory); } // Deploy or reuse PaymentTreasury implementation if (paymentTreasuryImplementation == address(0)) { paymentTreasuryImplementation = address(new PaymentTreasury()); paymentTreasuryDeployed = true; - console2.log( - "PaymentTreasury implementation deployed at:", - paymentTreasuryImplementation - ); + console2.log("PaymentTreasury implementation deployed at:", paymentTreasuryImplementation); } else { - console2.log( - "Reusing PaymentTreasury implementation at:", - paymentTreasuryImplementation - ); + console2.log("Reusing PaymentTreasury implementation at:", paymentTreasuryImplementation); } } @@ -237,9 +239,7 @@ contract DeployAllAndSetupPaymentTreasury is Script { function enlistPlatform() internal { // Skip if we didn't deploy GlobalParams (assuming it's already set up) if (!globalParamsDeployed) { - console2.log( - "Skipping enlistPlatform - using existing GlobalParams" - ); + console2.log("Skipping enlistPlatform - using existing GlobalParams"); platformEnlisted = true; return; } @@ -250,11 +250,12 @@ contract DeployAllAndSetupPaymentTreasury is Script { vm.startPrank(deployerAddress); } - GlobalParams(globalParams).enlistPlatform( - platformHash, - deployerAddress, // Initially deployer is platform admin - platformFeePercent - ); + GlobalParams(globalParams) + .enlistPlatform( + platformHash, + deployerAddress, // Initially deployer is platform admin + platformFeePercent + ); if (simulate) { vm.stopPrank(); @@ -266,9 +267,7 @@ contract DeployAllAndSetupPaymentTreasury is Script { function registerTreasuryImplementation() internal { // Skip if we didn't deploy TreasuryFactory (assuming it's already set up) if (!treasuryFactoryDeployed || !paymentTreasuryDeployed) { - console2.log( - "Skipping registerTreasuryImplementation - using existing contracts" - ); + console2.log("Skipping registerTreasuryImplementation - using existing contracts"); implementationRegistered = true; return; } @@ -279,11 +278,12 @@ contract DeployAllAndSetupPaymentTreasury is Script { vm.startPrank(deployerAddress); } - TreasuryFactory(treasuryFactory).registerTreasuryImplementation( - platformHash, - 0, // Implementation ID - paymentTreasuryImplementation - ); + TreasuryFactory(treasuryFactory) + .registerTreasuryImplementation( + platformHash, + 0, // Implementation ID + paymentTreasuryImplementation + ); if (simulate) { vm.stopPrank(); @@ -295,9 +295,7 @@ contract DeployAllAndSetupPaymentTreasury is Script { function approveTreasuryImplementation() internal { // Skip if we didn't deploy TreasuryFactory (assuming it's already set up) if (!treasuryFactoryDeployed || !paymentTreasuryDeployed) { - console2.log( - "Skipping approveTreasuryImplementation - using existing contracts" - ); + console2.log("Skipping approveTreasuryImplementation - using existing contracts"); implementationApproved = true; return; } @@ -308,10 +306,11 @@ contract DeployAllAndSetupPaymentTreasury is Script { vm.startPrank(deployerAddress); } - TreasuryFactory(treasuryFactory).approveTreasuryImplementation( - platformHash, - 0 // Implementation ID - ); + TreasuryFactory(treasuryFactory) + .approveTreasuryImplementation( + platformHash, + 0 // Implementation ID + ); if (simulate) { vm.stopPrank(); @@ -341,9 +340,7 @@ contract DeployAllAndSetupPaymentTreasury is Script { function transferAdminRights() internal { // Skip if we didn't deploy GlobalParams (assuming it's already set up) if (!globalParamsDeployed) { - console2.log( - "Skipping transferAdminRights - using existing GlobalParams" - ); + console2.log("Skipping transferAdminRights - using existing GlobalParams"); adminRightsTransferred = true; return; } @@ -352,24 +349,13 @@ contract DeployAllAndSetupPaymentTreasury is Script { // Only transfer if the final addresses are different from deployer if (finalPlatformAdmin != deployerAddress) { - console2.log( - "Updating platform admin address for platform hash:", - vm.toString(platformHash) - ); - GlobalParams(globalParams).updatePlatformAdminAddress( - platformHash, - finalPlatformAdmin - ); + console2.log("Updating platform admin address for platform hash:", vm.toString(platformHash)); + GlobalParams(globalParams).updatePlatformAdminAddress(platformHash, finalPlatformAdmin); } if (finalProtocolAdmin != deployerAddress) { - console2.log( - "Transferring protocol admin rights to:", - finalProtocolAdmin - ); - GlobalParams(globalParams).updateProtocolAdminAddress( - finalProtocolAdmin - ); + console2.log("Transferring protocol admin rights to:", finalProtocolAdmin); + GlobalParams(globalParams).updateProtocolAdminAddress(finalProtocolAdmin); //Transfer admin rights to the final protocol admin GlobalParams(globalParams).transferOwnership(finalProtocolAdmin); @@ -393,10 +379,12 @@ contract DeployAllAndSetupPaymentTreasury is Script { // Deploy or reuse contracts deployContracts(); + setRegistryValues(); // Setup the protocol with individual transactions in the correct order // Since deployer is both protocol and platform admin initially, we can do all steps enlistPlatform(); + setPlatformScopedMaxPaymentExpiration(); registerTreasuryImplementation(); approveTreasuryImplementation(); @@ -410,68 +398,74 @@ contract DeployAllAndSetupPaymentTreasury is Script { vm.stopBroadcast(); // Output summary - console2.log("\n--- Deployment & Setup Summary ---"); - console2.log("Platform Name Hash:", vm.toString(platformHash)); - console2.log("TEST_TOKEN_ADDRESS:", testToken); - console2.log("GLOBAL_PARAMS_ADDRESS:", globalParams); + console2.log("\n==========================================="); + console2.log(" Deployment & Setup Summary"); + console2.log("==========================================="); + console2.log("\n--- Core Protocol Contracts (UUPS Proxies) ---"); + console2.log("GLOBAL_PARAMS_PROXY:", globalParams); + if (globalParamsImplementation != address(0)) { + console2.log(" Implementation:", globalParamsImplementation); + } + console2.log("TREASURY_FACTORY_PROXY:", treasuryFactory); + if (treasuryFactoryImplementation != address(0)) { + console2.log(" Implementation:", treasuryFactoryImplementation); + } + console2.log("CAMPAIGN_INFO_FACTORY_PROXY:", campaignInfoFactory); + if (campaignInfoFactoryImplementation != address(0)) { + console2.log(" Implementation:", campaignInfoFactoryImplementation); + } + + console2.log("\n--- Treasury Implementation Contracts ---"); if (campaignInfoImplementation != address(0)) { - console2.log( - "CAMPAIGN_INFO_IMPLEMENTATION_ADDRESS:", - campaignInfoImplementation - ); + console2.log("CAMPAIGN_INFO_IMPLEMENTATION:", campaignInfoImplementation); } - console2.log("TREASURY_FACTORY_ADDRESS:", treasuryFactory); - console2.log("CAMPAIGN_INFO_FACTORY_ADDRESS:", campaignInfoFactory); - console2.log( - "PAYMENT_TREASURY_IMPLEMENTATION_ADDRESS:", - paymentTreasuryImplementation - ); + console2.log("PAYMENT_TREASURY_IMPLEMENTATION:", paymentTreasuryImplementation); + + console2.log("\n--- Platform Configuration ---"); + console2.log("Platform Name Hash:", vm.toString(platformHash)); console2.log("Protocol Admin:", finalProtocolAdmin); console2.log("Platform Admin:", finalPlatformAdmin); - console2.log("GlobalParams owner:", GlobalParams(globalParams).owner()); - console2.log("CampaignInfoFactory owner:", CampaignInfoFactory(campaignInfoFactory).owner()); - if (backer1 != address(0)) { - console2.log("Backer1 (tokens minted):", backer1); + console2.log("\n--- Supported Currencies & Tokens ---"); + string memory currenciesConfig = vm.envOr("CURRENCIES", string("")); + if (bytes(currenciesConfig).length > 0) { + string[] memory currencyStrings = _split(currenciesConfig, ","); + string memory tokensConfig = vm.envOr("TOKENS_PER_CURRENCY", string("")); + string[] memory perCurrencyConfigs = _split(tokensConfig, ";"); + + for (uint256 i = 0; i < currencyStrings.length; i++) { + string memory currency = _trimWhitespace(currencyStrings[i]); + console2.log(string(abi.encodePacked("Currency: ", currency))); + + string[] memory tokenStrings = _split(perCurrencyConfigs[i], ","); + for (uint256 j = 0; j < tokenStrings.length; j++) { + console2.log(" Token:", _trimWhitespace(tokenStrings[j])); + } + } + } else { + console2.log("Currency: USD (default)"); + console2.log(" Token:", testToken); + if (testTokenDeployed) { + console2.log(" (TestToken deployed for testing)"); + } } - if (backer2 != address(0) && backer1 != backer2) { - console2.log("Backer2 (tokens minted):", backer2); + + if (backer1 != address(0)) { + console2.log("\n--- Test Backers (Tokens Minted) ---"); + console2.log("Backer1:", backer1); + if (backer2 != address(0) && backer1 != backer2) { + console2.log("Backer2:", backer2); + } } - console2.log("\nDeployment status:"); - console2.log( - "- TestToken:", - testTokenDeployed ? "Newly deployed" : "Reused existing" - ); - console2.log( - "- GlobalParams:", - globalParamsDeployed ? "Newly deployed" : "Reused existing" - ); - console2.log( - "- TreasuryFactory:", - treasuryFactoryDeployed ? "Newly deployed" : "Reused existing" - ); - console2.log( - "- CampaignInfoFactory:", - campaignInfoFactoryDeployed ? "Newly deployed" : "Reused existing" - ); - console2.log( - "- PaymentTreasury Implementation:", - paymentTreasuryDeployed ? "Newly deployed" : "Reused existing" - ); - - console2.log("\nSetup steps:"); - console2.log("1. Platform enlisted:", platformEnlisted); - console2.log( - "2. Treasury implementation registered:", - implementationRegistered - ); - console2.log( - "3. Treasury implementation approved:", - implementationApproved - ); - console2.log("4. Admin rights transferred:", adminRightsTransferred); - - console2.log("\nDeployment and setup completed successfully!"); + console2.log("\n--- Setup Steps ---"); + console2.log("Platform enlisted:", platformEnlisted); + console2.log("Treasury implementation registered:", implementationRegistered); + console2.log("Treasury implementation approved:", implementationApproved); + console2.log("Admin rights transferred:", adminRightsTransferred); + + console2.log("\n==========================================="); + console2.log("Deployment and setup completed successfully!"); + console2.log("==========================================="); } } diff --git a/script/DeployGlobalParams.s.sol b/script/DeployGlobalParams.s.sol index a3df403f..525558db 100644 --- a/script/DeployGlobalParams.s.sol +++ b/script/DeployGlobalParams.s.sol @@ -8,30 +8,19 @@ import {DeployBase} from "./lib/DeployBase.s.sol"; contract DeployGlobalParams is DeployBase { function deployWithToken(address token) public returns (address) { address deployer = vm.addr(vm.envUint("PRIVATE_KEY")); - - // Setup currencies and tokens for multi-token support - bytes32[] memory currencies = new bytes32[](1); - address[][] memory tokensPerCurrency = new address[][](1); - - currencies[0] = keccak256(abi.encodePacked("USD")); - tokensPerCurrency[0] = new address[](1); - tokensPerCurrency[0][0] = token; - + + (bytes32[] memory currencies, address[][] memory tokensPerCurrency) = loadCurrenciesAndTokens(token); + // Deploy implementation GlobalParams implementation = new GlobalParams(); - + // Prepare initialization data - bytes memory initData = abi.encodeWithSelector( - GlobalParams.initialize.selector, - deployer, - 200, - currencies, - tokensPerCurrency - ); - + bytes memory initData = + abi.encodeWithSelector(GlobalParams.initialize.selector, deployer, 200, currencies, tokensPerCurrency); + // Deploy proxy ERC1967Proxy proxy = new ERC1967Proxy(address(implementation), initData); - + return address(proxy); } @@ -43,30 +32,19 @@ contract DeployGlobalParams is DeployBase { address deployer = vm.addr(vm.envUint("PRIVATE_KEY")); address token = vm.envOr("TOKEN_ADDRESS", address(0)); require(token != address(0), "TestToken address must be set"); - - // Setup currencies and tokens for multi-token support - bytes32[] memory currencies = new bytes32[](1); - address[][] memory tokensPerCurrency = new address[][](1); - - currencies[0] = keccak256(abi.encodePacked("USD")); - tokensPerCurrency[0] = new address[](1); - tokensPerCurrency[0][0] = token; - + + (bytes32[] memory currencies, address[][] memory tokensPerCurrency) = loadCurrenciesAndTokens(token); + // Deploy implementation GlobalParams implementation = new GlobalParams(); - + // Prepare initialization data - bytes memory initData = abi.encodeWithSelector( - GlobalParams.initialize.selector, - deployer, - 200, - currencies, - tokensPerCurrency - ); - + bytes memory initData = + abi.encodeWithSelector(GlobalParams.initialize.selector, deployer, 200, currencies, tokensPerCurrency); + // Deploy proxy ERC1967Proxy proxy = new ERC1967Proxy(address(implementation), initData); - + return address(proxy); } diff --git a/script/DeployKeepWhatsRaised.s.sol b/script/DeployKeepWhatsRaised.s.sol index e6c0413d..45a450d8 100644 --- a/script/DeployKeepWhatsRaised.s.sol +++ b/script/DeployKeepWhatsRaised.s.sol @@ -1,16 +1,19 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity ^0.8.22; -import "forge-std/Script.sol"; -import "forge-std/console.sol"; +import {Script} from "forge-std/Script.sol"; +import {console2} from "forge-std/console2.sol"; import {KeepWhatsRaised} from "src/treasuries/KeepWhatsRaised.sol"; contract DeployKeepWhatsRaisedImplementation is Script { function deploy() public returns (address) { - console.log("Deploying KeepWhatsRaisedImplementation..."); - KeepWhatsRaised KeepWhatsRaisedImplementation = new KeepWhatsRaised(); - console.log("KeepWhatsRaisedImplementation deployed at:", address(KeepWhatsRaisedImplementation)); - return address(KeepWhatsRaisedImplementation); + console2.log("Deploying KeepWhatsRaisedImplementation..."); + KeepWhatsRaised keepWhatsRaisedImplementation = new KeepWhatsRaised(); + console2.log( + "KeepWhatsRaisedImplementation deployed at:", + address(keepWhatsRaisedImplementation) + ); + return address(keepWhatsRaisedImplementation); } function run() external { @@ -27,6 +30,9 @@ contract DeployKeepWhatsRaisedImplementation is Script { vm.stopBroadcast(); } - console.log("KEEP_WHATS_RAISED_IMPLEMENTATION_ADDRESS", implementationAddress); + console2.log( + "KEEP_WHATS_RAISED_IMPLEMENTATION_ADDRESS", + implementationAddress + ); } } \ No newline at end of file diff --git a/script/UpgradeCampaignInfoFactory.s.sol b/script/UpgradeCampaignInfoFactory.s.sol index 22b54eea..bc460fa8 100644 --- a/script/UpgradeCampaignInfoFactory.s.sol +++ b/script/UpgradeCampaignInfoFactory.s.sol @@ -4,7 +4,6 @@ pragma solidity ^0.8.22; import {Script} from "forge-std/Script.sol"; import {console2} from "forge-std/console2.sol"; import {CampaignInfoFactory} from "../src/CampaignInfoFactory.sol"; -import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; /** * @title UpgradeCampaignInfoFactory diff --git a/script/UpgradeGlobalParams.s.sol b/script/UpgradeGlobalParams.s.sol index 69d51f4f..8f1dab67 100644 --- a/script/UpgradeGlobalParams.s.sol +++ b/script/UpgradeGlobalParams.s.sol @@ -4,7 +4,6 @@ pragma solidity ^0.8.22; import {Script} from "forge-std/Script.sol"; import {console2} from "forge-std/console2.sol"; import {GlobalParams} from "../src/GlobalParams.sol"; -import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; /** * @title UpgradeGlobalParams diff --git a/script/UpgradeTreasuryFactory.s.sol b/script/UpgradeTreasuryFactory.s.sol index f56357b1..2a62fd5a 100644 --- a/script/UpgradeTreasuryFactory.s.sol +++ b/script/UpgradeTreasuryFactory.s.sol @@ -4,7 +4,6 @@ pragma solidity ^0.8.22; import {Script} from "forge-std/Script.sol"; import {console2} from "forge-std/console2.sol"; import {TreasuryFactory} from "../src/TreasuryFactory.sol"; -import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; /** * @title UpgradeTreasuryFactory diff --git a/script/lib/DeployBase.s.sol b/script/lib/DeployBase.s.sol index efb34b6c..a61ebe50 100644 --- a/script/lib/DeployBase.s.sol +++ b/script/lib/DeployBase.s.sol @@ -5,10 +5,10 @@ import {Script} from "forge-std/Script.sol"; import {console2} from "forge-std/console2.sol"; contract DeployBase is Script { - function deployOrUse( - string memory envVar, - function() internal returns (address) deployFn - ) internal returns (address deployedOrExisting) { + function deployOrUse(string memory envVar, function() internal returns (address) deployFn) + internal + returns (address deployedOrExisting) + { address existing = vm.envOr(envVar, address(0)); if (existing != address(0)) { console2.log(envVar, "Using existing contract at:", existing); @@ -18,4 +18,146 @@ contract DeployBase is Script { deployedOrExisting = deployFn(); console2.log(envVar, "Deployed new contract at:", deployedOrExisting); } + + /** + * @notice Checks if TestToken deployment should be skipped + * @dev TestToken is only needed when CURRENCIES is not provided (defaults to USD) + * @return true if TestToken should be deployed, false otherwise + */ + function shouldDeployTestToken() internal returns (bool) { + string memory currenciesConfig = vm.envOr("CURRENCIES", string("")); + return bytes(currenciesConfig).length == 0; + } + + function loadCurrenciesAndTokens(address defaultToken) + internal + returns (bytes32[] memory currencies, address[][] memory tokensPerCurrency) + { + string memory currenciesConfig = vm.envOr("CURRENCIES", string("")); + if (bytes(currenciesConfig).length == 0) { + currencies = new bytes32[](1); + currencies[0] = _toCurrencyKey("USD"); + + tokensPerCurrency = new address[][](1); + tokensPerCurrency[0] = new address[](1); + tokensPerCurrency[0][0] = defaultToken; + return (currencies, tokensPerCurrency); + } + + string memory tokensConfig = vm.envOr("TOKENS_PER_CURRENCY", string("")); + require(bytes(tokensConfig).length != 0, "TOKENS_PER_CURRENCY env must be set"); + + string[] memory currencyStrings = _split(currenciesConfig, ","); + string[] memory perCurrencyConfigs = _split(tokensConfig, ";"); + require(currencyStrings.length == perCurrencyConfigs.length, "TOKENS_PER_CURRENCY length mismatch"); + + currencies = new bytes32[](currencyStrings.length); + for (uint256 i = 0; i < currencyStrings.length; i++) { + string memory currency = _trimWhitespace(currencyStrings[i]); + require(bytes(currency).length != 0, "Currency value empty"); + currencies[i] = _toCurrencyKey(currency); + } + + tokensPerCurrency = new address[][](perCurrencyConfigs.length); + for (uint256 i = 0; i < perCurrencyConfigs.length; i++) { + string[] memory tokenStrings = _split(perCurrencyConfigs[i], ","); + require(tokenStrings.length > 0, "Currency must have at least one token"); + + tokensPerCurrency[i] = new address[](tokenStrings.length); + for (uint256 j = 0; j < tokenStrings.length; j++) { + string memory tokenString = _trimWhitespace(tokenStrings[j]); + require(bytes(tokenString).length != 0, "Token address string empty"); + + address tokenAddress = vm.parseAddress(tokenString); + require(tokenAddress != address(0), "Token address cannot be zero"); + tokensPerCurrency[i][j] = tokenAddress; + } + } + } + + function _split(string memory input, string memory delimiter) internal pure returns (string[] memory) { + bytes memory inputBytes = bytes(input); + bytes memory delimiterBytes = bytes(delimiter); + require(delimiterBytes.length == 1, "Delimiter must be a single character"); + + if (inputBytes.length == 0) { + string[] memory empty = new string[](1); + empty[0] = ""; + return empty; + } + + uint256 parts = 1; + for (uint256 i = 0; i < inputBytes.length; i++) { + if (inputBytes[i] == delimiterBytes[0]) { + unchecked { + ++parts; + } + } + } + + string[] memory output = new string[](parts); + uint256 lastIndex = 0; + uint256 partIndex = 0; + + for (uint256 i = 0; i <= inputBytes.length; i++) { + if (i == inputBytes.length || inputBytes[i] == delimiterBytes[0]) { + output[partIndex] = _substring(inputBytes, lastIndex, i); + unchecked { + ++partIndex; + } + lastIndex = i + 1; + } + } + + return output; + } + + function _substring(bytes memory input, uint256 start, uint256 end) internal pure returns (string memory) { + require(end >= start && end <= input.length, "Invalid substring range"); + + bytes memory result = new bytes(end - start); + for (uint256 i = start; i < end; i++) { + result[i - start] = input[i]; + } + return string(result); + } + + function _trimWhitespace(string memory input) internal pure returns (string memory) { + bytes memory inputBytes = bytes(input); + uint256 start = 0; + uint256 end = inputBytes.length; + + while (start < end && _isWhitespace(inputBytes[start])) { + unchecked { + ++start; + } + } + + while (end > start && _isWhitespace(inputBytes[end - 1])) { + unchecked { + --end; + } + } + + if (start == 0 && end == inputBytes.length) { + return input; + } + + return _substring(inputBytes, start, end); + } + + function _isWhitespace(bytes1 char) private pure returns (bool) { + return char == 0x20 /* space */ || char == 0x09 /* tab */ || char == 0x0A /* line feed */ || char == 0x0D; /* carriage return */ + } + + function _toCurrencyKey(string memory currency) internal pure returns (bytes32) { + bytes memory currencyBytes = bytes(currency); + require(currencyBytes.length <= 32, "Currency too long"); + + bytes32 key; + assembly { + key := mload(add(currency, 32)) + } + return key; + } } From 75eceea790d5b8f344ca2d98f8188235f230b7a6 Mon Sep 17 00:00:00 2001 From: mahabubAlahi <32974385+mahabubAlahi@users.noreply.github.com> Date: Tue, 2 Dec 2025 21:08:29 +0600 Subject: [PATCH 54/63] Immunefi audit fixes v2 (#57) * Enhance deadline validation in CampaignInfo contract (#46) (immunefi-v2)(issue#6) - Updated the deadline validation logic to ensure that the campaign deadline is not only after the launch time but also meets the minimum campaign duration requirement. * Refactor TimeConstrainedPaymentTreasury to use unified pause and cancel modifiers (#47) (immunefi-v2)(issue#7) - Updated function modifiers in TimeConstrainedPaymentTreasury to replace specific campaign pause and cancel checks with more general whenNotPaused and whenNotCancelled modifiers. * Fix missing Access Control on withdraw allows blocking refund mechanism (#48) (immunefi-v2)(issue#9) * Add access control modifier to BasePaymentTreasury - Introduced `onlyPlatformAdminOrCampaignOwner` modifier to restrict access to specific functions, allowing only the platform admin or campaign owner to execute them. * Enhance PaymentTreasury tests with campaign owner authorization for withdrawals - Updated integration and unit tests to use the campaign owner as the authorized caller for the withdraw function, ensuring proper access control. - Refactored multiple test cases to include `vm.prank(owner)` before withdrawal calls, improving test accuracy and reflecting the latest access control changes. * Campaign owner can block protocol/platform fee & reward collection in PaymentTreasury and TimeConstrainedPaymentTreasury (#49) * Refactor claimExpiredFunds and disburseFees functions in PaymentTreasury and TimeConstrainedPaymentTreasury - Removed the whenNotCancelled modifier from claimExpiredFunds and disburseFees functions in both PaymentTreasury and TimeConstrainedPaymentTreasury contracts to simplify access control. - Added claimNonGoalLineItems function to both contracts, allowing for the claiming of non-goal line items while maintaining the whenNotPaused modifier for access control. * Fix disburseFees vulnerability in PaymentTreasury tests - Updated unit tests to ensure disburseFees() function succeeds even when the treasury is cancelled, addressing a potential vulnerability. - Added comments for clarity on the expected behavior of disburseFees() in the context of cancelled treasuries. * Enhance Payment ID Handling in BasePaymentTreasury (#52) * Enhance Payment ID Handling in BasePaymentTreasury - Introduced new functions for scoping payment IDs for both off-chain and on-chain payments, improving the ability to track and manage payments. - Added a mapping to associate payment IDs with creator addresses for better lookup capabilities. - Updated existing payment processing functions to utilize the new scoping methods, ensuring consistent handling of payment IDs across various operations. - Enhanced error handling to prevent duplicate payment entries by checking both off-chain and on-chain scopes. * Refactor Payment Processing Logic in BasePaymentTreasury - Removed the restriction for NFT payments in the refund process, allowing for broader payment handling. * Emit PledgeNFTMinted event before _safeMint call (#50) Co-authored-by: adnhq * Add character validation for NFT name (#56) Co-authored-by: adnhq * Add launch time validation to updateLaunchTime (#55) * Add campaign launch time buffer check to updateLaunchTime * Change updateLaunchTime validation to check new launch time is greater than the existing one --------- Co-authored-by: adnhq * Fix precision loss for token amount denormalization (#53) Co-authored-by: adnhq * Cache globalParams instance in updateSelectedPlatform to reduce gas usage (#51) Co-authored-by: adnhq * Add ERC-2771 Meta-Transaction Support for Adapter Contracts (#54) * Add ERC2771 Meta Transaction support * Simplify ERC2771 implementation --------- Co-authored-by: adnhq * Add env field for platform adapter input (#58) Co-authored-by: adnhq * Update documentation --------- Co-authored-by: AdnanHKx --- docs/book.toml | 2 +- .../CampaignInfo.sol/contract.CampaignInfo.md | 98 +- .../contract.CampaignInfoFactory.md | 22 +- .../GlobalParams.sol/contract.GlobalParams.md | 176 ++- .../contract.TreasuryFactory.md | 18 +- .../library.DataRegistryKeys.md | 14 +- .../interface.ICampaignData.md | 12 +- .../interface.ICampaignInfo.md | 36 +- .../interface.ICampaignInfoFactory.md | 8 +- .../interface.ICampaignPaymentTreasury.md | 14 +- .../interface.ICampaignTreasury.md | 2 +- .../interface.IGlobalParams.md | 41 +- .../interfaces/IItem.sol/interface.IItem.md | 14 +- .../IReward.sol/interface.IReward.md | 2 +- .../interface.ITreasuryFactory.md | 21 +- .../library.AdminAccessCheckerStorage.md | 6 +- .../library.CampaignInfoFactoryStorage.md | 6 +- .../library.GlobalParamsStorage.md | 8 +- .../library.TreasuryFactoryStorage.md | 6 +- .../AllOrNothing.sol/contract.AllOrNothing.md | 58 +- .../contract.KeepWhatsRaised.md | 219 ++-- .../contract.PaymentTreasury.md | 41 +- ...contract.TimeConstrainedPaymentTreasury.md | 73 +- .../abstract.AdminAccessChecker.md | 34 +- .../abstract.BasePaymentTreasury.md | 283 +++-- .../BaseTreasury.sol/abstract.BaseTreasury.md | 68 +- .../abstract.CampaignAccessChecker.md | 51 +- .../utils/Counters.sol/library.Counters.md | 9 +- .../FiatEnabled.sol/abstract.FiatEnabled.md | 16 +- .../ItemRegistry.sol/contract.ItemRegistry.md | 12 +- .../abstract.PausableCancellable.md | 30 +- .../utils/PledgeNFT.sol/abstract.PledgeNFT.md | 63 +- .../abstract.TimestampChecker.md | 20 +- env.example | 1 + script/DeployAll.s.sol | 27 +- script/DeployAllAndSetupAllOrNothing.s.sol | 51 +- script/DeployAllAndSetupKeepWhatsRaised.s.sol | 51 +- script/DeployAllAndSetupPaymentTreasury.s.sol | 51 +- script/DeployAllOrNothingImplementation.s.sol | 10 +- script/DeployCampaignInfoFactory.s.sol | 10 +- script/DeployCampaignInfoImplementation.s.sol | 5 +- script/DeployKeepWhatsRaised.s.sol | 12 +- script/DeployTreasuryFactory.s.sol | 14 +- script/UpgradeCampaignInfoFactory.s.sol | 5 +- script/UpgradeGlobalParams.s.sol | 5 +- script/UpgradeTreasuryFactory.s.sol | 5 +- src/CampaignInfo.sol | 178 +-- src/CampaignInfoFactory.sol | 42 +- src/GlobalParams.sol | 257 ++-- src/TreasuryFactory.sol | 65 +- src/interfaces/ICampaignInfo.sol | 25 +- src/interfaces/ICampaignInfoFactory.sol | 13 +- src/interfaces/ICampaignPaymentTreasury.sol | 19 +- src/interfaces/IGlobalParams.sol | 58 +- src/interfaces/IItem.sol | 5 +- src/interfaces/ITreasuryFactory.sol | 25 +- src/storage/AdminAccessCheckerStorage.sol | 2 +- src/storage/CampaignInfoFactoryStorage.sol | 2 +- src/storage/GlobalParamsStorage.sol | 4 +- src/storage/TreasuryFactoryStorage.sol | 2 +- src/treasuries/AllOrNothing.sol | 135 +-- src/treasuries/KeepWhatsRaised.sol | 363 +++--- src/treasuries/PaymentTreasury.sol | 74 +- .../TimeConstrainedPaymentTreasury.sol | 82 +- src/utils/AdminAccessChecker.sol | 1 - src/utils/BasePaymentTreasury.sol | 874 +++++++------- src/utils/BaseTreasury.sol | 107 +- src/utils/CampaignAccessChecker.sol | 4 +- src/utils/FiatEnabled.sol | 34 +- src/utils/ItemRegistry.sol | 10 +- src/utils/PausableCancellable.sol | 8 +- src/utils/PledgeNFT.sol | 96 +- src/utils/TimestampChecker.sol | 13 +- test/foundry/Base.t.sol | 74 +- .../AllOrNothing/AllOrNothing.t.sol | 136 +-- .../AllOrNothing/AllOrNothingFunction.t.sol | 354 ++---- .../KeepWhatsRaised/KeepWhatsRaised.t.sol | 34 +- .../KeepWhatsRaisedFunction.t.sol | 182 ++- .../PaymentTreasury/PaymentTreasury.t.sol | 162 ++- .../PaymentTreasuryBatchLimitTest.t.sol | 18 +- .../PaymentTreasuryFunction.t.sol | 411 +++---- .../PaymentTreasuryLineItems.t.sol | 225 ++-- .../TimeConstrainedPaymentTreasury.t.sol | 2 +- ...meConstrainedPaymentTreasuryFunction.t.sol | 179 +-- test/foundry/unit/CampaignInfo.t.sol | 350 ++---- test/foundry/unit/CampaignInfoFactory.t.sol | 81 +- test/foundry/unit/GlobalParams.t.sol | 155 ++- test/foundry/unit/KeepWhatsRaised.t.sol | 1037 +++++++++-------- test/foundry/unit/PaymentTreasury.t.sol | 795 +++++++------ test/foundry/unit/PledgeNFT.t.sol | 107 +- .../unit/TimeConstrainedPaymentTreasury.t.sol | 282 +++-- test/foundry/unit/TreasuryFactory.t.sol | 107 +- test/foundry/unit/Upgrades.t.sol | 132 +-- test/foundry/utils/Defaults.sol | 6 +- test/foundry/utils/LogDecoder.sol | 36 +- test/mocks/TestToken.sol | 9 +- 96 files changed, 4265 insertions(+), 4837 deletions(-) diff --git a/docs/book.toml b/docs/book.toml index def08238..ce804787 100644 --- a/docs/book.toml +++ b/docs/book.toml @@ -7,7 +7,7 @@ no-section-label = true additional-js = ["solidity.min.js"] additional-css = ["book.css"] mathjax-support = true -git-repository-url = "https://github.com/ccprotocol/ccprotocol-contracts-internal" +git-repository-url = "https://github.com/oak-network/ccprotocol-contracts-internal" [output.html.fold] enable = true diff --git a/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md b/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md index 2797c314..5602899c 100644 --- a/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md +++ b/docs/src/src/CampaignInfo.sol/contract.CampaignInfo.md @@ -1,8 +1,8 @@ # CampaignInfo -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/CampaignInfo.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/CampaignInfo.sol) **Inherits:** -[ICampaignData](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md), [ICampaignInfo](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md), Ownable, [PausableCancellable](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md), [TimestampChecker](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), [AdminAccessChecker](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md), [PledgeNFT](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/PledgeNFT.sol/abstract.PledgeNFT.md), Initializable +[ICampaignData](/src/interfaces/ICampaignData.sol/interface.ICampaignData.md), [ICampaignInfo](/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md), Ownable, [PausableCancellable](/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md), [TimestampChecker](/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), [AdminAccessChecker](/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md), [PledgeNFT](/src/utils/PledgeNFT.sol/abstract.PledgeNFT.md), Initializable Manages campaign information and platform data. @@ -11,70 +11,70 @@ Manages campaign information and platform data. ### s_campaignData ```solidity -CampaignData private s_campaignData +CampaignData private s_campaignData; ``` ### s_platformTreasuryAddress ```solidity -mapping(bytes32 => address) private s_platformTreasuryAddress +mapping(bytes32 => address) private s_platformTreasuryAddress; ``` ### s_platformFeePercent ```solidity -mapping(bytes32 => uint256) private s_platformFeePercent +mapping(bytes32 => uint256) private s_platformFeePercent; ``` ### s_isSelectedPlatform ```solidity -mapping(bytes32 => bool) private s_isSelectedPlatform +mapping(bytes32 => bool) private s_isSelectedPlatform; ``` ### s_isApprovedPlatform ```solidity -mapping(bytes32 => bool) private s_isApprovedPlatform +mapping(bytes32 => bool) private s_isApprovedPlatform; ``` ### s_platformData ```solidity -mapping(bytes32 => bytes32) private s_platformData +mapping(bytes32 => bytes32) private s_platformData; ``` ### s_approvedPlatformHashes ```solidity -bytes32[] private s_approvedPlatformHashes +bytes32[] private s_approvedPlatformHashes; ``` ### s_acceptedTokens ```solidity -address[] private s_acceptedTokens +address[] private s_acceptedTokens; ``` ### s_isAcceptedToken ```solidity -mapping(address => bool) private s_isAcceptedToken +mapping(address => bool) private s_isAcceptedToken; ``` ### s_isLocked ```solidity -bool private s_isLocked +bool private s_isLocked; ``` @@ -88,7 +88,7 @@ function getApprovedPlatformHashes() external view returns (bytes32[] memory); ### isLocked -Returns whether the campaign is locked (after treasury deployment). +*Returns whether the campaign is locked (after treasury deployment).* ```solidity @@ -103,11 +103,11 @@ function isLocked() external view override returns (bool); ### whenNotLocked -Modifier that checks if the campaign is not locked. +*Modifier that checks if the campaign is not locked.* ```solidity -modifier whenNotLocked() ; +modifier whenNotLocked(); ``` ### constructor @@ -168,7 +168,7 @@ function checkIfPlatformSelected(bytes32 platformHash) public view override retu ### checkIfPlatformApproved -Check if a platform is already approved +*Check if a platform is already approved* ```solidity @@ -221,7 +221,7 @@ function getProtocolAdminAddress() public view override returns (address); Retrieves the total amount raised across non-cancelled treasuries. -This excludes cancelled treasuries and is affected by refunds. +*This excludes cancelled treasuries and is affected by refunds.* ```solidity @@ -238,9 +238,9 @@ function getTotalRaisedAmount() external view override returns (uint256); Retrieves the total lifetime raised amount across all treasuries. -This amount never decreases even when refunds are processed. +*This amount never decreases even when refunds are processed. It represents the sum of all pledges/payments ever made to the campaign, -regardless of cancellations or refunds. +regardless of cancellations or refunds.* ```solidity @@ -257,9 +257,9 @@ function getTotalLifetimeRaisedAmount() external view returns (uint256); Retrieves the total refunded amount across all treasuries. -This is calculated as the difference between lifetime raised amount +*This is calculated as the difference between lifetime raised amount and current raised amount. It represents the sum of all refunds -that have been processed across all treasuries. +that have been processed across all treasuries.* ```solidity @@ -276,9 +276,9 @@ function getTotalRefundedAmount() external view returns (uint256); Retrieves the total available raised amount across all treasuries. -This includes funds from both active and cancelled treasuries, +*This includes funds from both active and cancelled treasuries, and is affected by refunds. It represents the actual current -balance of funds across all treasuries. +balance of funds across all treasuries.* ```solidity @@ -295,9 +295,9 @@ function getTotalAvailableRaisedAmount() external view returns (uint256); Retrieves the total raised amount from cancelled treasuries only. -This is the opposite of getTotalRaisedAmount(), which only includes +*This is the opposite of getTotalRaisedAmount(), which only includes non-cancelled treasuries. This function only sums up raised amounts -from treasuries that have been cancelled. +from treasuries that have been cancelled.* ```solidity @@ -314,8 +314,8 @@ function getTotalCancelledAmount() external view returns (uint256); Retrieves the total expected (pending) amount across payment treasuries. -This only applies to payment treasuries and represents payments that -have been created but not yet confirmed. Regular treasuries are skipped. +*This only applies to payment treasuries and represents payments that +have been created but not yet confirmed. Regular treasuries are skipped.* ```solidity @@ -462,7 +462,7 @@ function isTokenAccepted(address token) external view override returns (bool); ### paused -Returns true if the campaign is paused, and false otherwise. +*Returns true if the campaign is paused, and false otherwise.* ```solidity @@ -471,7 +471,7 @@ function paused() public view override(ICampaignInfo, PausableCancellable) retur ### cancelled -Returns true if the campaign is cancelled, and false otherwise. +*Returns true if the campaign is cancelled, and false otherwise.* ```solidity @@ -632,8 +632,8 @@ function getLineItemType(bytes32 platformHash, bytes32 typeId) ### transferOwnership -Transfers ownership of the contract to a new account (`newOwner`). -Can only be called by the current owner. +*Transfers ownership of the contract to a new account (`newOwner`). +Can only be called by the current owner.* ```solidity @@ -706,7 +706,7 @@ function updateGoalAmount(uint256 goalAmount) Updates the selection status of a platform for the campaign. -It can only be called for a platform if its not approved i.e. the platform treasury is not deployed +*It can only be called for a platform if its not approved i.e. the platform treasury is not deployed* ```solidity @@ -729,7 +729,7 @@ function updateSelectedPlatform( ### _pauseCampaign -External function to pause the campaign. +*External function to pause the campaign.* ```solidity @@ -738,7 +738,7 @@ function _pauseCampaign(bytes32 message) external onlyProtocolAdmin; ### _unpauseCampaign -External function to unpause the campaign. +*External function to unpause the campaign.* ```solidity @@ -747,7 +747,7 @@ function _unpauseCampaign(bytes32 message) external onlyProtocolAdmin; ### _cancelCampaign -External function to cancel the campaign. +*External function to cancel the campaign.* ```solidity @@ -758,7 +758,7 @@ function _cancelCampaign(bytes32 message) external; Sets the image URI for NFT metadata -Can only be updated before campaign launch +*Can only be updated before campaign launch* ```solidity @@ -779,7 +779,7 @@ function setImageURI(string calldata newImageURI) Updates the contract-level metadata URI -Can only be updated before campaign launch +*Can only be updated before campaign launch* ```solidity @@ -819,7 +819,7 @@ function burn(uint256 tokenId) public override(ICampaignInfo, PledgeNFT); ### _setPlatformInfo -Sets platform information for the campaign and grants treasury role. +*Sets platform information for the campaign and grants treasury role.* ```solidity @@ -835,7 +835,7 @@ function _setPlatformInfo(bytes32 platformHash, address platformTreasuryAddress) ## Events ### CampaignInfoLaunchTimeUpdated -Emitted when the launch time of the campaign is updated. +*Emitted when the launch time of the campaign is updated.* ```solidity @@ -849,7 +849,7 @@ event CampaignInfoLaunchTimeUpdated(uint256 newLaunchTime); |`newLaunchTime`|`uint256`|The new launch time.| ### CampaignInfoDeadlineUpdated -Emitted when the deadline of the campaign is updated. +*Emitted when the deadline of the campaign is updated.* ```solidity @@ -863,7 +863,7 @@ event CampaignInfoDeadlineUpdated(uint256 newDeadline); |`newDeadline`|`uint256`|The new deadline.| ### CampaignInfoGoalAmountUpdated -Emitted when the goal amount of the campaign is updated. +*Emitted when the goal amount of the campaign is updated.* ```solidity @@ -877,7 +877,7 @@ event CampaignInfoGoalAmountUpdated(uint256 newGoalAmount); |`newGoalAmount`|`uint256`|The new goal amount.| ### CampaignInfoSelectedPlatformUpdated -Emitted when the selection state of a platform is updated. +*Emitted when the selection state of a platform is updated.* ```solidity @@ -892,7 +892,7 @@ event CampaignInfoSelectedPlatformUpdated(bytes32 indexed platformHash, bool sel |`selection`|`bool`|The new selection state.| ### CampaignInfoPlatformInfoUpdated -Emitted when platform information is updated for the campaign. +*Emitted when platform information is updated for the campaign.* ```solidity @@ -908,7 +908,7 @@ event CampaignInfoPlatformInfoUpdated(bytes32 indexed platformHash, address inde ## Errors ### CampaignInfoInvalidPlatformUpdate -Emitted when an invalid platform update is attempted. +*Emitted when an invalid platform update is attempted.* ```solidity @@ -923,7 +923,7 @@ error CampaignInfoInvalidPlatformUpdate(bytes32 platformHash, bool selection); |`selection`|`bool`|The selection state (true/false).| ### CampaignInfoUnauthorized -Emitted when an unauthorized action is attempted. +*Emitted when an unauthorized action is attempted.* ```solidity @@ -931,7 +931,7 @@ error CampaignInfoUnauthorized(); ``` ### CampaignInfoInvalidInput -Emitted when an invalid input is detected. +*Emitted when an invalid input is detected.* ```solidity @@ -939,7 +939,7 @@ error CampaignInfoInvalidInput(); ``` ### CampaignInfoPlatformNotSelected -Emitted when a platform is not selected for the campaign. +*Emitted when a platform is not selected for the campaign.* ```solidity @@ -953,7 +953,7 @@ error CampaignInfoPlatformNotSelected(bytes32 platformHash); |`platformHash`|`bytes32`|The bytes32 identifier of the platform.| ### CampaignInfoPlatformAlreadyApproved -Emitted when a platform is already approved for the campaign. +*Emitted when a platform is already approved for the campaign.* ```solidity @@ -967,7 +967,7 @@ error CampaignInfoPlatformAlreadyApproved(bytes32 platformHash); |`platformHash`|`bytes32`|The bytes32 identifier of the platform.| ### CampaignInfoIsLocked -Emitted when an operation is attempted on a locked campaign. +*Emitted when an operation is attempted on a locked campaign.* ```solidity diff --git a/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md b/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md index eaa3cb69..665700b5 100644 --- a/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md +++ b/docs/src/src/CampaignInfoFactory.sol/contract.CampaignInfoFactory.md @@ -1,22 +1,22 @@ # CampaignInfoFactory -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/CampaignInfoFactory.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/CampaignInfoFactory.sol) **Inherits:** -Initializable, [ICampaignInfoFactory](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md), OwnableUpgradeable, UUPSUpgradeable +Initializable, [ICampaignInfoFactory](/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md), OwnableUpgradeable, UUPSUpgradeable Factory contract for creating campaign information contracts. -UUPS Upgradeable contract with ERC-7201 namespaced storage +*UUPS Upgradeable contract with ERC-7201 namespaced storage* ## Functions ### constructor -Constructor that disables initializers to prevent implementation contract initialization +*Constructor that disables initializers to prevent implementation contract initialization* ```solidity -constructor() ; +constructor(); ``` ### initialize @@ -44,7 +44,7 @@ function initialize( ### _authorizeUpgrade -Function that authorizes an upgrade to a new implementation +*Function that authorizes an upgrade to a new implementation* ```solidity @@ -61,11 +61,11 @@ function _authorizeUpgrade(address newImplementation) internal override onlyOwne Creates a new campaign with NFT -IMPORTANT: Protocol and platform fees are retrieved at execution time and locked +*IMPORTANT: Protocol and platform fees are retrieved at execution time and locked permanently in the campaign contract. Users should verify current fees before calling this function or using intermediate contracts that check fees haven't changed from expected values. The protocol fee is stored as immutable in the cloned -contract and platform fees are stored during initialization. +contract and platform fees are stored during initialization.* ```solidity @@ -157,7 +157,7 @@ function identifierToCampaignInfo(bytes32 identifierHash) external view returns ## Errors ### CampaignInfoFactoryInvalidInput -Emitted when invalid input is provided. +*Emitted when invalid input is provided.* ```solidity @@ -165,7 +165,7 @@ error CampaignInfoFactoryInvalidInput(); ``` ### CampaignInfoFactoryCampaignInitializationFailed -Emitted when campaign creation fails. +*Emitted when campaign creation fails.* ```solidity @@ -185,7 +185,7 @@ error CampaignInfoFactoryCampaignWithSameIdentifierExists(bytes32 identifierHash ``` ### CampaignInfoInvalidTokenList -Emitted when the campaign currency has no tokens. +*Emitted when the campaign currency has no tokens.* ```solidity diff --git a/docs/src/src/GlobalParams.sol/contract.GlobalParams.md b/docs/src/src/GlobalParams.sol/contract.GlobalParams.md index a3665165..a9b94a39 100644 --- a/docs/src/src/GlobalParams.sol/contract.GlobalParams.md +++ b/docs/src/src/GlobalParams.sol/contract.GlobalParams.md @@ -1,40 +1,40 @@ # GlobalParams -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/GlobalParams.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/GlobalParams.sol) **Inherits:** -Initializable, [IGlobalParams](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md), OwnableUpgradeable, UUPSUpgradeable +Initializable, [IGlobalParams](/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md), OwnableUpgradeable, UUPSUpgradeable Manages global parameters and platform information. -UUPS Upgradeable contract with ERC-7201 namespaced storage +*UUPS Upgradeable contract with ERC-7201 namespaced storage* ## State Variables ### ZERO_BYTES ```solidity -bytes32 private constant ZERO_BYTES = 0x0000000000000000000000000000000000000000000000000000000000000000 +bytes32 private constant ZERO_BYTES = 0x0000000000000000000000000000000000000000000000000000000000000000; ``` ## Functions ### notAddressZero -Reverts if the input address is zero. +*Reverts if the input address is zero.* ```solidity -modifier notAddressZero(address account) ; +modifier notAddressZero(address account); ``` ### onlyPlatformAdmin -Modifier that restricts function access to platform administrators of a specific platform. -Users attempting to execute functions with this modifier must be the platform admin for the given platform. +*Modifier that restricts function access to platform administrators of a specific platform. +Users attempting to execute functions with this modifier must be the platform admin for the given platform.* ```solidity -modifier onlyPlatformAdmin(bytes32 platformHash) ; +modifier onlyPlatformAdmin(bytes32 platformHash); ``` **Parameters** @@ -47,21 +47,21 @@ modifier onlyPlatformAdmin(bytes32 platformHash) ; ```solidity -modifier platformIsListed(bytes32 platformHash) ; +modifier platformIsListed(bytes32 platformHash); ``` ### constructor -Constructor that disables initializers to prevent implementation contract initialization +*Constructor that disables initializers to prevent implementation contract initialization* ```solidity -constructor() ; +constructor(); ``` ### initialize -Initializer function (replaces constructor) +*Initializer function (replaces constructor)* ```solidity @@ -84,7 +84,7 @@ function initialize( ### _authorizeUpgrade -Function that authorizes an upgrade to a new implementation +*Function that authorizes an upgrade to a new implementation* ```solidity @@ -322,16 +322,18 @@ function checkIfPlatformDataKeyValid(bytes32 platformDataKey) external view over ### enlistPlatform -Enlists a platform with its admin address and fee percentage. +Enlists a platform with its admin address, fee percentage, and optional adapter. -The platformFeePercent can be any value including zero. +*The platformFeePercent can be any value including zero.* ```solidity -function enlistPlatform(bytes32 platformHash, address platformAdminAddress, uint256 platformFeePercent) - external - onlyOwner - notAddressZero(platformAdminAddress); +function enlistPlatform( + bytes32 platformHash, + address platformAdminAddress, + uint256 platformFeePercent, + address platformAdapter +) external onlyOwner notAddressZero(platformAdminAddress); ``` **Parameters** @@ -340,6 +342,7 @@ function enlistPlatform(bytes32 platformHash, address platformAdminAddress, uint |`platformHash`|`bytes32`|The platform's identifier.| |`platformAdminAddress`|`address`|The platform's admin address.| |`platformFeePercent`|`uint256`|The platform's fee percentage.| +|`platformAdapter`|`address`|The platform's adapter (trusted forwarder) address for ERC-2771 meta-transactions. Can be address(0) if not needed.| ### delistPlatform @@ -470,6 +473,54 @@ function updatePlatformClaimDelay(bytes32 platformHash, uint256 claimDelay) |`claimDelay`|`uint256`|The claim delay in seconds.| +### getPlatformAdapter + +Retrieves the adapter (trusted forwarder) address for a platform. + + +```solidity +function getPlatformAdapter(bytes32 platformHash) + external + view + override + platformIsListed(platformHash) + returns (address); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`platformHash`|`bytes32`|The unique identifier of the platform.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`address`|The adapter address for ERC-2771 meta-transactions.| + + +### setPlatformAdapter + +Sets the adapter (trusted forwarder) address for a platform. + +*Only callable by the protocol admin (owner).* + + +```solidity +function setPlatformAdapter(bytes32 platformHash, address adapter) + external + override + onlyOwner + platformIsListed(platformHash); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`platformHash`|`bytes32`|The unique identifier of the platform.| +|`adapter`|`address`|The address of the adapter contract.| + + ### addTokenToCurrency Adds a token to a currency. @@ -492,11 +543,7 @@ Removes a token from a currency. ```solidity -function removeTokenFromCurrency(bytes32 currency, address token) - external - override - onlyOwner - notAddressZero(token); +function removeTokenFromCurrency(bytes32 currency, address token) external override onlyOwner notAddressZero(token); ``` **Parameters** @@ -531,7 +578,7 @@ function getTokensForCurrency(bytes32 currency) external view override returns ( Sets or updates a platform-specific line item type configuration. -Only callable by the platform admin. +*Only callable by the platform admin.* ```solidity @@ -562,7 +609,7 @@ function setPlatformLineItemType( Removes a platform-specific line item type by setting its exists flag to false. -Only callable by the platform admin. This prevents the type from being used in new pledges. +*Only callable by the platform admin. This prevents the type from being used in new pledges.* ```solidity @@ -618,7 +665,7 @@ function getPlatformLineItemType(bytes32 platformHash, bytes32 typeId) ### _revertIfAddressZero -Reverts if the input address is zero. +*Reverts if the input address is zero.* ```solidity @@ -627,8 +674,8 @@ function _revertIfAddressZero(address account) internal pure; ### _onlyPlatformAdmin -Internal function to check if the sender is the platform administrator for a specific platform. -If the sender is not the platform admin, it reverts with GlobalParamsUnauthorized error. +*Internal function to check if the sender is the platform administrator for a specific platform. +If the sender is not the platform admin, it reverts with GlobalParamsUnauthorized error.* ```solidity @@ -643,13 +690,11 @@ function _onlyPlatformAdmin(bytes32 platformHash) private view; ## Events ### PlatformEnlisted -Emitted when a platform is enlisted. +*Emitted when a platform is enlisted.* ```solidity -event PlatformEnlisted( - bytes32 indexed platformHash, address indexed platformAdminAddress, uint256 platformFeePercent -); +event PlatformEnlisted(bytes32 indexed platformHash, address indexed platformAdminAddress, uint256 platformFeePercent); ``` **Parameters** @@ -661,7 +706,7 @@ event PlatformEnlisted( |`platformFeePercent`|`uint256`|The fee percentage of the enlisted platform.| ### PlatformDelisted -Emitted when a platform is delisted. +*Emitted when a platform is delisted.* ```solidity @@ -675,7 +720,7 @@ event PlatformDelisted(bytes32 indexed platformHash); |`platformHash`|`bytes32`|The identifier of the delisted platform.| ### ProtocolAdminAddressUpdated -Emitted when the protocol admin address is updated. +*Emitted when the protocol admin address is updated.* ```solidity @@ -689,7 +734,7 @@ event ProtocolAdminAddressUpdated(address indexed newAdminAddress); |`newAdminAddress`|`address`|The new protocol admin address.| ### TokenAddedToCurrency -Emitted when a token is added to a currency. +*Emitted when a token is added to a currency.* ```solidity @@ -704,7 +749,7 @@ event TokenAddedToCurrency(bytes32 indexed currency, address indexed token); |`token`|`address`|The token address added.| ### TokenRemovedFromCurrency -Emitted when a token is removed from a currency. +*Emitted when a token is removed from a currency.* ```solidity @@ -719,7 +764,7 @@ event TokenRemovedFromCurrency(bytes32 indexed currency, address indexed token); |`token`|`address`|The token address removed.| ### ProtocolFeePercentUpdated -Emitted when the protocol fee percent is updated. +*Emitted when the protocol fee percent is updated.* ```solidity @@ -733,7 +778,7 @@ event ProtocolFeePercentUpdated(uint256 newFeePercent); |`newFeePercent`|`uint256`|The new protocol fee percentage.| ### PlatformAdminAddressUpdated -Emitted when the platform admin address is updated. +*Emitted when the platform admin address is updated.* ```solidity @@ -748,7 +793,7 @@ event PlatformAdminAddressUpdated(bytes32 indexed platformHash, address indexed |`newAdminAddress`|`address`|The new admin address of the platform.| ### PlatformDataAdded -Emitted when platform data is added. +*Emitted when platform data is added.* ```solidity @@ -763,7 +808,7 @@ event PlatformDataAdded(bytes32 indexed platformHash, bytes32 indexed platformDa |`platformDataKey`|`bytes32`|The data key added to the platform.| ### PlatformDataRemoved -Emitted when platform data is removed. +*Emitted when platform data is removed.* ```solidity @@ -778,7 +823,7 @@ event PlatformDataRemoved(bytes32 indexed platformHash, bytes32 platformDataKey) |`platformDataKey`|`bytes32`|The data key removed from the platform.| ### DataAddedToRegistry -Emitted when data is added to the registry. +*Emitted when data is added to the registry.* ```solidity @@ -793,7 +838,7 @@ event DataAddedToRegistry(bytes32 indexed key, bytes32 value); |`value`|`bytes32`|The registry value.| ### PlatformLineItemTypeSet -Emitted when a platform-specific line item type is set or updated. +*Emitted when a platform-specific line item type is set or updated.* ```solidity @@ -826,8 +871,23 @@ event PlatformLineItemTypeSet( event PlatformClaimDelayUpdated(bytes32 indexed platformHash, uint256 claimDelay); ``` +### PlatformAdapterSet +*Emitted when a platform adapter (trusted forwarder) is set.* + + +```solidity +event PlatformAdapterSet(bytes32 indexed platformHash, address indexed adapter); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`platformHash`|`bytes32`|The identifier of the platform.| +|`adapter`|`address`|The address of the adapter contract.| + ### PlatformLineItemTypeRemoved -Emitted when a platform-specific line item type is removed. +*Emitted when a platform-specific line item type is removed.* ```solidity @@ -843,7 +903,7 @@ event PlatformLineItemTypeRemoved(bytes32 indexed platformHash, bytes32 indexed ## Errors ### GlobalParamsInvalidInput -Throws when the input address is zero. +*Throws when the input address is zero.* ```solidity @@ -851,7 +911,7 @@ error GlobalParamsInvalidInput(); ``` ### GlobalParamsPlatformNotListed -Throws when the platform is not listed. +*Throws when the platform is not listed.* ```solidity @@ -865,7 +925,7 @@ error GlobalParamsPlatformNotListed(bytes32 platformHash); |`platformHash`|`bytes32`|The identifier of the platform.| ### GlobalParamsPlatformAlreadyListed -Throws when the platform is already listed. +*Throws when the platform is already listed.* ```solidity @@ -879,7 +939,7 @@ error GlobalParamsPlatformAlreadyListed(bytes32 platformHash); |`platformHash`|`bytes32`|The identifier of the platform.| ### GlobalParamsPlatformAdminNotSet -Throws when the platform admin is not set. +*Throws when the platform admin is not set.* ```solidity @@ -893,7 +953,7 @@ error GlobalParamsPlatformAdminNotSet(bytes32 platformHash); |`platformHash`|`bytes32`|The identifier of the platform.| ### GlobalParamsPlatformFeePercentIsZero -Throws when the platform fee percent is zero. +*Throws when the platform fee percent is zero.* ```solidity @@ -907,7 +967,7 @@ error GlobalParamsPlatformFeePercentIsZero(bytes32 platformHash); |`platformHash`|`bytes32`|The identifier of the platform.| ### GlobalParamsPlatformDataAlreadySet -Throws when the platform data is already set. +*Throws when the platform data is already set.* ```solidity @@ -915,7 +975,7 @@ error GlobalParamsPlatformDataAlreadySet(); ``` ### GlobalParamsPlatformDataNotSet -Throws when the platform data is not set. +*Throws when the platform data is not set.* ```solidity @@ -923,7 +983,7 @@ error GlobalParamsPlatformDataNotSet(); ``` ### GlobalParamsPlatformDataSlotTaken -Throws when the platform data slot is already taken. +*Throws when the platform data slot is already taken.* ```solidity @@ -931,7 +991,7 @@ error GlobalParamsPlatformDataSlotTaken(); ``` ### GlobalParamsUnauthorized -Throws when the caller is not authorized. +*Throws when the caller is not authorized.* ```solidity @@ -939,7 +999,7 @@ error GlobalParamsUnauthorized(); ``` ### GlobalParamsCurrencyTokenLengthMismatch -Throws when currency and token arrays length mismatch. +*Throws when currency and token arrays length mismatch.* ```solidity @@ -947,7 +1007,7 @@ error GlobalParamsCurrencyTokenLengthMismatch(); ``` ### GlobalParamsCurrencyHasNoTokens -Throws when a currency has no tokens registered. +*Throws when a currency has no tokens registered.* ```solidity @@ -961,7 +1021,7 @@ error GlobalParamsCurrencyHasNoTokens(bytes32 currency); |`currency`|`bytes32`|The currency identifier.| ### GlobalParamsTokenNotInCurrency -Throws when a token is not found in a currency. +*Throws when a token is not found in a currency.* ```solidity @@ -976,7 +1036,7 @@ error GlobalParamsTokenNotInCurrency(bytes32 currency, address token); |`token`|`address`|The token address.| ### GlobalParamsPlatformLineItemTypeNotFound -Throws when a platform-specific line item type is not found. +*Throws when a platform-specific line item type is not found.* ```solidity diff --git a/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md b/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md index c635fd1f..d280373b 100644 --- a/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md +++ b/docs/src/src/TreasuryFactory.sol/contract.TreasuryFactory.md @@ -1,22 +1,22 @@ # TreasuryFactory -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/TreasuryFactory.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/TreasuryFactory.sol) **Inherits:** -Initializable, [ITreasuryFactory](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md), [AdminAccessChecker](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md), UUPSUpgradeable +Initializable, [ITreasuryFactory](/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md), [AdminAccessChecker](/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md), UUPSUpgradeable Factory contract for creating treasury contracts -UUPS Upgradeable contract with ERC-7201 namespaced storage +*UUPS Upgradeable contract with ERC-7201 namespaced storage* ## Functions ### constructor -Constructor that disables initializers to prevent implementation contract initialization +*Constructor that disables initializers to prevent implementation contract initialization* ```solidity -constructor() ; +constructor(); ``` ### initialize @@ -36,7 +36,7 @@ function initialize(IGlobalParams globalParams) public initializer; ### _authorizeUpgrade -Function that authorizes an upgrade to a new implementation +*Function that authorizes an upgrade to a new implementation* ```solidity @@ -53,7 +53,7 @@ function _authorizeUpgrade(address newImplementation) internal override onlyProt Registers a treasury implementation for a given platform. -Callable only by the platform admin. +*Callable only by the platform admin.* ```solidity @@ -75,7 +75,7 @@ function registerTreasuryImplementation(bytes32 platformHash, uint256 implementa Approves a previously registered implementation. -Callable only by the protocol admin. +*Callable only by the protocol admin.* ```solidity @@ -130,7 +130,7 @@ function removeTreasuryImplementation(bytes32 platformHash, uint256 implementati Deploys a treasury clone using an approved implementation. -Callable only by the platform admin. +*Callable only by the platform admin.* ```solidity diff --git a/docs/src/src/constants/DataRegistryKeys.sol/library.DataRegistryKeys.md b/docs/src/src/constants/DataRegistryKeys.sol/library.DataRegistryKeys.md index 54dcf73d..7f994c63 100644 --- a/docs/src/src/constants/DataRegistryKeys.sol/library.DataRegistryKeys.md +++ b/docs/src/src/constants/DataRegistryKeys.sol/library.DataRegistryKeys.md @@ -1,38 +1,38 @@ # DataRegistryKeys -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/constants/DataRegistryKeys.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/constants/DataRegistryKeys.sol) Centralized storage for all dataRegistry keys used in GlobalParams -This library provides a single source of truth for all dataRegistry keys -to ensure consistency across contracts and prevent key collisions. +*This library provides a single source of truth for all dataRegistry keys +to ensure consistency across contracts and prevent key collisions.* ## State Variables ### BUFFER_TIME ```solidity -bytes32 public constant BUFFER_TIME = keccak256("bufferTime") +bytes32 public constant BUFFER_TIME = keccak256("bufferTime"); ``` ### MAX_PAYMENT_EXPIRATION ```solidity -bytes32 public constant MAX_PAYMENT_EXPIRATION = keccak256("maxPaymentExpiration") +bytes32 public constant MAX_PAYMENT_EXPIRATION = keccak256("maxPaymentExpiration"); ``` ### CAMPAIGN_LAUNCH_BUFFER ```solidity -bytes32 public constant CAMPAIGN_LAUNCH_BUFFER = keccak256("campaignLaunchBuffer") +bytes32 public constant CAMPAIGN_LAUNCH_BUFFER = keccak256("campaignLaunchBuffer"); ``` ### MINIMUM_CAMPAIGN_DURATION ```solidity -bytes32 public constant MINIMUM_CAMPAIGN_DURATION = keccak256("minimumCampaignDuration") +bytes32 public constant MINIMUM_CAMPAIGN_DURATION = keccak256("minimumCampaignDuration"); ``` diff --git a/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md b/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md index 1cea83cd..ed73ad43 100644 --- a/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md +++ b/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md @@ -1,20 +1,20 @@ # ICampaignData -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/interfaces/ICampaignData.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/interfaces/ICampaignData.sol) An interface for managing campaign data in a CCP. ## Structs ### CampaignData -Struct to represent campaign data, including launch time, deadline, goal amount, and currency. +*Struct to represent campaign data, including launch time, deadline, goal amount, and currency.* ```solidity struct CampaignData { - uint256 launchTime; // Timestamp when the campaign is launched. - uint256 deadline; // Timestamp or block number when the campaign ends. - uint256 goalAmount; // Funding goal amount that the campaign aims to achieve. - bytes32 currency; // Currency identifier for the campaign (e.g., bytes32("USD")). + uint256 launchTime; + uint256 deadline; + uint256 goalAmount; + bytes32 currency; } ``` diff --git a/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md b/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md index 47b5b45f..be1e842e 100644 --- a/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md +++ b/docs/src/src/interfaces/ICampaignInfo.sol/interface.ICampaignInfo.md @@ -1,12 +1,12 @@ # ICampaignInfo -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/interfaces/ICampaignInfo.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/interfaces/ICampaignInfo.sol) **Inherits:** IERC721 An interface for managing campaign information in a crowdfunding system. -Inherits from IERC721 as CampaignInfo is an ERC721 NFT collection +*Inherits from IERC721 as CampaignInfo is an ERC721 NFT collection* ## Functions @@ -50,7 +50,7 @@ function checkIfPlatformSelected(bytes32 platformHash) external view returns (bo Retrieves the total amount raised across non-cancelled treasuries. -This excludes cancelled treasuries and is affected by refunds. +*This excludes cancelled treasuries and is affected by refunds.* ```solidity @@ -67,9 +67,9 @@ function getTotalRaisedAmount() external view returns (uint256); Retrieves the total lifetime raised amount across all treasuries. -This amount never decreases even when refunds are processed. +*This amount never decreases even when refunds are processed. It represents the sum of all pledges/payments ever made to the campaign, -regardless of cancellations or refunds. +regardless of cancellations or refunds.* ```solidity @@ -86,9 +86,9 @@ function getTotalLifetimeRaisedAmount() external view returns (uint256); Retrieves the total refunded amount across all treasuries. -This is calculated as the difference between lifetime raised amount +*This is calculated as the difference between lifetime raised amount and current raised amount. It represents the sum of all refunds -that have been processed across all treasuries. +that have been processed across all treasuries.* ```solidity @@ -105,9 +105,9 @@ function getTotalRefundedAmount() external view returns (uint256); Retrieves the total available raised amount across all treasuries. -This includes funds from both active and cancelled treasuries, +*This includes funds from both active and cancelled treasuries, and is affected by refunds. It represents the actual current -balance of funds across all treasuries. +balance of funds across all treasuries.* ```solidity @@ -124,9 +124,9 @@ function getTotalAvailableRaisedAmount() external view returns (uint256); Retrieves the total raised amount from cancelled treasuries only. -This is the opposite of getTotalRaisedAmount(), which only includes +*This is the opposite of getTotalRaisedAmount(), which only includes non-cancelled treasuries. This function only sums up raised amounts -from treasuries that have been cancelled. +from treasuries that have been cancelled.* ```solidity @@ -143,8 +143,8 @@ function getTotalCancelledAmount() external view returns (uint256); Retrieves the total expected (pending) amount across payment treasuries. -This only applies to payment treasuries and represents payments that -have been created but not yet confirmed. Regular treasuries are skipped. +*This only applies to payment treasuries and represents payments that +have been created but not yet confirmed. Regular treasuries are skipped.* ```solidity @@ -446,7 +446,7 @@ function updateGoalAmount(uint256 goalAmount) external; Updates the selection status of a platform for the campaign. -It can only be called for a platform if its not approved i.e. the platform treasury is not deployed +*It can only be called for a platform if its not approved i.e. the platform treasury is not deployed* ```solidity @@ -469,7 +469,7 @@ function updateSelectedPlatform( ### paused -Returns true if the campaign is paused, and false otherwise. +*Returns true if the campaign is paused, and false otherwise.* ```solidity @@ -478,7 +478,7 @@ function paused() external view returns (bool); ### cancelled -Returns true if the campaign is cancelled, and false otherwise. +*Returns true if the campaign is cancelled, and false otherwise.* ```solidity @@ -562,7 +562,7 @@ function getLineItemType(bytes32 platformHash, bytes32 typeId) Mints a pledge NFT for a backer -Can only be called by treasuries with MINTER_ROLE +*Can only be called by treasuries with MINTER_ROLE* ```solidity @@ -640,7 +640,7 @@ function burn(uint256 tokenId) external; ### isLocked -Returns true if the campaign is locked (after treasury deployment), and false otherwise. +*Returns true if the campaign is locked (after treasury deployment), and false otherwise.* ```solidity diff --git a/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md b/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md index f79aab64..705e4af4 100644 --- a/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md +++ b/docs/src/src/interfaces/ICampaignInfoFactory.sol/interface.ICampaignInfoFactory.md @@ -1,8 +1,8 @@ # ICampaignInfoFactory -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/interfaces/ICampaignInfoFactory.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/interfaces/ICampaignInfoFactory.sol) **Inherits:** -[ICampaignData](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md) +[ICampaignData](/src/interfaces/ICampaignData.sol/interface.ICampaignData.md) An interface for creating and managing campaign information contracts. @@ -12,11 +12,11 @@ An interface for creating and managing campaign information contracts. Creates a new campaign information contract with NFT. -IMPORTANT: Protocol and platform fees are retrieved at execution time and locked +*IMPORTANT: Protocol and platform fees are retrieved at execution time and locked permanently in the campaign contract. Users should verify current fees before calling this function or using intermediate contracts that check fees haven't changed from expected values. The protocol fee is stored as immutable in the cloned -contract and platform fees are stored during initialization. +contract and platform fees are stored during initialization.* ```solidity diff --git a/docs/src/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md b/docs/src/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md index 4335385e..61e4ac92 100644 --- a/docs/src/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md +++ b/docs/src/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md @@ -1,5 +1,5 @@ # ICampaignPaymentTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/interfaces/ICampaignPaymentTreasury.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/interfaces/ICampaignPaymentTreasury.sol) An interface for managing campaign payment treasury contracts. @@ -71,7 +71,7 @@ function createPaymentBatch( Allows a buyer to make a direct crypto payment for an item. -This function transfers tokens directly from the buyer's wallet and confirms the payment immediately. +*This function transfers tokens directly from the buyer's wallet and confirms the payment immediately.* ```solidity @@ -167,7 +167,7 @@ function withdraw() external; Claims a refund for non-NFT payments (payments without minted NFTs). -Only callable by platform admin. Used for payments confirmed without a buyer address. +*Only callable by platform admin. Used for payments confirmed without a buyer address.* ```solidity @@ -185,8 +185,8 @@ function claimRefund(bytes32 paymentId, address refundAddress) external; Claims a refund for NFT payments (payments with minted NFTs). -Burns the NFT associated with the payment. Caller must have approved the treasury for the NFT. -Used for processCryptoPayment and confirmPayment (with buyer address) transactions. +*Burns the NFT associated with the payment. Caller must have approved the treasury for the NFT. +Used for processCryptoPayment and confirmPayment (with buyer address) transactions.* ```solidity @@ -323,7 +323,7 @@ function getRefundedAmount() external view returns (uint256); Retrieves the total expected (pending) amount in the treasury. -This represents payments that have been created but not yet confirmed. +*This represents payments that have been created but not yet confirmed.* ```solidity @@ -437,7 +437,7 @@ struct LineItem { ### ExternalFees Represents metadata about external fees associated with a payment. -These values are informational only and do not affect treasury balances or transfers. +*These values are informational only and do not affect treasury balances or transfers.* ```solidity diff --git a/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md b/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md index e4951516..d9a37a8a 100644 --- a/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md +++ b/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md @@ -1,5 +1,5 @@ # ICampaignTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/interfaces/ICampaignTreasury.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/interfaces/ICampaignTreasury.sol) An interface for managing campaign treasury contracts. diff --git a/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md b/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md index b1a61bb8..8c69ef3a 100644 --- a/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md +++ b/docs/src/src/interfaces/IGlobalParams.sol/interface.IGlobalParams.md @@ -1,5 +1,5 @@ # IGlobalParams -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/interfaces/IGlobalParams.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/interfaces/IGlobalParams.sol) An interface for accessing and managing global parameters of the protocol. @@ -238,6 +238,45 @@ function updatePlatformClaimDelay(bytes32 platformHash, uint256 claimDelay) exte |`claimDelay`|`uint256`|The claim delay in seconds.| +### getPlatformAdapter + +Retrieves the adapter (trusted forwarder) address for a platform. + + +```solidity +function getPlatformAdapter(bytes32 platformHash) external view returns (address); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`platformHash`|`bytes32`|The unique identifier of the platform.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`address`|The adapter address for ERC-2771 meta-transactions.| + + +### setPlatformAdapter + +Sets the adapter (trusted forwarder) address for a platform. + +*Only callable by the protocol admin (owner).* + + +```solidity +function setPlatformAdapter(bytes32 platformHash, address adapter) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`platformHash`|`bytes32`|The unique identifier of the platform.| +|`adapter`|`address`|The address of the adapter contract.| + + ### addTokenToCurrency Adds a token to a currency. diff --git a/docs/src/src/interfaces/IItem.sol/interface.IItem.md b/docs/src/src/interfaces/IItem.sol/interface.IItem.md index 611b26f6..93e22266 100644 --- a/docs/src/src/interfaces/IItem.sol/interface.IItem.md +++ b/docs/src/src/interfaces/IItem.sol/interface.IItem.md @@ -1,5 +1,5 @@ # IItem -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/interfaces/IItem.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/interfaces/IItem.sol) An interface for managing items and their attributes. @@ -50,12 +50,12 @@ Represents the attributes of an item. ```solidity struct Item { - uint256 actualWeight; // The actual weight of the item. - uint256 height; // The height of the item. - uint256 width; // The width of the item. - uint256 length; // The length of the item. - bytes32 category; // The category of the item. - bytes32 declaredCurrency; // The declared currency of the item. + uint256 actualWeight; + uint256 height; + uint256 width; + uint256 length; + bytes32 category; + bytes32 declaredCurrency; } ``` diff --git a/docs/src/src/interfaces/IReward.sol/interface.IReward.md b/docs/src/src/interfaces/IReward.sol/interface.IReward.md index 044f068a..58754ab5 100644 --- a/docs/src/src/interfaces/IReward.sol/interface.IReward.md +++ b/docs/src/src/interfaces/IReward.sol/interface.IReward.md @@ -1,5 +1,5 @@ # IReward -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/interfaces/IReward.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/interfaces/IReward.sol) An interface for managing rewards in a campaign. diff --git a/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md b/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md index 528c2857..ecf224ea 100644 --- a/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md +++ b/docs/src/src/interfaces/ITreasuryFactory.sol/interface.ITreasuryFactory.md @@ -1,7 +1,7 @@ # ITreasuryFactory -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/interfaces/ITreasuryFactory.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/interfaces/ITreasuryFactory.sol) -Interface for the TreasuryFactory contract, which registers, approves, and deploys treasury clones. +*Interface for the TreasuryFactory contract, which registers, approves, and deploys treasury clones.* ## Functions @@ -9,7 +9,7 @@ Interface for the TreasuryFactory contract, which registers, approves, and deplo Registers a treasury implementation for a given platform. -Callable only by the platform admin. +*Callable only by the platform admin.* ```solidity @@ -29,7 +29,7 @@ function registerTreasuryImplementation(bytes32 platformHash, uint256 implementa Approves a previously registered implementation. -Callable only by the protocol admin. +*Callable only by the protocol admin.* ```solidity @@ -78,13 +78,11 @@ function removeTreasuryImplementation(bytes32 platformHash, uint256 implementati Deploys a treasury clone using an approved implementation. -Callable only by the platform admin. +*Callable only by the platform admin.* ```solidity -function deploy(bytes32 platformHash, address infoAddress, uint256 implementationId) - external - returns (address clone); +function deploy(bytes32 platformHash, address infoAddress, uint256 implementationId) external returns (address clone); ``` **Parameters** @@ -103,15 +101,12 @@ function deploy(bytes32 platformHash, address infoAddress, uint256 implementatio ## Events ### TreasuryFactoryTreasuryDeployed -Emitted when a new treasury is deployed. +*Emitted when a new treasury is deployed.* ```solidity event TreasuryFactoryTreasuryDeployed( - bytes32 indexed platformHash, - uint256 indexed implementationId, - address indexed infoAddress, - address treasuryAddress + bytes32 indexed platformHash, uint256 indexed implementationId, address indexed infoAddress, address treasuryAddress ); ``` diff --git a/docs/src/src/storage/AdminAccessCheckerStorage.sol/library.AdminAccessCheckerStorage.md b/docs/src/src/storage/AdminAccessCheckerStorage.sol/library.AdminAccessCheckerStorage.md index 841a0654..8e55e7ba 100644 --- a/docs/src/src/storage/AdminAccessCheckerStorage.sol/library.AdminAccessCheckerStorage.md +++ b/docs/src/src/storage/AdminAccessCheckerStorage.sol/library.AdminAccessCheckerStorage.md @@ -1,9 +1,9 @@ # AdminAccessCheckerStorage -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/storage/AdminAccessCheckerStorage.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/storage/AdminAccessCheckerStorage.sol) Storage contract for AdminAccessChecker using ERC-7201 namespaced storage -This contract contains the storage layout and accessor functions for AdminAccessChecker +*This contract contains the storage layout and accessor functions for AdminAccessChecker* ## State Variables @@ -11,7 +11,7 @@ This contract contains the storage layout and accessor functions for AdminAccess ```solidity bytes32 private constant ADMIN_ACCESS_CHECKER_STORAGE_LOCATION = - 0x7c2f08fa04c2c7c7ab255a45dbf913d4c236b91c59858917e818398e997f8800 + 0x7c2f08fa04c2c7c7ab255a45dbf913d4c236b91c59858917e818398e997f8800; ``` diff --git a/docs/src/src/storage/CampaignInfoFactoryStorage.sol/library.CampaignInfoFactoryStorage.md b/docs/src/src/storage/CampaignInfoFactoryStorage.sol/library.CampaignInfoFactoryStorage.md index 8c5c7a25..aaa73804 100644 --- a/docs/src/src/storage/CampaignInfoFactoryStorage.sol/library.CampaignInfoFactoryStorage.md +++ b/docs/src/src/storage/CampaignInfoFactoryStorage.sol/library.CampaignInfoFactoryStorage.md @@ -1,9 +1,9 @@ # CampaignInfoFactoryStorage -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/storage/CampaignInfoFactoryStorage.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/storage/CampaignInfoFactoryStorage.sol) Storage contract for CampaignInfoFactory using ERC-7201 namespaced storage -This contract contains the storage layout and accessor functions for CampaignInfoFactory +*This contract contains the storage layout and accessor functions for CampaignInfoFactory* ## State Variables @@ -11,7 +11,7 @@ This contract contains the storage layout and accessor functions for CampaignInf ```solidity bytes32 private constant CAMPAIGN_INFO_FACTORY_STORAGE_LOCATION = - 0x2857858a392b093e1f8b3f368c2276ce911f27cef445605a2932ebe945968d00 + 0x2857858a392b093e1f8b3f368c2276ce911f27cef445605a2932ebe945968d00; ``` diff --git a/docs/src/src/storage/GlobalParamsStorage.sol/library.GlobalParamsStorage.md b/docs/src/src/storage/GlobalParamsStorage.sol/library.GlobalParamsStorage.md index 0144834d..8808737a 100644 --- a/docs/src/src/storage/GlobalParamsStorage.sol/library.GlobalParamsStorage.md +++ b/docs/src/src/storage/GlobalParamsStorage.sol/library.GlobalParamsStorage.md @@ -1,9 +1,9 @@ # GlobalParamsStorage -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/storage/GlobalParamsStorage.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/storage/GlobalParamsStorage.sol) Storage contract for GlobalParams using ERC-7201 namespaced storage -This contract contains the storage layout and accessor functions for GlobalParams +*This contract contains the storage layout and accessor functions for GlobalParams* ## State Variables @@ -11,7 +11,7 @@ This contract contains the storage layout and accessor functions for GlobalParam ```solidity bytes32 private constant GLOBAL_PARAMS_STORAGE_LOCATION = - 0x83d0145f7c1378f10048390769ec94f999b3ba6d94904b8fd7251512962b1c00 + 0x83d0145f7c1378f10048390769ec94f999b3ba6d94904b8fd7251512962b1c00; ``` @@ -66,9 +66,9 @@ struct Storage { mapping(bytes32 => bool) platformData; mapping(bytes32 => bytes32) dataRegistry; mapping(bytes32 => address[]) currencyToTokens; - // Platform-specific line item types: mapping(platformHash => mapping(typeId => LineItemType)) mapping(bytes32 => mapping(bytes32 => LineItemType)) platformLineItemTypes; mapping(bytes32 => uint256) platformClaimDelay; + mapping(bytes32 => address) platformAdapter; Counters.Counter numberOfListedPlatforms; } ``` diff --git a/docs/src/src/storage/TreasuryFactoryStorage.sol/library.TreasuryFactoryStorage.md b/docs/src/src/storage/TreasuryFactoryStorage.sol/library.TreasuryFactoryStorage.md index be39f3c7..d57a9f84 100644 --- a/docs/src/src/storage/TreasuryFactoryStorage.sol/library.TreasuryFactoryStorage.md +++ b/docs/src/src/storage/TreasuryFactoryStorage.sol/library.TreasuryFactoryStorage.md @@ -1,9 +1,9 @@ # TreasuryFactoryStorage -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/storage/TreasuryFactoryStorage.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/storage/TreasuryFactoryStorage.sol) Storage contract for TreasuryFactory using ERC-7201 namespaced storage -This contract contains the storage layout and accessor functions for TreasuryFactory +*This contract contains the storage layout and accessor functions for TreasuryFactory* ## State Variables @@ -11,7 +11,7 @@ This contract contains the storage layout and accessor functions for TreasuryFac ```solidity bytes32 private constant TREASURY_FACTORY_STORAGE_LOCATION = - 0x96b7de8c171ef460648aea35787d043e89feb6b6de2623a1e6f17a91b9c9e900 + 0x96b7de8c171ef460648aea35787d043e89feb6b6de2623a1e6f17a91b9c9e900; ``` diff --git a/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md b/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md index aa64c7bf..1f61dc17 100644 --- a/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md +++ b/docs/src/src/treasuries/AllOrNothing.sol/contract.AllOrNothing.md @@ -1,8 +1,8 @@ # AllOrNothing -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/treasuries/AllOrNothing.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/treasuries/AllOrNothing.sol) **Inherits:** -[IReward](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/IReward.sol/interface.IReward.md), [BaseTreasury](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md), [TimestampChecker](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), ReentrancyGuard +[IReward](/src/interfaces/IReward.sol/interface.IReward.md), [BaseTreasury](/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md), [TimestampChecker](/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), ReentrancyGuard A contract for handling crowdfunding campaigns with rewards. @@ -11,53 +11,53 @@ A contract for handling crowdfunding campaigns with rewards. ### s_tokenToTotalCollectedAmount ```solidity -mapping(uint256 => uint256) private s_tokenToTotalCollectedAmount +mapping(uint256 => uint256) private s_tokenToTotalCollectedAmount; ``` ### s_tokenToPledgedAmount ```solidity -mapping(uint256 => uint256) private s_tokenToPledgedAmount +mapping(uint256 => uint256) private s_tokenToPledgedAmount; ``` ### s_reward ```solidity -mapping(bytes32 => Reward) private s_reward +mapping(bytes32 => Reward) private s_reward; ``` ### s_tokenIdToPledgeToken ```solidity -mapping(uint256 => address) private s_tokenIdToPledgeToken +mapping(uint256 => address) private s_tokenIdToPledgeToken; ``` ### s_rewardCounter ```solidity -Counters.Counter private s_rewardCounter +Counters.Counter private s_rewardCounter; ``` ## Functions ### constructor -Constructor for the AllOrNothing contract. +*Constructor for the AllOrNothing contract.* ```solidity -constructor() ; +constructor(); ``` ### initialize ```solidity -function initialize(bytes32 _platformHash, address _infoAddress) external initializer; +function initialize(bytes32 _platformHash, address _infoAddress, address _trustedForwarder) external initializer; ``` ### getReward @@ -130,10 +130,10 @@ function getRefundedAmount() external view override returns (uint256); Adds multiple rewards in a batch. -This function allows for both reward tiers and non-reward tiers. +*This function allows for both reward tiers and non-reward tiers. For both types, rewards must have non-zero value. If items are specified (non-empty arrays), the itemId, itemValue, and itemQuantity arrays must match in length. -Empty arrays are allowed for both reward tiers and non-reward tiers. +Empty arrays are allowed for both reward tiers and non-reward tiers.* ```solidity @@ -178,8 +178,8 @@ function removeReward(bytes32 rewardName) Allows a backer to pledge for a reward. -The first element of the `reward` array must be a reward tier and the other elements can be either reward tiers or non-reward tiers. -The non-reward tiers cannot be pledged for without a reward. +*The first element of the `reward` array must be a reward tier and the other elements can be either reward tiers or non-reward tiers. +The non-reward tiers cannot be pledged for without a reward.* ```solidity @@ -265,7 +265,7 @@ function withdraw() public override whenNotPaused whenNotCancelled; ### cancelTreasury -This function is overridden to allow the platform admin and the campaign owner to cancel a treasury. +*This function is overridden to allow the platform admin and the campaign owner to cancel a treasury.* ```solidity @@ -274,7 +274,7 @@ function cancelTreasury(bytes32 message) public override; ### _checkSuccessCondition -Internal function to check the success condition for fee disbursement. +*Internal function to check the success condition for fee disbursement.* ```solidity @@ -303,7 +303,7 @@ function _pledge( ## Events ### Receipt -Emitted when a backer makes a pledge. +*Emitted when a backer makes a pledge.* ```solidity @@ -331,7 +331,7 @@ event Receipt( |`rewards`|`bytes32[]`|An array of reward names.| ### RewardsAdded -Emitted when rewards are added to the campaign. +*Emitted when rewards are added to the campaign.* ```solidity @@ -346,7 +346,7 @@ event RewardsAdded(bytes32[] rewardNames, Reward[] rewards); |`rewards`|`Reward[]`|The details of the rewards.| ### RewardRemoved -Emitted when a reward is removed from the campaign. +*Emitted when a reward is removed from the campaign.* ```solidity @@ -360,7 +360,7 @@ event RewardRemoved(bytes32 indexed rewardName); |`rewardName`|`bytes32`|The name of the reward.| ### RefundClaimed -Emitted when a refund is claimed. +*Emitted when a refund is claimed.* ```solidity @@ -377,7 +377,7 @@ event RefundClaimed(uint256 tokenId, uint256 refundAmount, address claimer); ## Errors ### AllOrNothingUnAuthorized -Emitted when an unauthorized action is attempted. +*Emitted when an unauthorized action is attempted.* ```solidity @@ -385,7 +385,7 @@ error AllOrNothingUnAuthorized(); ``` ### AllOrNothingInvalidInput -Emitted when an invalid input is detected. +*Emitted when an invalid input is detected.* ```solidity @@ -393,7 +393,7 @@ error AllOrNothingInvalidInput(); ``` ### AllOrNothingTransferFailed -Emitted when a token transfer fails. +*Emitted when a token transfer fails.* ```solidity @@ -401,7 +401,7 @@ error AllOrNothingTransferFailed(); ``` ### AllOrNothingNotSuccessful -Emitted when the campaign is not successful. +*Emitted when the campaign is not successful.* ```solidity @@ -409,7 +409,7 @@ error AllOrNothingNotSuccessful(); ``` ### AllOrNothingFeeNotDisbursed -Emitted when fees are not disbursed. +*Emitted when fees are not disbursed.* ```solidity @@ -417,7 +417,7 @@ error AllOrNothingFeeNotDisbursed(); ``` ### AllOrNothingFeeAlreadyDisbursed -Emitted when `disburseFees` after fee is disbursed already. +*Emitted when `disburseFees` after fee is disbursed already.* ```solidity @@ -425,7 +425,7 @@ error AllOrNothingFeeAlreadyDisbursed(); ``` ### AllOrNothingRewardExists -Emitted when a `Reward` already exists for given input. +*Emitted when a `Reward` already exists for given input.* ```solidity @@ -433,7 +433,7 @@ error AllOrNothingRewardExists(); ``` ### AllOrNothingTokenNotAccepted -Emitted when a token is not accepted for the campaign. +*Emitted when a token is not accepted for the campaign.* ```solidity @@ -441,7 +441,7 @@ error AllOrNothingTokenNotAccepted(address token); ``` ### AllOrNothingNotClaimable -Emitted when claiming an unclaimable refund. +*Emitted when claiming an unclaimable refund.* ```solidity diff --git a/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md b/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md index 5afa5461..5fad796d 100644 --- a/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md +++ b/docs/src/src/treasuries/KeepWhatsRaised.sol/contract.KeepWhatsRaised.md @@ -1,8 +1,8 @@ # KeepWhatsRaised -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/treasuries/KeepWhatsRaised.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/treasuries/KeepWhatsRaised.sol) **Inherits:** -[IReward](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/IReward.sol/interface.IReward.md), [BaseTreasury](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md), [TimestampChecker](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), [ICampaignData](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/ICampaignData.sol/interface.ICampaignData.md), ReentrancyGuard +[IReward](/src/interfaces/IReward.sol/interface.IReward.md), [BaseTreasury](/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md), [TimestampChecker](/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md), [ICampaignData](/src/interfaces/ICampaignData.sol/interface.ICampaignData.md), ReentrancyGuard A contract that keeps all the funds raised, regardless of the success condition. @@ -11,28 +11,28 @@ A contract that keeps all the funds raised, regardless of the success condition. ### s_tokenToPledgedAmount ```solidity -mapping(uint256 => uint256) private s_tokenToPledgedAmount +mapping(uint256 => uint256) private s_tokenToPledgedAmount; ``` ### s_tokenToTippedAmount ```solidity -mapping(uint256 => uint256) private s_tokenToTippedAmount +mapping(uint256 => uint256) private s_tokenToTippedAmount; ``` ### s_tokenToPaymentFee ```solidity -mapping(uint256 => uint256) private s_tokenToPaymentFee +mapping(uint256 => uint256) private s_tokenToPaymentFee; ``` ### s_reward ```solidity -mapping(bytes32 => Reward) private s_reward +mapping(bytes32 => Reward) private s_reward; ``` @@ -41,7 +41,7 @@ Tracks whether a pledge with a specific ID has already been processed ```solidity -mapping(bytes32 => bool) public s_processedPledges +mapping(bytes32 => bool) public s_processedPledges; ``` @@ -50,7 +50,7 @@ Mapping to store payment gateway fees by unique pledge ID ```solidity -mapping(bytes32 => uint256) public s_paymentGatewayFees +mapping(bytes32 => uint256) public s_paymentGatewayFees; ``` @@ -59,149 +59,149 @@ Mapping that stores fee values indexed by their corresponding fee keys. ```solidity -mapping(bytes32 => uint256) private s_feeValues +mapping(bytes32 => uint256) private s_feeValues; ``` ### s_tokenIdToPledgeToken ```solidity -mapping(uint256 => address) private s_tokenIdToPledgeToken +mapping(uint256 => address) private s_tokenIdToPledgeToken; ``` ### s_protocolFeePerToken ```solidity -mapping(address => uint256) private s_protocolFeePerToken +mapping(address => uint256) private s_protocolFeePerToken; ``` ### s_platformFeePerToken ```solidity -mapping(address => uint256) private s_platformFeePerToken +mapping(address => uint256) private s_platformFeePerToken; ``` ### s_tipPerToken ```solidity -mapping(address => uint256) private s_tipPerToken +mapping(address => uint256) private s_tipPerToken; ``` ### s_availablePerToken ```solidity -mapping(address => uint256) private s_availablePerToken +mapping(address => uint256) private s_availablePerToken; ``` ### s_rewardCounter ```solidity -Counters.Counter private s_rewardCounter +Counters.Counter private s_rewardCounter; ``` ### s_cancellationTime ```solidity -uint256 private s_cancellationTime +uint256 private s_cancellationTime; ``` ### s_isWithdrawalApproved ```solidity -bool private s_isWithdrawalApproved +bool private s_isWithdrawalApproved; ``` ### s_tipClaimed ```solidity -bool private s_tipClaimed +bool private s_tipClaimed; ``` ### s_fundClaimed ```solidity -bool private s_fundClaimed +bool private s_fundClaimed; ``` ### s_feeKeys ```solidity -FeeKeys private s_feeKeys +FeeKeys private s_feeKeys; ``` ### s_config ```solidity -Config private s_config +Config private s_config; ``` ### s_campaignData ```solidity -CampaignData private s_campaignData +CampaignData private s_campaignData; ``` ## Functions ### withdrawalEnabled -Ensures that withdrawals are currently enabled. -Reverts with `KeepWhatsRaisedDisabled` if the withdrawal approval flag is not set. +*Ensures that withdrawals are currently enabled. +Reverts with `KeepWhatsRaisedDisabled` if the withdrawal approval flag is not set.* ```solidity -modifier withdrawalEnabled() ; +modifier withdrawalEnabled(); ``` ### onlyBeforeConfigLock -Restricts execution to only occur before the configuration lock period. +*Restricts execution to only occur before the configuration lock period. Reverts with `KeepWhatsRaisedConfigLocked` if called too close to or after the campaign deadline. -The lock period is defined as the duration before the deadline during which configuration changes are not allowed. +The lock period is defined as the duration before the deadline during which configuration changes are not allowed.* ```solidity -modifier onlyBeforeConfigLock() ; +modifier onlyBeforeConfigLock(); ``` ### onlyPlatformAdminOrCampaignOwner Restricts access to only the platform admin or the campaign owner. -Checks if `_msgSender()` is either the platform admin (via `INFO.getPlatformAdminAddress`) -or the campaign owner (via `INFO.owner()`). Reverts with `KeepWhatsRaisedUnAuthorized` if not authorized. +*Checks if `_msgSender()` is either the platform admin (via `INFO.getPlatformAdminAddress`) +or the campaign owner (via `INFO.owner()`). Reverts with `KeepWhatsRaisedUnAuthorized` if not authorized.* ```solidity -modifier onlyPlatformAdminOrCampaignOwner() ; +modifier onlyPlatformAdminOrCampaignOwner(); ``` ### constructor -Constructor for the KeepWhatsRaised contract. +*Constructor for the KeepWhatsRaised contract.* ```solidity -constructor() ; +constructor(); ``` ### initialize ```solidity -function initialize(bytes32 _platformHash, address _infoAddress) external initializer; +function initialize(bytes32 _platformHash, address _infoAddress, address _trustedForwarder) external initializer; ``` ### getWithdrawalApprovalStatus @@ -362,7 +362,7 @@ function getPaymentGatewayFee(bytes32 pledgeId) public view returns (uint256); ### getFeeValue -Retrieves the fee value associated with a specific fee key from storage. +*Retrieves the fee value associated with a specific fee key from storage.* ```solidity @@ -420,8 +420,8 @@ function approveWithdrawal() ### configureTreasury -Configures the treasury for a campaign by setting the system parameters, -campaign-specific data, and fee configuration keys. +*Configures the treasury for a campaign by setting the system parameters, +campaign-specific data, and fee configuration keys.* ```solidity @@ -450,7 +450,7 @@ function configureTreasury( ### updateDeadline -Updates the campaign's deadline. +*Updates the campaign's deadline.* ```solidity @@ -470,7 +470,7 @@ function updateDeadline(uint256 deadline) ### updateGoalAmount -Updates the funding goal amount for the campaign. +*Updates the funding goal amount for the campaign.* ```solidity @@ -492,10 +492,10 @@ function updateGoalAmount(uint256 goalAmount) Adds multiple rewards in a batch. -This function allows for both reward tiers and non-reward tiers. +*This function allows for both reward tiers and non-reward tiers. For both types, rewards must have non-zero value. If items are specified (non-empty arrays), the itemId, itemValue, and itemQuantity arrays must match in length. -Empty arrays are allowed for both reward tiers and non-reward tiers. +Empty arrays are allowed for both reward tiers and non-reward tiers.* ```solidity @@ -578,18 +578,12 @@ function setFeeAndPledge( Allows a backer to pledge for a reward. -The first element of the `reward` array must be a reward tier and the other elements can be either reward tiers or non-reward tiers. -The non-reward tiers cannot be pledged for without a reward. +*The first element of the `reward` array must be a reward tier and the other elements can be either reward tiers or non-reward tiers. +The non-reward tiers cannot be pledged for without a reward.* ```solidity -function pledgeForAReward( - bytes32 pledgeId, - address backer, - address pledgeToken, - uint256 tip, - bytes32[] calldata reward -) +function pledgeForAReward(bytes32 pledgeId, address backer, address pledgeToken, uint256 tip, bytes32[] calldata reward) public nonReentrant currentTimeIsWithinRange(getLaunchTime(), getDeadline()) @@ -613,10 +607,10 @@ function pledgeForAReward( Internal function that allows a backer to pledge for a reward with tokens transferred from a specified source. -The first element of the `reward` array must be a reward tier and the other elements can be either reward tiers or non-reward tiers. +*The first element of the `reward` array must be a reward tier and the other elements can be either reward tiers or non-reward tiers. The non-reward tiers cannot be pledged for without a reward. This function is called internally by both public pledgeForAReward (with backer as token source) and -setFeeAndPledge (with admin as token source). +setFeeAndPledge (with admin as token source).* ```solidity @@ -647,13 +641,7 @@ Allows a backer to pledge without selecting a reward. ```solidity -function pledgeWithoutAReward( - bytes32 pledgeId, - address backer, - address pledgeToken, - uint256 pledgeAmount, - uint256 tip -) +function pledgeWithoutAReward(bytes32 pledgeId, address backer, address pledgeToken, uint256 pledgeAmount, uint256 tip) public nonReentrant currentTimeIsWithinRange(getLaunchTime(), getDeadline()) @@ -677,8 +665,8 @@ function pledgeWithoutAReward( Internal function that allows a backer to pledge without selecting a reward with tokens transferred from a specified source. -This function is called internally by both public pledgeWithoutAReward (with backer as token source) and -setFeeAndPledge (with admin as token source). +*This function is called internally by both public pledgeWithoutAReward (with backer as token source) and +setFeeAndPledge (with admin as token source).* ```solidity @@ -714,7 +702,7 @@ function withdraw() public view override whenNotPaused whenNotCancelled; ### withdraw -Allows the campaign owner or platform admin to withdraw funds, applying required fees and taxes. +*Allows the campaign owner or platform admin to withdraw funds, applying required fees and taxes.* ```solidity @@ -736,7 +724,7 @@ function withdraw(address token, uint256 amount) ### claimRefund -Allows a backer to claim a refund associated with a specific pledge (token ID). +*Allows a backer to claim a refund associated with a specific pledge (token ID).* ```solidity @@ -755,9 +743,9 @@ function claimRefund(uint256 tokenId) ### disburseFees -Disburses all accumulated fees to the appropriate fee collector or treasury. +*Disburses all accumulated fees to the appropriate fee collector or treasury. Requirements: -- Only callable when fees are available. +- Only callable when fees are available.* ```solidity @@ -766,10 +754,10 @@ function disburseFees() public override whenNotPaused whenNotCancelled; ### claimTip -Allows an authorized claimer to collect tips contributed during the campaign. +*Allows an authorized claimer to collect tips contributed during the campaign. Requirements: - Caller must be authorized to claim tips. -- Tip amount must be non-zero. +- Tip amount must be non-zero.* ```solidity @@ -778,10 +766,10 @@ function claimTip() external onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPau ### claimFund -Allows the platform admin to claim the remaining funds from a campaign. +*Allows the platform admin to claim the remaining funds from a campaign. Requirements: - Claim period must have started and funds must be available. -- Cannot be previously claimed. +- Cannot be previously claimed.* ```solidity @@ -790,7 +778,7 @@ function claimFund() external onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPa ### cancelTreasury -This function is overridden to allow the platform admin and the campaign owner to cancel a treasury. +*This function is overridden to allow the platform admin and the campaign owner to cancel a treasury.* ```solidity @@ -799,7 +787,7 @@ function cancelTreasury(bytes32 message) public override onlyPlatformAdminOrCamp ### _checkSuccessCondition -Internal function to check the success condition for fee disbursement. +*Internal function to check the success condition for fee disbursement.* ```solidity @@ -833,12 +821,12 @@ function _pledge( Calculates the net amount available from a pledge after deducting all applicable fees. -The function performs the following: +*The function performs the following: - Applies all configured gross percentage-based fees - Applies payment gateway fee for the given pledge - Applies protocol fee based on protocol configuration - Accumulates total platform and protocol fees per token -- Records the total deducted fee for the token +- Records the total deducted fee for the token* ```solidity @@ -869,9 +857,9 @@ Refund period logic: - If campaign is not cancelled: refund period is active until deadline + s_config.refundDelay - Before deadline (non-cancelled): not in refund period -Checks the refund period status based on campaign state +*Checks the refund period status based on campaign state* -This function handles both cancelled and non-cancelled campaign scenarios +*This function handles both cancelled and non-cancelled campaign scenarios* ```solidity @@ -892,7 +880,7 @@ function _checkRefundPeriodStatus(bool checkIfOver) internal view returns (bool) ## Events ### Receipt -Emitted when a backer makes a pledge. +*Emitted when a backer makes a pledge.* ```solidity @@ -920,7 +908,7 @@ event Receipt( |`rewards`|`bytes32[]`|An array of reward names.| ### RewardsAdded -Emitted when rewards are added to the campaign. +*Emitted when rewards are added to the campaign.* ```solidity @@ -935,7 +923,7 @@ event RewardsAdded(bytes32[] rewardNames, Reward[] rewards); |`rewards`|`Reward[]`|The details of the rewards.| ### RewardRemoved -Emitted when a reward is removed from the campaign. +*Emitted when a reward is removed from the campaign.* ```solidity @@ -949,7 +937,7 @@ event RewardRemoved(bytes32 indexed rewardName); |`rewardName`|`bytes32`|The name of the reward.| ### WithdrawalApproved -Emitted when withdrawal functionality has been approved by the platform admin. +*Emitted when withdrawal functionality has been approved by the platform admin.* ```solidity @@ -957,7 +945,7 @@ event WithdrawalApproved(); ``` ### TreasuryConfigured -Emitted when the treasury configuration is updated. +*Emitted when the treasury configuration is updated.* ```solidity @@ -974,7 +962,7 @@ event TreasuryConfigured(Config config, CampaignData campaignData, FeeKeys feeKe |`feeValues`|`FeeValues`|The fee values corresponding to the fee keys.| ### WithdrawalWithFeeSuccessful -Emitted when a withdrawal is successfully processed along with the applied fee. +*Emitted when a withdrawal is successfully processed along with the applied fee.* ```solidity @@ -990,7 +978,7 @@ event WithdrawalWithFeeSuccessful(address indexed to, uint256 amount, uint256 fe |`fee`|`uint256`|The fee amount deducted from the withdrawal.| ### TipClaimed -Emitted when a tip is claimed from the contract. +*Emitted when a tip is claimed from the contract.* ```solidity @@ -1005,7 +993,7 @@ event TipClaimed(uint256 amount, address indexed claimer); |`claimer`|`address`|The address that claimed the tip.| ### FundClaimed -Emitted when campaign or user's remaining funds are successfully claimed by the platform admin. +*Emitted when campaign or user's remaining funds are successfully claimed by the platform admin.* ```solidity @@ -1020,7 +1008,7 @@ event FundClaimed(uint256 amount, address indexed claimer); |`claimer`|`address`|The address that claimed the funds.| ### RefundClaimed -Emitted when a refund is claimed. +*Emitted when a refund is claimed.* ```solidity @@ -1036,7 +1024,7 @@ event RefundClaimed(uint256 indexed tokenId, uint256 refundAmount, address index |`claimer`|`address`|The address of the claimer.| ### KeepWhatsRaisedDeadlineUpdated -Emitted when the deadline of the campaign is updated. +*Emitted when the deadline of the campaign is updated.* ```solidity @@ -1050,7 +1038,7 @@ event KeepWhatsRaisedDeadlineUpdated(uint256 newDeadline); |`newDeadline`|`uint256`|The new deadline.| ### KeepWhatsRaisedGoalAmountUpdated -Emitted when the goal amount for a campaign is updated. +*Emitted when the goal amount for a campaign is updated.* ```solidity @@ -1064,7 +1052,7 @@ event KeepWhatsRaisedGoalAmountUpdated(uint256 newGoalAmount); |`newGoalAmount`|`uint256`|The new goal amount set for the campaign.| ### KeepWhatsRaisedPaymentGatewayFeeSet -Emitted when a gateway fee is set for a specific pledge. +*Emitted when a gateway fee is set for a specific pledge.* ```solidity @@ -1080,7 +1068,7 @@ event KeepWhatsRaisedPaymentGatewayFeeSet(bytes32 indexed pledgeId, uint256 fee) ## Errors ### KeepWhatsRaisedUnAuthorized -Emitted when an unauthorized action is attempted. +*Emitted when an unauthorized action is attempted.* ```solidity @@ -1088,7 +1076,7 @@ error KeepWhatsRaisedUnAuthorized(); ``` ### KeepWhatsRaisedInvalidInput -Emitted when an invalid input is detected. +*Emitted when an invalid input is detected.* ```solidity @@ -1096,7 +1084,7 @@ error KeepWhatsRaisedInvalidInput(); ``` ### KeepWhatsRaisedTokenNotAccepted -Emitted when a token is not accepted for the campaign. +*Emitted when a token is not accepted for the campaign.* ```solidity @@ -1104,7 +1092,7 @@ error KeepWhatsRaisedTokenNotAccepted(address token); ``` ### KeepWhatsRaisedRewardExists -Emitted when a `Reward` already exists for given input. +*Emitted when a `Reward` already exists for given input.* ```solidity @@ -1112,7 +1100,7 @@ error KeepWhatsRaisedRewardExists(); ``` ### KeepWhatsRaisedDisabled -Emitted when anyone called a disabled function. +*Emitted when anyone called a disabled function.* ```solidity @@ -1120,7 +1108,7 @@ error KeepWhatsRaisedDisabled(); ``` ### KeepWhatsRaisedAlreadyEnabled -Emitted when any functionality is already enabled and cannot be re-enabled. +*Emitted when any functionality is already enabled and cannot be re-enabled.* ```solidity @@ -1128,7 +1116,7 @@ error KeepWhatsRaisedAlreadyEnabled(); ``` ### KeepWhatsRaisedInsufficientFundsForWithdrawalAndFee -Emitted when a withdrawal attempt exceeds the available funds after accounting for the fee. +*Emitted when a withdrawal attempt exceeds the available funds after accounting for the fee.* ```solidity @@ -1161,7 +1149,7 @@ error KeepWhatsRaisedInsufficientFundsForFee(uint256 withdrawalAmount, uint256 f |`fee`|`uint256`|The calculated fee, which is greater than the withdrawal amount.| ### KeepWhatsRaisedAlreadyWithdrawn -Emitted when a withdrawal has already been made and cannot be repeated. +*Emitted when a withdrawal has already been made and cannot be repeated.* ```solidity @@ -1169,7 +1157,7 @@ error KeepWhatsRaisedAlreadyWithdrawn(); ``` ### KeepWhatsRaisedAlreadyClaimed -Emitted when funds or rewards have already been claimed for the given context. +*Emitted when funds or rewards have already been claimed for the given context.* ```solidity @@ -1177,7 +1165,7 @@ error KeepWhatsRaisedAlreadyClaimed(); ``` ### KeepWhatsRaisedNotClaimable -Emitted when a token or pledge is not eligible for claiming (e.g., claim period not reached or not valid). +*Emitted when a token or pledge is not eligible for claiming (e.g., claim period not reached or not valid).* ```solidity @@ -1191,7 +1179,7 @@ error KeepWhatsRaisedNotClaimable(uint256 tokenId); |`tokenId`|`uint256`|The ID of the token that was attempted to be claimed.| ### KeepWhatsRaisedNotClaimableAdmin -Emitted when an admin attempts to claim funds that are not yet claimable according to the rules. +*Emitted when an admin attempts to claim funds that are not yet claimable according to the rules.* ```solidity @@ -1199,7 +1187,7 @@ error KeepWhatsRaisedNotClaimableAdmin(); ``` ### KeepWhatsRaisedConfigLocked -Emitted when a configuration change is attempted during the lock period. +*Emitted when a configuration change is attempted during the lock period.* ```solidity @@ -1207,7 +1195,7 @@ error KeepWhatsRaisedConfigLocked(); ``` ### KeepWhatsRaisedDisbursementBlocked -Emitted when a disbursement is attempted before the refund period has ended. +*Emitted when a disbursement is attempted before the refund period has ended.* ```solidity @@ -1215,7 +1203,7 @@ error KeepWhatsRaisedDisbursementBlocked(); ``` ### KeepWhatsRaisedPledgeAlreadyProcessed -Emitted when a pledge is submitted using a pledgeId that has already been processed. +*Emitted when a pledge is submitted using a pledgeId that has already been processed.* ```solidity @@ -1230,61 +1218,42 @@ error KeepWhatsRaisedPledgeAlreadyProcessed(bytes32 pledgeId); ## Structs ### FeeKeys -Represents keys used to reference different fee configurations. -These keys are typically used to look up fee values stored in `s_platformData`. +*Represents keys used to reference different fee configurations. +These keys are typically used to look up fee values stored in `s_platformData`.* ```solidity struct FeeKeys { - /// @dev Key for a flat fee applied to an operation. bytes32 flatFeeKey; - - /// @dev Key for a cumulative flat fee, potentially across multiple actions. bytes32 cumulativeFlatFeeKey; - - /// @dev Keys for gross percentage-based fees (calculated before deductions). bytes32[] grossPercentageFeeKeys; } ``` ### FeeValues -Represents the complete fee structure values for treasury operations. +*Represents the complete fee structure values for treasury operations. These values correspond to the fees that will be applied to transactions -and are typically retrieved using keys from `FeeKeys` struct. +and are typically retrieved using keys from `FeeKeys` struct.* ```solidity struct FeeValues { - /// @dev Value for a flat fee applied to an operation. uint256 flatFeeValue; - - /// @dev Value for a cumulative flat fee, potentially across multiple actions. uint256 cumulativeFlatFeeValue; - - /// @dev Values for gross percentage-based fees (calculated before deductions). uint256[] grossPercentageFeeValues; } ``` ### Config -System configuration parameters related to withdrawal and refund behavior. +*System configuration parameters related to withdrawal and refund behavior.* ```solidity struct Config { - /// @dev The minimum withdrawal amount required to qualify for fee exemption. uint256 minimumWithdrawalForFeeExemption; - - /// @dev Time delay (in timestamp) enforced before a withdrawal can be completed. uint256 withdrawalDelay; - - /// @dev Time delay (in timestamp) before a refund becomes claimable or processed. uint256 refundDelay; - - /// @dev Duration (in timestamp) for which config changes are locked to prevent immediate updates. uint256 configLockPeriod; - - /// @dev True if the creator is Colombian, false otherwise. bool isColombianCreator; } ``` diff --git a/docs/src/src/treasuries/PaymentTreasury.sol/contract.PaymentTreasury.md b/docs/src/src/treasuries/PaymentTreasury.sol/contract.PaymentTreasury.md index fb7cf9ad..86136646 100644 --- a/docs/src/src/treasuries/PaymentTreasury.sol/contract.PaymentTreasury.md +++ b/docs/src/src/treasuries/PaymentTreasury.sol/contract.PaymentTreasury.md @@ -1,25 +1,25 @@ # PaymentTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/treasuries/PaymentTreasury.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/treasuries/PaymentTreasury.sol) **Inherits:** -[BasePaymentTreasury](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md) +[BasePaymentTreasury](/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md) ## Functions ### constructor -Constructor for the PaymentTreasury contract. +*Constructor for the PaymentTreasury contract.* ```solidity -constructor() ; +constructor(); ``` ### initialize ```solidity -function initialize(bytes32 _platformHash, address _infoAddress) external initializer; +function initialize(bytes32 _platformHash, address _infoAddress, address _trustedForwarder) external initializer; ``` ### createPayment @@ -88,7 +88,7 @@ function createPaymentBatch( Allows a buyer to make a direct crypto payment for an item. -This function transfers tokens directly from the buyer's wallet and confirms the payment immediately. +*This function transfers tokens directly from the buyer's wallet and confirms the payment immediately.* ```solidity @@ -170,7 +170,7 @@ function confirmPaymentBatch(bytes32[] calldata paymentIds, address[] calldata b Claims a refund for non-NFT payments (payments without minted NFTs). -Only callable by platform admin. Used for payments confirmed without a buyer address. +*Only callable by platform admin. Used for payments confirmed without a buyer address.* ```solidity @@ -188,7 +188,7 @@ function claimRefund(bytes32 paymentId, address refundAddress) public override w Claims a refund for non-NFT payments (payments without minted NFTs). -Only callable by platform admin. Used for payments confirmed without a buyer address. +*Only callable by platform admin. Used for payments confirmed without a buyer address.* ```solidity @@ -207,7 +207,7 @@ Allows platform admin to claim all remaining funds once the claim window has ope ```solidity -function claimExpiredFunds() public override whenNotPaused whenNotCancelled; +function claimExpiredFunds() public override whenNotPaused; ``` ### disburseFees @@ -216,9 +216,24 @@ Disburses fees collected by the treasury. ```solidity -function disburseFees() public override whenNotPaused whenNotCancelled; +function disburseFees() public override whenNotPaused; ``` +### claimNonGoalLineItems + +Allows platform admin to claim non-goal line items that are available for claiming. + + +```solidity +function claimNonGoalLineItems(address token) public override whenNotPaused; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`token`|`address`|The token address to claim.| + + ### withdraw Withdraws funds from the treasury. @@ -230,7 +245,7 @@ function withdraw() public override whenNotPaused whenNotCancelled; ### cancelTreasury -This function is overridden to allow the platform admin and the campaign owner to cancel a treasury. +*This function is overridden to allow the platform admin and the campaign owner to cancel a treasury.* ```solidity @@ -239,7 +254,7 @@ function cancelTreasury(bytes32 message) public override; ### _checkSuccessCondition -Internal function to check the success condition for fee disbursement. +*Internal function to check the success condition for fee disbursement.* ```solidity @@ -254,7 +269,7 @@ function _checkSuccessCondition() internal view virtual override returns (bool); ## Errors ### PaymentTreasuryUnAuthorized -Emitted when an unauthorized action is attempted. +*Emitted when an unauthorized action is attempted.* ```solidity diff --git a/docs/src/src/treasuries/TimeConstrainedPaymentTreasury.sol/contract.TimeConstrainedPaymentTreasury.md b/docs/src/src/treasuries/TimeConstrainedPaymentTreasury.sol/contract.TimeConstrainedPaymentTreasury.md index 4e7fd79f..c9df077d 100644 --- a/docs/src/src/treasuries/TimeConstrainedPaymentTreasury.sol/contract.TimeConstrainedPaymentTreasury.md +++ b/docs/src/src/treasuries/TimeConstrainedPaymentTreasury.sol/contract.TimeConstrainedPaymentTreasury.md @@ -1,30 +1,30 @@ # TimeConstrainedPaymentTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/treasuries/TimeConstrainedPaymentTreasury.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/treasuries/TimeConstrainedPaymentTreasury.sol) **Inherits:** -[BasePaymentTreasury](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md), [TimestampChecker](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md) +[BasePaymentTreasury](/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md), [TimestampChecker](/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md) ## Functions ### constructor -Constructor for the TimeConstrainedPaymentTreasury contract. +*Constructor for the TimeConstrainedPaymentTreasury contract.* ```solidity -constructor() ; +constructor(); ``` ### initialize ```solidity -function initialize(bytes32 _platformHash, address _infoAddress) external initializer; +function initialize(bytes32 _platformHash, address _infoAddress, address _trustedForwarder) external initializer; ``` ### _checkTimeWithinRange -Internal function to check if current time is within the allowed range. +*Internal function to check if current time is within the allowed range.* ```solidity @@ -33,7 +33,7 @@ function _checkTimeWithinRange() internal view; ### _checkTimeIsGreater -Internal function to check if current time is greater than launch time. +*Internal function to check if current time is greater than launch time.* ```solidity @@ -55,7 +55,7 @@ function createPayment( uint256 expiration, ICampaignPaymentTreasury.LineItem[] calldata lineItems, ICampaignPaymentTreasury.ExternalFees[] calldata externalFees -) public override whenCampaignNotPaused whenCampaignNotCancelled; +) public override whenNotPaused whenNotCancelled; ``` **Parameters** @@ -86,7 +86,7 @@ function createPaymentBatch( uint256[] calldata expirations, ICampaignPaymentTreasury.LineItem[][] calldata lineItemsArray, ICampaignPaymentTreasury.ExternalFees[][] calldata externalFeesArray -) public override whenCampaignNotPaused whenCampaignNotCancelled; +) public override whenNotPaused whenNotCancelled; ``` **Parameters** @@ -106,7 +106,7 @@ function createPaymentBatch( Allows a buyer to make a direct crypto payment for an item. -This function transfers tokens directly from the buyer's wallet and confirms the payment immediately. +*This function transfers tokens directly from the buyer's wallet and confirms the payment immediately.* ```solidity @@ -118,7 +118,7 @@ function processCryptoPayment( uint256 amount, ICampaignPaymentTreasury.LineItem[] calldata lineItems, ICampaignPaymentTreasury.ExternalFees[] calldata externalFees -) public override whenCampaignNotPaused whenCampaignNotCancelled; +) public override whenNotPaused whenNotCancelled; ``` **Parameters** @@ -139,7 +139,7 @@ Cancels an existing payment with the given payment ID. ```solidity -function cancelPayment(bytes32 paymentId) public override whenCampaignNotPaused whenCampaignNotCancelled; +function cancelPayment(bytes32 paymentId) public override whenNotPaused whenNotCancelled; ``` **Parameters** @@ -154,11 +154,7 @@ Confirms and finalizes the payment associated with the given payment ID. ```solidity -function confirmPayment(bytes32 paymentId, address buyerAddress) - public - override - whenCampaignNotPaused - whenCampaignNotCancelled; +function confirmPayment(bytes32 paymentId, address buyerAddress) public override whenNotPaused whenNotCancelled; ``` **Parameters** @@ -177,8 +173,8 @@ Confirms and finalizes multiple payments in a single transaction. function confirmPaymentBatch(bytes32[] calldata paymentIds, address[] calldata buyerAddresses) public override - whenCampaignNotPaused - whenCampaignNotCancelled; + whenNotPaused + whenNotCancelled; ``` **Parameters** @@ -192,15 +188,11 @@ function confirmPaymentBatch(bytes32[] calldata paymentIds, address[] calldata b Claims a refund for non-NFT payments (payments without minted NFTs). -Only callable by platform admin. Used for payments confirmed without a buyer address. +*Only callable by platform admin. Used for payments confirmed without a buyer address.* ```solidity -function claimRefund(bytes32 paymentId, address refundAddress) - public - override - whenCampaignNotPaused - whenCampaignNotCancelled; +function claimRefund(bytes32 paymentId, address refundAddress) public override whenNotPaused whenNotCancelled; ``` **Parameters** @@ -214,11 +206,11 @@ function claimRefund(bytes32 paymentId, address refundAddress) Claims a refund for non-NFT payments (payments without minted NFTs). -Only callable by platform admin. Used for payments confirmed without a buyer address. +*Only callable by platform admin. Used for payments confirmed without a buyer address.* ```solidity -function claimRefund(bytes32 paymentId) public override whenCampaignNotPaused whenCampaignNotCancelled; +function claimRefund(bytes32 paymentId) public override whenNotPaused whenNotCancelled; ``` **Parameters** @@ -233,7 +225,7 @@ Allows platform admin to claim all remaining funds once the claim window has ope ```solidity -function claimExpiredFunds() public override whenCampaignNotPaused whenCampaignNotCancelled; +function claimExpiredFunds() public override whenNotPaused; ``` ### disburseFees @@ -242,21 +234,36 @@ Disburses fees collected by the treasury. ```solidity -function disburseFees() public override whenCampaignNotPaused whenCampaignNotCancelled; +function disburseFees() public override whenNotPaused; ``` +### claimNonGoalLineItems + +Allows platform admin to claim non-goal line items that are available for claiming. + + +```solidity +function claimNonGoalLineItems(address token) public override whenNotPaused; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`token`|`address`|The token address to claim.| + + ### withdraw Withdraws funds from the treasury. ```solidity -function withdraw() public override whenCampaignNotPaused whenCampaignNotCancelled; +function withdraw() public override whenNotPaused whenNotCancelled; ``` ### cancelTreasury -This function is overridden to allow the platform admin and the campaign owner to cancel a treasury. +*This function is overridden to allow the platform admin and the campaign owner to cancel a treasury.* ```solidity @@ -265,7 +272,7 @@ function cancelTreasury(bytes32 message) public override; ### _checkSuccessCondition -Internal function to check the success condition for fee disbursement. +*Internal function to check the success condition for fee disbursement.* ```solidity @@ -280,7 +287,7 @@ function _checkSuccessCondition() internal view virtual override returns (bool); ## Errors ### TimeConstrainedPaymentTreasuryUnAuthorized -Emitted when an unauthorized action is attempted. +*Emitted when an unauthorized action is attempted.* ```solidity diff --git a/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md b/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md index 6548aae2..9538e053 100644 --- a/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md +++ b/docs/src/src/utils/AdminAccessChecker.sol/abstract.AdminAccessChecker.md @@ -1,19 +1,19 @@ # AdminAccessChecker -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/utils/AdminAccessChecker.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/utils/AdminAccessChecker.sol) **Inherits:** Context -This abstract contract provides access control mechanisms to restrict the execution of specific functions -to authorized protocol administrators and platform administrators. +*This abstract contract provides access control mechanisms to restrict the execution of specific functions +to authorized protocol administrators and platform administrators.* -Updated to use ERC-7201 namespaced storage for upgradeable contracts +*Updated to use ERC-7201 namespaced storage for upgradeable contracts* ## Functions ### __AccessChecker_init -Internal initializer function for AdminAccessChecker +*Internal initializer function for AdminAccessChecker* ```solidity @@ -28,7 +28,7 @@ function __AccessChecker_init(IGlobalParams globalParams) internal; ### _getGlobalParams -Returns the stored GLOBAL_PARAMS for internal use +*Returns the stored GLOBAL_PARAMS for internal use* ```solidity @@ -37,22 +37,22 @@ function _getGlobalParams() internal view returns (IGlobalParams); ### onlyProtocolAdmin -Modifier that restricts function access to protocol administrators only. -Users attempting to execute functions with this modifier must be the protocol admin. +*Modifier that restricts function access to protocol administrators only. +Users attempting to execute functions with this modifier must be the protocol admin.* ```solidity -modifier onlyProtocolAdmin() ; +modifier onlyProtocolAdmin(); ``` ### onlyPlatformAdmin -Modifier that restricts function access to platform administrators of a specific platform. -Users attempting to execute functions with this modifier must be the platform admin for the given platform. +*Modifier that restricts function access to platform administrators of a specific platform. +Users attempting to execute functions with this modifier must be the platform admin for the given platform.* ```solidity -modifier onlyPlatformAdmin(bytes32 platformHash) ; +modifier onlyPlatformAdmin(bytes32 platformHash); ``` **Parameters** @@ -63,8 +63,8 @@ modifier onlyPlatformAdmin(bytes32 platformHash) ; ### _onlyProtocolAdmin -Internal function to check if the sender is the protocol administrator. -If the sender is not the protocol admin, it reverts with AdminAccessCheckerUnauthorized error. +*Internal function to check if the sender is the protocol administrator. +If the sender is not the protocol admin, it reverts with AdminAccessCheckerUnauthorized error.* ```solidity @@ -73,8 +73,8 @@ function _onlyProtocolAdmin() private view; ### _onlyPlatformAdmin -Internal function to check if the sender is the platform administrator for a specific platform. -If the sender is not the platform admin, it reverts with AdminAccessCheckerUnauthorized error. +*Internal function to check if the sender is the platform administrator for a specific platform. +If the sender is not the platform admin, it reverts with AdminAccessCheckerUnauthorized error.* ```solidity @@ -89,7 +89,7 @@ function _onlyPlatformAdmin(bytes32 platformHash) private view; ## Errors ### AdminAccessCheckerUnauthorized -Throws when the caller is not authorized. +*Throws when the caller is not authorized.* ```solidity diff --git a/docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md b/docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md index 0e533596..254583b2 100644 --- a/docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md +++ b/docs/src/src/utils/BasePaymentTreasury.sol/abstract.BasePaymentTreasury.md @@ -1,155 +1,238 @@ # BasePaymentTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/utils/BasePaymentTreasury.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/utils/BasePaymentTreasury.sol) **Inherits:** -Initializable, [ICampaignPaymentTreasury](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md), [CampaignAccessChecker](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md), [PausableCancellable](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md), ReentrancyGuard +Initializable, [ICampaignPaymentTreasury](/src/interfaces/ICampaignPaymentTreasury.sol/interface.ICampaignPaymentTreasury.md), [CampaignAccessChecker](/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md), [PausableCancellable](/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md), ReentrancyGuard + +Base contract for payment treasury implementations. + +*Supports ERC-2771 meta-transactions via adapter contracts for platform admin operations.* ## State Variables ### ZERO_BYTES ```solidity -bytes32 internal constant ZERO_BYTES = 0x0000000000000000000000000000000000000000000000000000000000000000 +bytes32 internal constant ZERO_BYTES = 0x0000000000000000000000000000000000000000000000000000000000000000; ``` ### PERCENT_DIVIDER ```solidity -uint256 internal constant PERCENT_DIVIDER = 10000 +uint256 internal constant PERCENT_DIVIDER = 10000; ``` ### STANDARD_DECIMALS ```solidity -uint256 internal constant STANDARD_DECIMALS = 18 +uint256 internal constant STANDARD_DECIMALS = 18; +``` + + +### ZERO_ADDRESS + +```solidity +address internal constant ZERO_ADDRESS = address(0); ``` ### PLATFORM_HASH ```solidity -bytes32 internal PLATFORM_HASH +bytes32 internal PLATFORM_HASH; ``` ### PLATFORM_FEE_PERCENT ```solidity -uint256 internal PLATFORM_FEE_PERCENT +uint256 internal PLATFORM_FEE_PERCENT; ``` ### s_paymentIdToToken ```solidity -mapping(bytes32 => address) internal s_paymentIdToToken +mapping(bytes32 => address) internal s_paymentIdToToken; ``` ### s_platformFeePerToken ```solidity -mapping(address => uint256) internal s_platformFeePerToken +mapping(address => uint256) internal s_platformFeePerToken; ``` ### s_protocolFeePerToken ```solidity -mapping(address => uint256) internal s_protocolFeePerToken +mapping(address => uint256) internal s_protocolFeePerToken; ``` ### s_paymentIdToTokenId ```solidity -mapping(bytes32 => uint256) internal s_paymentIdToTokenId +mapping(bytes32 => uint256) internal s_paymentIdToTokenId; +``` + + +### s_paymentIdToCreator + +```solidity +mapping(bytes32 => address) internal s_paymentIdToCreator; ``` ### s_payment ```solidity -mapping(bytes32 => PaymentInfo) internal s_payment +mapping(bytes32 => PaymentInfo) internal s_payment; ``` ### s_paymentLineItems ```solidity -mapping(bytes32 => ICampaignPaymentTreasury.PaymentLineItem[]) internal s_paymentLineItems +mapping(bytes32 => ICampaignPaymentTreasury.PaymentLineItem[]) internal s_paymentLineItems; ``` ### s_paymentExternalFeeMetadata ```solidity -mapping(bytes32 => ICampaignPaymentTreasury.ExternalFees[]) internal s_paymentExternalFeeMetadata +mapping(bytes32 => ICampaignPaymentTreasury.ExternalFees[]) internal s_paymentExternalFeeMetadata; ``` ### s_pendingPaymentPerToken ```solidity -mapping(address => uint256) internal s_pendingPaymentPerToken +mapping(address => uint256) internal s_pendingPaymentPerToken; ``` ### s_confirmedPaymentPerToken ```solidity -mapping(address => uint256) internal s_confirmedPaymentPerToken +mapping(address => uint256) internal s_confirmedPaymentPerToken; ``` ### s_lifetimeConfirmedPaymentPerToken ```solidity -mapping(address => uint256) internal s_lifetimeConfirmedPaymentPerToken +mapping(address => uint256) internal s_lifetimeConfirmedPaymentPerToken; ``` ### s_availableConfirmedPerToken ```solidity -mapping(address => uint256) internal s_availableConfirmedPerToken +mapping(address => uint256) internal s_availableConfirmedPerToken; ``` ### s_nonGoalLineItemPendingPerToken ```solidity -mapping(address => uint256) internal s_nonGoalLineItemPendingPerToken +mapping(address => uint256) internal s_nonGoalLineItemPendingPerToken; ``` ### s_nonGoalLineItemConfirmedPerToken ```solidity -mapping(address => uint256) internal s_nonGoalLineItemConfirmedPerToken +mapping(address => uint256) internal s_nonGoalLineItemConfirmedPerToken; ``` ### s_nonGoalLineItemClaimablePerToken ```solidity -mapping(address => uint256) internal s_nonGoalLineItemClaimablePerToken +mapping(address => uint256) internal s_nonGoalLineItemClaimablePerToken; ``` ### s_refundableNonGoalLineItemPerToken ```solidity -mapping(address => uint256) internal s_refundableNonGoalLineItemPerToken +mapping(address => uint256) internal s_refundableNonGoalLineItemPerToken; ``` ## Functions +### _scopePaymentIdForOffChain + +*Scopes a payment ID for off-chain payments (createPayment/createPaymentBatch).* + + +```solidity +function _scopePaymentIdForOffChain(bytes32 paymentId) internal pure returns (bytes32); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The external payment ID.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes32`|The scoped internal payment ID.| + + +### _scopePaymentIdForOnChain + +*Scopes a payment ID for on-chain crypto payments (processCryptoPayment).* + + +```solidity +function _scopePaymentIdForOnChain(bytes32 paymentId) internal view returns (bytes32); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The external payment ID.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes32`|The scoped internal payment ID.| + + +### _findPaymentId + +*Tries to find a payment by checking both off-chain and on-chain scopes. +- Off-chain payments (createPayment) can be looked up by anyone (scoped with address(0)) +- On-chain payments (processCryptoPayment) can be looked up by anyone using the stored creator address* + + +```solidity +function _findPaymentId(bytes32 paymentId) internal view returns (bytes32 internalPaymentId); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`paymentId`|`bytes32`|The external payment ID.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`internalPaymentId`|`bytes32`|The scoped internal payment ID if found, or ZERO_BYTES if not found.| + + ### _getMaxExpirationDuration -Retrieves the max expiration duration configured for the current platform or globally. +*Retrieves the max expiration duration configured for the current platform or globally.* ```solidity @@ -167,23 +250,45 @@ function _getMaxExpirationDuration() internal view returns (bool hasLimit, uint2 ```solidity -function __BaseContract_init(bytes32 platformHash, address infoAddress) internal; +function __BaseContract_init(bytes32 platformHash, address infoAddress, address trustedForwarder_) internal; +``` + +### _msgSender + +*Override _msgSender to support ERC-2771 meta-transactions. +When called by the trusted forwarder (adapter), extracts the actual sender from calldata.* + + +```solidity +function _msgSender() internal view virtual override returns (address sender); ``` ### whenCampaignNotPaused -Modifier that checks if the campaign is not paused. +*Modifier that checks if the campaign is not paused.* ```solidity -modifier whenCampaignNotPaused() ; +modifier whenCampaignNotPaused(); ``` ### whenCampaignNotCancelled ```solidity -modifier whenCampaignNotCancelled() ; +modifier whenCampaignNotCancelled(); +``` + +### onlyPlatformAdminOrCampaignOwner + +*Restricts access to only the platform admin or the campaign owner.* + +*Checks if `_msgSender()` is either the platform admin (via `INFO.getPlatformAdminAddress`) +or the campaign owner (via `INFO.owner()`). Reverts with `AccessCheckerUnauthorized` if not authorized.* + + +```solidity +modifier onlyPlatformAdminOrCampaignOwner(); ``` ### getplatformHash @@ -280,7 +385,7 @@ function getRefundedAmount() external view returns (uint256); Retrieves the total expected (pending) amount in the treasury. -This represents payments that have been created but not yet confirmed. +*This represents payments that have been created but not yet confirmed.* ```solidity @@ -295,7 +400,7 @@ function getExpectedAmount() external view returns (uint256); ### _normalizeAmount -Normalizes token amounts to 18 decimals for consistent comparisons. +*Normalizes token amounts to 18 decimals for consistent comparisons.* ```solidity @@ -317,7 +422,7 @@ function _normalizeAmount(address token, uint256 amount) internal view returns ( ### _validateStoreAndTrackLineItems -Validates, stores, and tracks line items in a single loop for gas efficiency. +*Validates, stores, and tracks line items in a single loop for gas efficiency.* ```solidity @@ -402,7 +507,7 @@ function createPaymentBatch( Allows a buyer to make a direct crypto payment for an item. -This function transfers tokens directly from the buyer's wallet and confirms the payment immediately. +*This function transfers tokens directly from the buyer's wallet and confirms the payment immediately.* ```solidity @@ -452,7 +557,7 @@ function cancelPayment(bytes32 paymentId) ### _calculateLineItemTotals -Calculates line item totals for balance checking and state updates. +*Calculates line item totals for balance checking and state updates.* ```solidity @@ -477,7 +582,7 @@ function _calculateLineItemTotals( ### _checkBalanceForConfirmation -Checks if there's sufficient balance for payment confirmation. +*Checks if there's sufficient balance for payment confirmation.* ```solidity @@ -496,7 +601,7 @@ function _checkBalanceForConfirmation(address paymentToken, uint256 paymentAmoun ### _updateLineItemsForConfirmation -Updates state for line items during payment confirmation. +*Updates state for line items during payment confirmation.* ```solidity @@ -571,7 +676,7 @@ function confirmPaymentBatch(bytes32[] calldata paymentIds, address[] calldata b Claims a refund for non-NFT payments (payments without minted NFTs). -For non-NFT payments only. Verifies that no NFT exists for this payment. +*For non-NFT payments only. Verifies that no NFT exists for this payment.* ```solidity @@ -595,7 +700,7 @@ function claimRefund(bytes32 paymentId, address refundAddress) Claims a refund for non-NFT payments (payments without minted NFTs). -For NFT payments only. Requires an NFT exists and burns it. Refund is sent to current NFT owner. +*For NFT payments only. Requires an NFT exists and burns it. Refund is sent to current NFT owner.* ```solidity @@ -614,7 +719,7 @@ Disburses fees collected by the treasury. ```solidity -function disburseFees() public virtual override whenCampaignNotPaused whenCampaignNotCancelled; +function disburseFees() public virtual override whenCampaignNotPaused; ``` ### claimNonGoalLineItems @@ -623,12 +728,7 @@ Allows platform admin to claim non-goal line items that are available for claimi ```solidity -function claimNonGoalLineItems(address token) - public - virtual - onlyPlatformAdmin(PLATFORM_HASH) - whenCampaignNotPaused - whenCampaignNotCancelled; +function claimNonGoalLineItems(address token) public virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused; ``` **Parameters** @@ -643,12 +743,7 @@ Allows the platform admin to claim all remaining funds once the claim window has ```solidity -function claimExpiredFunds() - public - virtual - onlyPlatformAdmin(PLATFORM_HASH) - whenCampaignNotPaused - whenCampaignNotCancelled; +function claimExpiredFunds() public virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused; ``` ### withdraw @@ -657,12 +752,18 @@ Withdraws funds from the treasury. ```solidity -function withdraw() public virtual override whenCampaignNotPaused whenCampaignNotCancelled; +function withdraw() + public + virtual + override + onlyPlatformAdminOrCampaignOwner + whenCampaignNotPaused + whenCampaignNotCancelled; ``` ### pauseTreasury -External function to pause the campaign. +*External function to pause the campaign.* ```solidity @@ -671,7 +772,7 @@ function pauseTreasury(bytes32 message) public virtual onlyPlatformAdmin(PLATFOR ### unpauseTreasury -External function to unpause the campaign. +*External function to unpause the campaign.* ```solidity @@ -680,7 +781,7 @@ function unpauseTreasury(bytes32 message) public virtual onlyPlatformAdmin(PLATF ### cancelTreasury -External function to cancel the campaign. +*External function to cancel the campaign.* ```solidity @@ -704,8 +805,8 @@ function cancelled() public view virtual override(ICampaignPaymentTreasury, Paus ### _revertIfCampaignPaused -Internal function to check if the campaign is paused. -If the campaign is paused, it reverts with PaymentTreasuryCampaignInfoIsPaused error. +*Internal function to check if the campaign is paused. +If the campaign is paused, it reverts with PaymentTreasuryCampaignInfoIsPaused error.* ```solidity @@ -721,12 +822,12 @@ function _revertIfCampaignCancelled() internal view; ### _validatePaymentForAction -Validates the given payment ID to ensure it is eligible for further action. +*Validates the given payment ID to ensure it is eligible for further action. Reverts if: - The payment does not exist. - The payment has already been confirmed. - The payment has already expired. -- The payment is a crypto payment +- The payment is a crypto payment* ```solidity @@ -743,13 +844,13 @@ function _validatePaymentForAction(bytes32 paymentId) internal view; Retrieves comprehensive payment data including payment info, token, line items, and external fees. +*This function can look up payments created by anyone: +- Off-chain payments (created via createPayment): Scoped with address(0), anyone can look these up +- On-chain payments (created via processCryptoPayment): Uses stored creator address, anyone can look these up* + ```solidity -function getPaymentData(bytes32 paymentId) - public - view - override - returns (ICampaignPaymentTreasury.PaymentData memory); +function getPaymentData(bytes32 paymentId) public view override returns (ICampaignPaymentTreasury.PaymentData memory); ``` **Parameters** @@ -766,7 +867,7 @@ function getPaymentData(bytes32 paymentId) ### _checkSuccessCondition -Internal function to check the success condition for fee disbursement. +*Internal function to check the success condition for fee disbursement.* ```solidity @@ -781,7 +882,7 @@ function _checkSuccessCondition() internal view virtual returns (bool); ## Events ### PaymentCreated -Emitted when a new payment is created. +*Emitted when a new payment is created.* ```solidity @@ -811,7 +912,7 @@ event PaymentCreated( |`isCryptoPayment`|`bool`|Boolean indicating whether the payment is made using direct crypto payment.| ### PaymentCancelled -Emitted when a payment is cancelled and removed from the treasury. +*Emitted when a payment is cancelled and removed from the treasury.* ```solidity @@ -825,7 +926,7 @@ event PaymentCancelled(bytes32 indexed paymentId); |`paymentId`|`bytes32`|The unique identifier of the cancelled payment.| ### PaymentConfirmed -Emitted when a payment is confirmed. +*Emitted when a payment is confirmed.* ```solidity @@ -839,7 +940,7 @@ event PaymentConfirmed(bytes32 indexed paymentId); |`paymentId`|`bytes32`|The unique identifier of the confirmed payment.| ### PaymentBatchConfirmed -Emitted when multiple payments are confirmed in a single batch operation. +*Emitted when multiple payments are confirmed in a single batch operation.* ```solidity @@ -853,7 +954,7 @@ event PaymentBatchConfirmed(bytes32[] paymentIds); |`paymentIds`|`bytes32[]`|An array of unique identifiers for the confirmed payments.| ### PaymentBatchCreated -Emitted when multiple payments are created in a single batch operation. +*Emitted when multiple payments are created in a single batch operation.* ```solidity @@ -883,7 +984,7 @@ event FeesDisbursed(address indexed token, uint256 protocolShare, uint256 platfo |`platformShare`|`uint256`|The amount of fees sent to the platform.| ### WithdrawalWithFeeSuccessful -Emitted when a withdrawal is successfully processed along with the applied fee. +*Emitted when a withdrawal is successfully processed along with the applied fee.* ```solidity @@ -900,7 +1001,7 @@ event WithdrawalWithFeeSuccessful(address indexed token, address indexed to, uin |`fee`|`uint256`|The fee amount deducted from the withdrawal.| ### RefundClaimed -Emitted when a refund is claimed. +*Emitted when a refund is claimed.* ```solidity @@ -916,7 +1017,7 @@ event RefundClaimed(bytes32 indexed paymentId, uint256 refundAmount, address ind |`claimer`|`address`|The address of the claimer.| ### NonGoalLineItemsClaimed -Emitted when non-goal line items are claimed by the platform admin. +*Emitted when non-goal line items are claimed by the platform admin.* ```solidity @@ -932,7 +1033,7 @@ event NonGoalLineItemsClaimed(address indexed token, uint256 amount, address ind |`platformAdmin`|`address`|The address of the platform admin who claimed.| ### ExpiredFundsClaimed -Emitted when expired funds are claimed by the platform and protocol admins. +*Emitted when expired funds are claimed by the platform and protocol admins.* ```solidity @@ -949,7 +1050,7 @@ event ExpiredFundsClaimed(address indexed token, uint256 platformAmount, uint256 ## Errors ### PaymentTreasuryInvalidInput -Reverts when one or more provided inputs to the payment treasury are invalid. +*Reverts when one or more provided inputs to the payment treasury are invalid.* ```solidity @@ -957,7 +1058,7 @@ error PaymentTreasuryInvalidInput(); ``` ### PaymentTreasuryPaymentAlreadyExist -Throws an error indicating that the payment id already exists. +*Throws an error indicating that the payment id already exists.* ```solidity @@ -965,7 +1066,7 @@ error PaymentTreasuryPaymentAlreadyExist(bytes32 paymentId); ``` ### PaymentTreasuryPaymentAlreadyConfirmed -Throws an error indicating that the payment id is already confirmed. +*Throws an error indicating that the payment id is already confirmed.* ```solidity @@ -973,7 +1074,7 @@ error PaymentTreasuryPaymentAlreadyConfirmed(bytes32 paymentId); ``` ### PaymentTreasuryPaymentAlreadyExpired -Throws an error indicating that the payment id is already expired. +*Throws an error indicating that the payment id is already expired.* ```solidity @@ -981,7 +1082,7 @@ error PaymentTreasuryPaymentAlreadyExpired(bytes32 paymentId); ``` ### PaymentTreasuryPaymentNotExist -Throws an error indicating that the payment id does not exist. +*Throws an error indicating that the payment id does not exist.* ```solidity @@ -989,7 +1090,7 @@ error PaymentTreasuryPaymentNotExist(bytes32 paymentId); ``` ### PaymentTreasuryCampaignInfoIsPaused -Throws an error indicating that the campaign is paused. +*Throws an error indicating that the campaign is paused.* ```solidity @@ -997,7 +1098,7 @@ error PaymentTreasuryCampaignInfoIsPaused(); ``` ### PaymentTreasuryTokenNotAccepted -Emitted when a token is not accepted for the campaign. +*Emitted when a token is not accepted for the campaign.* ```solidity @@ -1005,7 +1106,7 @@ error PaymentTreasuryTokenNotAccepted(address token); ``` ### PaymentTreasurySuccessConditionNotFulfilled -Throws an error indicating that the success condition was not fulfilled. +*Throws an error indicating that the success condition was not fulfilled.* ```solidity @@ -1013,7 +1114,7 @@ error PaymentTreasurySuccessConditionNotFulfilled(); ``` ### PaymentTreasuryFeeNotDisbursed -Throws an error indicating that fees have not been disbursed. +*Throws an error indicating that fees have not been disbursed.* ```solidity @@ -1021,7 +1122,7 @@ error PaymentTreasuryFeeNotDisbursed(); ``` ### PaymentTreasuryPaymentNotConfirmed -Throws an error indicating that the payment id is not confirmed. +*Throws an error indicating that the payment id is not confirmed.* ```solidity @@ -1029,7 +1130,7 @@ error PaymentTreasuryPaymentNotConfirmed(bytes32 paymentId); ``` ### PaymentTreasuryPaymentNotClaimable -Emitted when claiming an unclaimable refund. +*Emitted when claiming an unclaimable refund.* ```solidity @@ -1043,7 +1144,7 @@ error PaymentTreasuryPaymentNotClaimable(bytes32 paymentId); |`paymentId`|`bytes32`|The unique identifier of the refundable payment.| ### PaymentTreasuryAlreadyWithdrawn -Emitted when an attempt is made to withdraw funds from the treasury but the payment has already been withdrawn. +*Emitted when an attempt is made to withdraw funds from the treasury but the payment has already been withdrawn.* ```solidity @@ -1051,7 +1152,7 @@ error PaymentTreasuryAlreadyWithdrawn(); ``` ### PaymentTreasuryCryptoPayment -This error is thrown when an operation is attempted on a crypto payment that is only valid for non-crypto payments. +*This error is thrown when an operation is attempted on a crypto payment that is only valid for non-crypto payments.* ```solidity @@ -1080,7 +1181,7 @@ error PaymentTreasuryInsufficientFundsForFee(uint256 withdrawalAmount, uint256 f |`fee`|`uint256`|The calculated fee, which is greater than the withdrawal amount.| ### PaymentTreasuryInsufficientBalance -Emitted when there are insufficient unallocated tokens for a payment confirmation. +*Emitted when there are insufficient unallocated tokens for a payment confirmation.* ```solidity @@ -1088,7 +1189,7 @@ error PaymentTreasuryInsufficientBalance(uint256 required, uint256 available); ``` ### PaymentTreasuryExpirationExceedsMax -Throws an error indicating that the payment expiration exceeds the maximum allowed expiration time. +*Throws an error indicating that the payment expiration exceeds the maximum allowed expiration time.* ```solidity @@ -1103,7 +1204,7 @@ error PaymentTreasuryExpirationExceedsMax(uint256 expiration, uint256 maxExpirat |`maxExpiration`|`uint256`|The maximum allowed expiration timestamp.| ### PaymentTreasuryClaimWindowNotReached -Throws when attempting to claim expired funds before the claim window opens. +*Throws when attempting to claim expired funds before the claim window opens.* ```solidity @@ -1117,7 +1218,7 @@ error PaymentTreasuryClaimWindowNotReached(uint256 claimableAt); |`claimableAt`|`uint256`|The timestamp when the claim window opens.| ### PaymentTreasuryNoFundsToClaim -Throws when there are no funds available to claim. +*Throws when there are no funds available to claim.* ```solidity @@ -1126,7 +1227,7 @@ error PaymentTreasuryNoFundsToClaim(); ## Structs ### PaymentInfo -Stores information about a payment in the treasury. +*Stores information about a payment in the treasury.* ```solidity @@ -1156,7 +1257,7 @@ struct PaymentInfo { |`lineItemCount`|`uint256`|The number of line items associated with this payment.| ### LineItemTotals -Struct to hold line item calculation totals to reduce stack depth. +*Struct to hold line item calculation totals to reduce stack depth.* ```solidity diff --git a/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md b/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md index ed924313..4770229b 100644 --- a/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md +++ b/docs/src/src/utils/BaseTreasury.sol/abstract.BaseTreasury.md @@ -1,70 +1,72 @@ # BaseTreasury -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/utils/BaseTreasury.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/utils/BaseTreasury.sol) **Inherits:** -Initializable, [ICampaignTreasury](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md), [CampaignAccessChecker](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md), [PausableCancellable](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md) +Initializable, [ICampaignTreasury](/src/interfaces/ICampaignTreasury.sol/interface.ICampaignTreasury.md), [CampaignAccessChecker](/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md), [PausableCancellable](/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md) A base contract for creating and managing treasuries in crowdfunding campaigns. -This contract defines common functionality and storage for campaign treasuries. +*This contract defines common functionality and storage for campaign treasuries.* -Contracts implementing this base contract should provide specific success conditions. +*Supports ERC-2771 meta-transactions via adapter contracts for platform admin operations.* + +*Contracts implementing this base contract should provide specific success conditions.* ## State Variables ### ZERO_BYTES ```solidity -bytes32 internal constant ZERO_BYTES = 0x0000000000000000000000000000000000000000000000000000000000000000 +bytes32 internal constant ZERO_BYTES = 0x0000000000000000000000000000000000000000000000000000000000000000; ``` ### PERCENT_DIVIDER ```solidity -uint256 internal constant PERCENT_DIVIDER = 10000 +uint256 internal constant PERCENT_DIVIDER = 10000; ``` ### STANDARD_DECIMALS ```solidity -uint256 internal constant STANDARD_DECIMALS = 18 +uint256 internal constant STANDARD_DECIMALS = 18; ``` ### PLATFORM_HASH ```solidity -bytes32 internal PLATFORM_HASH +bytes32 internal PLATFORM_HASH; ``` ### PLATFORM_FEE_PERCENT ```solidity -uint256 internal PLATFORM_FEE_PERCENT +uint256 internal PLATFORM_FEE_PERCENT; ``` ### s_feesDisbursed ```solidity -bool internal s_feesDisbursed +bool internal s_feesDisbursed; ``` ### s_tokenRaisedAmounts ```solidity -mapping(address => uint256) internal s_tokenRaisedAmounts +mapping(address => uint256) internal s_tokenRaisedAmounts; ``` ### s_tokenLifetimeRaisedAmounts ```solidity -mapping(address => uint256) internal s_tokenLifetimeRaisedAmounts +mapping(address => uint256) internal s_tokenLifetimeRaisedAmounts; ``` @@ -73,23 +75,33 @@ mapping(address => uint256) internal s_tokenLifetimeRaisedAmounts ```solidity -function __BaseContract_init(bytes32 platformHash, address infoAddress) internal; +function __BaseContract_init(bytes32 platformHash, address infoAddress, address trustedForwarder_) internal; +``` + +### _msgSender + +*Override _msgSender to support ERC-2771 meta-transactions. +When called by the trusted forwarder (adapter), extracts the actual sender from calldata.* + + +```solidity +function _msgSender() internal view virtual override returns (address sender); ``` ### whenCampaignNotPaused -Modifier that checks if the campaign is not paused. +*Modifier that checks if the campaign is not paused.* ```solidity -modifier whenCampaignNotPaused() ; +modifier whenCampaignNotPaused(); ``` ### whenCampaignNotCancelled ```solidity -modifier whenCampaignNotCancelled() ; +modifier whenCampaignNotCancelled(); ``` ### getplatformHash @@ -124,7 +136,7 @@ function getplatformFeePercent() external view override returns (uint256); ### _normalizeAmount -Normalizes token amount to 18 decimals for consistent comparison. +*Normalizes token amount to 18 decimals for consistent comparison.* ```solidity @@ -146,7 +158,7 @@ function _normalizeAmount(address token, uint256 amount) internal view returns ( ### _denormalizeAmount -Denormalizes an amount from 18 decimals to the token's actual decimals. +*Denormalizes an amount from 18 decimals to the token's actual decimals.* ```solidity @@ -186,7 +198,7 @@ function withdraw() public virtual override whenCampaignNotPaused whenCampaignNo ### pauseTreasury -External function to pause the campaign. +*External function to pause the campaign.* ```solidity @@ -195,7 +207,7 @@ function pauseTreasury(bytes32 message) public virtual onlyPlatformAdmin(PLATFOR ### unpauseTreasury -External function to unpause the campaign. +*External function to unpause the campaign.* ```solidity @@ -204,7 +216,7 @@ function unpauseTreasury(bytes32 message) public virtual onlyPlatformAdmin(PLATF ### cancelTreasury -External function to cancel the campaign. +*External function to cancel the campaign.* ```solidity @@ -228,8 +240,8 @@ function cancelled() public view virtual override(ICampaignTreasury, PausableCan ### _revertIfCampaignPaused -Internal function to check if the campaign is paused. -If the campaign is paused, it reverts with TreasuryCampaignInfoIsPaused error. +*Internal function to check if the campaign is paused. +If the campaign is paused, it reverts with TreasuryCampaignInfoIsPaused error.* ```solidity @@ -245,7 +257,7 @@ function _revertIfCampaignCancelled() internal view; ### _checkSuccessCondition -Internal function to check the success condition for fee disbursement. +*Internal function to check the success condition for fee disbursement.* ```solidity @@ -301,7 +313,7 @@ event SuccessConditionNotFulfilled(); ## Errors ### TreasuryTransferFailed -Throws an error indicating a failed treasury transfer. +*Throws an error indicating a failed treasury transfer.* ```solidity @@ -309,7 +321,7 @@ error TreasuryTransferFailed(); ``` ### TreasurySuccessConditionNotFulfilled -Throws an error indicating that the success condition was not fulfilled. +*Throws an error indicating that the success condition was not fulfilled.* ```solidity @@ -317,7 +329,7 @@ error TreasurySuccessConditionNotFulfilled(); ``` ### TreasuryFeeNotDisbursed -Throws an error indicating that fees have not been disbursed. +*Throws an error indicating that fees have not been disbursed.* ```solidity @@ -325,7 +337,7 @@ error TreasuryFeeNotDisbursed(); ``` ### TreasuryCampaignInfoIsPaused -Throws an error indicating that the campaign is paused. +*Throws an error indicating that the campaign is paused.* ```solidity diff --git a/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md b/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md index 4fed8a0a..6445be01 100644 --- a/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md +++ b/docs/src/src/utils/CampaignAccessChecker.sol/abstract.CampaignAccessChecker.md @@ -1,25 +1,34 @@ # CampaignAccessChecker -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/utils/CampaignAccessChecker.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/utils/CampaignAccessChecker.sol) **Inherits:** Context -This abstract contract provides access control mechanisms to restrict the execution of specific functions -to authorized protocol administrators, platform administrators, and campaign owners. +*This abstract contract provides access control mechanisms to restrict the execution of specific functions +to authorized protocol administrators, platform administrators, and campaign owners.* ## State Variables ### INFO ```solidity -ICampaignInfo internal INFO +ICampaignInfo internal INFO; +``` + + +### _trustedForwarder +*Trusted forwarder address for ERC-2771 meta-transactions (set by derived contracts)* + + +```solidity +address internal _trustedForwarder; ``` ## Functions ### __CampaignAccessChecker_init -Constructor to initialize the contract with the address of the campaign information contract. +*Constructor to initialize the contract with the address of the campaign information contract.* ```solidity @@ -34,22 +43,22 @@ function __CampaignAccessChecker_init(address campaignInfo) internal; ### onlyProtocolAdmin -Modifier that restricts function access to protocol administrators only. -Users attempting to execute functions with this modifier must be the protocol admin. +*Modifier that restricts function access to protocol administrators only. +Users attempting to execute functions with this modifier must be the protocol admin.* ```solidity -modifier onlyProtocolAdmin() ; +modifier onlyProtocolAdmin(); ``` ### onlyPlatformAdmin -Modifier that restricts function access to platform administrators of a specific platform. -Users attempting to execute functions with this modifier must be the platform admin for the given platform. +*Modifier that restricts function access to platform administrators of a specific platform. +Users attempting to execute functions with this modifier must be the platform admin for the given platform.* ```solidity -modifier onlyPlatformAdmin(bytes32 platformHash) ; +modifier onlyPlatformAdmin(bytes32 platformHash); ``` **Parameters** @@ -60,18 +69,18 @@ modifier onlyPlatformAdmin(bytes32 platformHash) ; ### onlyCampaignOwner -Modifier that restricts function access to the owner of the campaign. -Users attempting to execute functions with this modifier must be the owner of the campaign. +*Modifier that restricts function access to the owner of the campaign. +Users attempting to execute functions with this modifier must be the owner of the campaign.* ```solidity -modifier onlyCampaignOwner() ; +modifier onlyCampaignOwner(); ``` ### _onlyProtocolAdmin -Internal function to check if the sender is the protocol administrator. -If the sender is not the protocol admin, it reverts with AccessCheckerUnauthorized error. +*Internal function to check if the sender is the protocol administrator. +If the sender is not the protocol admin, it reverts with AccessCheckerUnauthorized error.* ```solidity @@ -80,8 +89,8 @@ function _onlyProtocolAdmin() private view; ### _onlyPlatformAdmin -Internal function to check if the sender is the platform administrator for a specific platform. -If the sender is not the platform admin, it reverts with AccessCheckerUnauthorized error. +*Internal function to check if the sender is the platform administrator for a specific platform. +If the sender is not the platform admin, it reverts with AccessCheckerUnauthorized error.* ```solidity @@ -96,8 +105,8 @@ function _onlyPlatformAdmin(bytes32 platformHash) private view; ### _onlyCampaignOwner -Internal function to check if the sender is the owner of the campaign. -If the sender is not the owner, it reverts with AccessCheckerUnauthorized error. +*Internal function to check if the sender is the owner of the campaign. +If the sender is not the owner, it reverts with AccessCheckerUnauthorized error.* ```solidity @@ -106,7 +115,7 @@ function _onlyCampaignOwner() private view; ## Errors ### AccessCheckerUnauthorized -Throws when the caller is not authorized. +*Throws when the caller is not authorized.* ```solidity diff --git a/docs/src/src/utils/Counters.sol/library.Counters.md b/docs/src/src/utils/Counters.sol/library.Counters.md index d907ccf6..95d9a13c 100644 --- a/docs/src/src/utils/Counters.sol/library.Counters.md +++ b/docs/src/src/utils/Counters.sol/library.Counters.md @@ -1,5 +1,5 @@ # Counters -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/utils/Counters.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/utils/Counters.sol) ## Functions @@ -33,7 +33,7 @@ function reset(Counter storage counter) internal; ## Errors ### CounterDecrementOverflow -Error thrown when attempting to decrement a counter with value 0. +*Error thrown when attempting to decrement a counter with value 0.* ```solidity @@ -45,10 +45,7 @@ error CounterDecrementOverflow(); ```solidity struct Counter { - // This variable should never be directly accessed by users of the library: interactions must be restricted to - // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add - // this feature: see https://github.com/ethereum/solidity/issues/4637 - uint256 _value; // default: 0 + uint256 _value; } ``` diff --git a/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md b/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md index 0ae6098b..0df1f0d6 100644 --- a/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md +++ b/docs/src/src/utils/FiatEnabled.sol/abstract.FiatEnabled.md @@ -1,5 +1,5 @@ # FiatEnabled -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/utils/FiatEnabled.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/utils/FiatEnabled.sol) A contract that provides functionality for tracking and managing fiat transactions. This contract allows tracking the amount of fiat raised, individual fiat transactions, and the state of fiat fee disbursement. @@ -9,21 +9,21 @@ This contract allows tracking the amount of fiat raised, individual fiat transac ### s_fiatRaisedAmount ```solidity -uint256 internal s_fiatRaisedAmount +uint256 internal s_fiatRaisedAmount; ``` ### s_fiatFeeIsDisbursed ```solidity -bool internal s_fiatFeeIsDisbursed +bool internal s_fiatFeeIsDisbursed; ``` ### s_fiatAmountById ```solidity -mapping(bytes32 => uint256) internal s_fiatAmountById +mapping(bytes32 => uint256) internal s_fiatAmountById; ``` @@ -97,7 +97,7 @@ function _updateFiatTransaction(bytes32 fiatTransactionId, uint256 fiatTransacti ### _updateFiatFeeDisbursementState -Update the state of fiat fee disbursement. +*Update the state of fiat fee disbursement.* ```solidity @@ -147,7 +147,7 @@ event FiatFeeDisbusementStateUpdated(bool isDisbursed, uint256 protocolFeeAmount ## Errors ### FiatEnabledAlreadySet -Throws an error indicating that the fiat enabled functionality is already set. +*Throws an error indicating that the fiat enabled functionality is already set.* ```solidity @@ -155,7 +155,7 @@ error FiatEnabledAlreadySet(); ``` ### FiatEnabledDisallowedState -Throws an error indicating that the fiat enabled functionality is in an invalid state. +*Throws an error indicating that the fiat enabled functionality is in an invalid state.* ```solidity @@ -163,7 +163,7 @@ error FiatEnabledDisallowedState(); ``` ### FiatEnabledInvalidTransaction -Throws an error indicating that the fiat transaction is invalid. +*Throws an error indicating that the fiat transaction is invalid.* ```solidity diff --git a/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md b/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md index 3901ed4d..03353ec4 100644 --- a/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md +++ b/docs/src/src/utils/ItemRegistry.sol/contract.ItemRegistry.md @@ -1,17 +1,17 @@ # ItemRegistry -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/utils/ItemRegistry.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/utils/ItemRegistry.sol) **Inherits:** -[IItem](/Users/mahabubalahi/Documents/ccp/ccprotocol-contracts-internal/docs/src/src/interfaces/IItem.sol/interface.IItem.md), Context +[IItem](/src/interfaces/IItem.sol/interface.IItem.md), Context -A contract that manages the registration and retrieval of items. +*A contract that manages the registration and retrieval of items.* ## State Variables ### Items ```solidity -mapping(address => mapping(bytes32 => Item)) private Items +mapping(address => mapping(bytes32 => Item)) private Items; ``` @@ -72,7 +72,7 @@ function addItemsBatch(bytes32[] calldata itemIds, Item[] calldata items) extern ## Events ### ItemAdded -Emitted when a new item is added to the registry. +*Emitted when a new item is added to the registry.* ```solidity @@ -89,7 +89,7 @@ event ItemAdded(address indexed owner, bytes32 indexed itemId, Item item); ## Errors ### ItemRegistryMismatchedArraysLength -Thrown when the input arrays have mismatched lengths. +*Thrown when the input arrays have mismatched lengths.* ```solidity diff --git a/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md b/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md index f672b4ac..b50fdf5f 100644 --- a/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md +++ b/docs/src/src/utils/PausableCancellable.sol/abstract.PausableCancellable.md @@ -1,5 +1,5 @@ # PausableCancellable -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/utils/PausableCancellable.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/utils/PausableCancellable.sol) **Inherits:** Context @@ -11,14 +11,14 @@ Abstract contract providing pause and cancel state management with events and mo ### _paused ```solidity -bool private _paused +bool private _paused; ``` ### _cancelled ```solidity -bool private _cancelled +bool private _cancelled; ``` @@ -29,7 +29,7 @@ Modifier to allow function only when not paused ```solidity -modifier whenNotPaused() ; +modifier whenNotPaused(); ``` ### whenPaused @@ -38,7 +38,7 @@ Modifier to allow function only when paused ```solidity -modifier whenPaused() ; +modifier whenPaused(); ``` ### whenNotCancelled @@ -47,7 +47,7 @@ Modifier to allow function only when not cancelled ```solidity -modifier whenNotCancelled() ; +modifier whenNotCancelled(); ``` ### whenCancelled @@ -56,7 +56,7 @@ Modifier to allow function only when cancelled ```solidity -modifier whenCancelled() ; +modifier whenCancelled(); ``` ### paused @@ -81,7 +81,7 @@ function cancelled() public view virtual returns (bool); Pauses the contract -Can only pause if not already paused or cancelled +*Can only pause if not already paused or cancelled* ```solidity @@ -98,7 +98,7 @@ function _pause(bytes32 reason) internal virtual whenNotPaused whenNotCancelled; Unpauses the contract -Can only unpause if currently paused +*Can only unpause if currently paused* ```solidity @@ -115,7 +115,7 @@ function _unpause(bytes32 reason) internal virtual whenPaused; Cancels the contract permanently -Auto-unpauses if paused, and cannot be undone +*Auto-unpauses if paused, and cannot be undone* ```solidity @@ -155,7 +155,7 @@ event Cancelled(address indexed account, bytes32 reason); ## Errors ### PausedError -Reverts if contract is paused +*Reverts if contract is paused* ```solidity @@ -163,7 +163,7 @@ error PausedError(); ``` ### NotPausedError -Reverts if contract is not paused +*Reverts if contract is not paused* ```solidity @@ -171,7 +171,7 @@ error NotPausedError(); ``` ### CancelledError -Reverts if contract is cancelled +*Reverts if contract is cancelled* ```solidity @@ -179,7 +179,7 @@ error CancelledError(); ``` ### NotCancelledError -Reverts if contract is not cancelled +*Reverts if contract is not cancelled* ```solidity @@ -187,7 +187,7 @@ error NotCancelledError(); ``` ### CannotCancel -Reverts if contract is already cancelled +*Reverts if contract is already cancelled* ```solidity diff --git a/docs/src/src/utils/PledgeNFT.sol/abstract.PledgeNFT.md b/docs/src/src/utils/PledgeNFT.sol/abstract.PledgeNFT.md index ae3bf19d..5cdf97ec 100644 --- a/docs/src/src/utils/PledgeNFT.sol/abstract.PledgeNFT.md +++ b/docs/src/src/utils/PledgeNFT.sol/abstract.PledgeNFT.md @@ -1,61 +1,61 @@ # PledgeNFT -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/utils/PledgeNFT.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/utils/PledgeNFT.sol) **Inherits:** ERC721Burnable, AccessControl Abstract contract for NFTs representing pledges with on-chain metadata -Contains counter logic and NFT metadata storage +*Contains counter logic and NFT metadata storage* ## State Variables ### MINTER_ROLE ```solidity -bytes32 public constant MINTER_ROLE = 0x9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6 +bytes32 public constant MINTER_ROLE = 0x9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6; ``` ### s_nftName ```solidity -string internal s_nftName +string internal s_nftName; ``` ### s_nftSymbol ```solidity -string internal s_nftSymbol +string internal s_nftSymbol; ``` ### s_imageURI ```solidity -string internal s_imageURI +string internal s_imageURI; ``` ### s_contractURI ```solidity -string internal s_contractURI +string internal s_contractURI; ``` ### s_tokenIdCounter ```solidity -Counters.Counter internal s_tokenIdCounter +Counters.Counter internal s_tokenIdCounter; ``` ### s_pledgeData ```solidity -mapping(uint256 => PledgeData) internal s_pledgeData +mapping(uint256 => PledgeData) internal s_pledgeData; ``` @@ -64,7 +64,7 @@ mapping(uint256 => PledgeData) internal s_pledgeData Initialize NFT metadata -Called by CampaignInfo during initialization +*Called by CampaignInfo during initialization* ```solidity @@ -85,11 +85,28 @@ function _initializeNFT( |`_contractURI`|`string`|IPFS URI for contract-level metadata| +### _validateJsonString + +Validates that a string is safe for JSON embedding + +*Reverts if string contains quotes, backslashes, or control characters* + + +```solidity +function _validateJsonString(string calldata str) internal pure; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`str`|`string`|The string to validate| + + ### mintNFTForPledge Mints a pledge NFT (auto-increments counter) -Called by treasuries - returns the new token ID to use as pledge ID +*Called by treasuries - returns the new token ID to use as pledge ID* ```solidity @@ -169,7 +186,7 @@ function symbol() public view virtual override returns (string memory); Sets the image URI for all NFTs -Must be overridden by inheriting contracts to implement access control +*Must be overridden by inheriting contracts to implement access control* ```solidity @@ -201,7 +218,7 @@ function contractURI() external view virtual returns (string memory); Update contract-level metadata URI -Must be overridden by inheriting contracts to implement access control +*Must be overridden by inheriting contracts to implement access control* ```solidity @@ -290,7 +307,7 @@ function getPledgeData(uint256 tokenId) external view returns (PledgeData memory Override supportsInterface for multiple inheritance -Internal function to set pledge data for a token +*Internal function to set pledge data for a token* ```solidity @@ -311,7 +328,7 @@ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC7 ## Events ### ImageURIUpdated -Emitted when the image URI is updated +*Emitted when the image URI is updated* ```solidity @@ -325,7 +342,7 @@ event ImageURIUpdated(string newImageURI); |`newImageURI`|`string`|The new image URI| ### ContractURIUpdated -Emitted when the contract URI is updated +*Emitted when the contract URI is updated* ```solidity @@ -339,7 +356,7 @@ event ContractURIUpdated(string newContractURI); |`newContractURI`|`string`|The new contract URI| ### PledgeNFTMinted -Emitted when a pledge NFT is minted +*Emitted when a pledge NFT is minted* ```solidity @@ -357,16 +374,24 @@ event PledgeNFTMinted(uint256 indexed tokenId, address indexed backer, address i ## Errors ### PledgeNFTUnAuthorized -Emitted when unauthorized access is attempted +*Emitted when unauthorized access is attempted* ```solidity error PledgeNFTUnAuthorized(); ``` +### PledgeNFTInvalidJsonString +*Emitted when a string contains invalid characters for JSON* + + +```solidity +error PledgeNFTInvalidJsonString(); +``` + ## Structs ### PledgeData -Struct to store pledge data for each token +*Struct to store pledge data for each token* ```solidity diff --git a/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md b/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md index 2fc29743..5da0ebc5 100644 --- a/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md +++ b/docs/src/src/utils/TimestampChecker.sol/abstract.TimestampChecker.md @@ -1,5 +1,5 @@ # TimestampChecker -[Git Source](https://github.com/ccprotocol/ccprotocol-contracts-internal/blob/e5024d64e3fbbb8a9ba5520b2280c0e3ebc75174/src/utils/TimestampChecker.sol) +[Git Source](https://github.com/oak-network/ccprotocol-contracts-internal/blob/be3636c015d0f78c20f6d8f0de7b678aaf6d8428/src/utils/TimestampChecker.sol) A contract that provides timestamp-related checks for contract functions. @@ -11,7 +11,7 @@ Modifier that checks if the current timestamp is greater than a specified time. ```solidity -modifier currentTimeIsGreater(uint256 inputTime) ; +modifier currentTimeIsGreater(uint256 inputTime); ``` **Parameters** @@ -26,7 +26,7 @@ Modifier that checks if the current timestamp is less than a specified time. ```solidity -modifier currentTimeIsLess(uint256 inputTime) ; +modifier currentTimeIsLess(uint256 inputTime); ``` **Parameters** @@ -41,7 +41,7 @@ Modifier that checks if the current timestamp is within a specified time range. ```solidity -modifier currentTimeIsWithinRange(uint256 initialTime, uint256 finalTime) ; +modifier currentTimeIsWithinRange(uint256 initialTime, uint256 finalTime); ``` **Parameters** @@ -53,7 +53,7 @@ modifier currentTimeIsWithinRange(uint256 initialTime, uint256 finalTime) ; ### _revertIfCurrentTimeIsNotLess -Internal function to revert if the current timestamp is less than or equal a specified time. +*Internal function to revert if the current timestamp is less than or equal a specified time.* ```solidity @@ -68,7 +68,7 @@ function _revertIfCurrentTimeIsNotLess(uint256 inputTime) internal view virtual; ### _revertIfCurrentTimeIsNotGreater -Internal function to revert if the current timestamp is not greater than or equal a specified time. +*Internal function to revert if the current timestamp is not greater than or equal a specified time.* ```solidity @@ -83,7 +83,7 @@ function _revertIfCurrentTimeIsNotGreater(uint256 inputTime) internal view virtu ### _revertIfCurrentTimeIsNotWithinRange -Internal function to revert if the current timestamp is not within a specified time range. +*Internal function to revert if the current timestamp is not within a specified time range.* ```solidity @@ -99,7 +99,7 @@ function _revertIfCurrentTimeIsNotWithinRange(uint256 initialTime, uint256 final ## Errors ### CurrentTimeIsGreater -Error: The current timestamp is greater than the specified input time. +*Error: The current timestamp is greater than the specified input time.* ```solidity @@ -114,7 +114,7 @@ error CurrentTimeIsGreater(uint256 inputTime, uint256 currentTime); |`currentTime`|`uint256`|The current block timestamp.| ### CurrentTimeIsLess -Error: The current timestamp is less than the specified input time. +*Error: The current timestamp is less than the specified input time.* ```solidity @@ -129,7 +129,7 @@ error CurrentTimeIsLess(uint256 inputTime, uint256 currentTime); |`currentTime`|`uint256`|The current block timestamp.| ### CurrentTimeIsNotWithinRange -Error: The current timestamp is not within the specified range. +*Error: The current timestamp is not within the specified range.* ```solidity diff --git a/env.example b/env.example index 11883c7d..e2979993 100644 --- a/env.example +++ b/env.example @@ -41,6 +41,7 @@ PROTOCOL_FEE_PERCENT= PLATFORM_NAME= PLATFORM_ADMIN_ADDRESS= +PLATFORM_ADAPTER_ADDRESS= # Optional: Trusted forwarder address for ERC-2771 meta-transactions (adapter contract) PLATFORM_FEE_PERCENT= diff --git a/script/DeployAll.s.sol b/script/DeployAll.s.sol index 5180e7c9..c1bc4d54 100644 --- a/script/DeployAll.s.sol +++ b/script/DeployAll.s.sol @@ -25,7 +25,7 @@ contract DeployAll is DeployBase { // Deploy TestToken only if needed address testTokenAddress; bool testTokenDeployed = false; - + if (shouldDeployTestToken()) { string memory tokenName = vm.envOr("TOKEN_NAME", string("TestToken")); string memory tokenSymbol = vm.envOr("TOKEN_SYMBOL", string("TST")); @@ -42,8 +42,7 @@ contract DeployAll is DeployBase { // Deploy GlobalParams with UUPS proxy uint256 protocolFeePercent = vm.envOr("PROTOCOL_FEE_PERCENT", uint256(100)); - (bytes32[] memory currencies, address[][] memory tokensPerCurrency) = - loadCurrenciesAndTokens(testTokenAddress); + (bytes32[] memory currencies, address[][] memory tokensPerCurrency) = loadCurrenciesAndTokens(testTokenAddress); // Deploy GlobalParams implementation GlobalParams globalParamsImpl = new GlobalParams(); @@ -97,10 +96,12 @@ contract DeployAll is DeployBase { uint256 minimumCampaignDuration = vm.envOr("MINIMUM_CAMPAIGN_DURATION", uint256(0)); GlobalParams(address(globalParamsProxy)).addToRegistry(DataRegistryKeys.BUFFER_TIME, bytes32(bufferTime)); - GlobalParams(address(globalParamsProxy)) - .addToRegistry(DataRegistryKeys.CAMPAIGN_LAUNCH_BUFFER, bytes32(campaignLaunchBuffer)); - GlobalParams(address(globalParamsProxy)) - .addToRegistry(DataRegistryKeys.MINIMUM_CAMPAIGN_DURATION, bytes32(minimumCampaignDuration)); + GlobalParams(address(globalParamsProxy)).addToRegistry( + DataRegistryKeys.CAMPAIGN_LAUNCH_BUFFER, bytes32(campaignLaunchBuffer) + ); + GlobalParams(address(globalParamsProxy)).addToRegistry( + DataRegistryKeys.MINIMUM_CAMPAIGN_DURATION, bytes32(minimumCampaignDuration) + ); if (!simulate) { vm.stopBroadcast(); @@ -110,7 +111,7 @@ contract DeployAll is DeployBase { console2.log("\n==========================================="); console2.log(" Deployment Summary"); console2.log("==========================================="); - + console2.log("\n--- Core Protocol Contracts (UUPS Proxies) ---"); console2.log("GLOBAL_PARAMS_PROXY:", address(globalParamsProxy)); console2.log(" Implementation:", address(globalParamsImpl)); @@ -118,21 +119,21 @@ contract DeployAll is DeployBase { console2.log(" Implementation:", address(treasuryFactoryImpl)); console2.log("CAMPAIGN_INFO_FACTORY_PROXY:", address(campaignFactoryProxy)); console2.log(" Implementation:", address(campaignFactoryImpl)); - + console2.log("\n--- Implementation Contracts ---"); console2.log("CAMPAIGN_INFO_IMPLEMENTATION:", address(campaignInfoImplementation)); - + console2.log("\n--- Supported Currencies & Tokens ---"); string memory currenciesConfig = vm.envOr("CURRENCIES", string("")); if (bytes(currenciesConfig).length > 0) { string[] memory currencyStrings = _split(currenciesConfig, ","); string memory tokensConfig = vm.envOr("TOKENS_PER_CURRENCY", string("")); string[] memory perCurrencyConfigs = _split(tokensConfig, ";"); - + for (uint256 i = 0; i < currencyStrings.length; i++) { string memory currency = _trimWhitespace(currencyStrings[i]); console2.log(string(abi.encodePacked("Currency: ", currency))); - + string[] memory tokenStrings = _split(perCurrencyConfigs[i], ","); for (uint256 j = 0; j < tokenStrings.length; j++) { console2.log(" Token:", _trimWhitespace(tokenStrings[j])); @@ -145,7 +146,7 @@ contract DeployAll is DeployBase { console2.log(" (TestToken deployed for testing)"); } } - + console2.log("\n==========================================="); console2.log("Deployment completed successfully!"); console2.log("==========================================="); diff --git a/script/DeployAllAndSetupAllOrNothing.s.sol b/script/DeployAllAndSetupAllOrNothing.s.sol index 7acec53a..74f8c86e 100644 --- a/script/DeployAllAndSetupAllOrNothing.s.sol +++ b/script/DeployAllAndSetupAllOrNothing.s.sol @@ -42,6 +42,7 @@ contract DeployAllAndSetupAllOrNothing is DeployBase { address deployerAddress; address finalProtocolAdmin; address finalPlatformAdmin; + address platformAdapter; address backer1; address backer2; @@ -83,6 +84,7 @@ contract DeployAllAndSetupAllOrNothing is DeployBase { // These are the final admin addresses that will receive control finalProtocolAdmin = vm.envOr("PROTOCOL_ADMIN_ADDRESS", deployerAddress); finalPlatformAdmin = vm.envOr("PLATFORM_ADMIN_ADDRESS", deployerAddress); + platformAdapter = vm.envOr("PLATFORM_ADAPTER_ADDRESS", address(0)); backer1 = vm.envOr("BACKER1_ADDRESS", address(0)); backer2 = vm.envOr("BACKER2_ADDRESS", address(0)); @@ -100,6 +102,7 @@ contract DeployAllAndSetupAllOrNothing is DeployBase { console2.log("Deployer address:", deployerAddress); console2.log("Final protocol admin:", finalProtocolAdmin); console2.log("Final platform admin:", finalPlatformAdmin); + console2.log("Platform adapter (trusted forwarder):", platformAdapter); console2.log("Buffer time (seconds):", bufferTime); console2.log("Campaign launch buffer (seconds):", campaignLaunchBuffer); console2.log("Minimum campaign duration (seconds):", minimumCampaignDuration); @@ -114,8 +117,9 @@ contract DeployAllAndSetupAllOrNothing is DeployBase { console2.log("Setting registry values on GlobalParams"); GlobalParams(globalParams).addToRegistry(DataRegistryKeys.BUFFER_TIME, bytes32(bufferTime)); GlobalParams(globalParams).addToRegistry(DataRegistryKeys.CAMPAIGN_LAUNCH_BUFFER, bytes32(campaignLaunchBuffer)); - GlobalParams(globalParams) - .addToRegistry(DataRegistryKeys.MINIMUM_CAMPAIGN_DURATION, bytes32(minimumCampaignDuration)); + GlobalParams(globalParams).addToRegistry( + DataRegistryKeys.MINIMUM_CAMPAIGN_DURATION, bytes32(minimumCampaignDuration) + ); } // Deploy or reuse contracts @@ -228,12 +232,12 @@ contract DeployAllAndSetupAllOrNothing is DeployBase { vm.startPrank(deployerAddress); } - GlobalParams(globalParams) - .enlistPlatform( - platformHash, - deployerAddress, // Initially deployer is platform admin - platformFeePercent - ); + GlobalParams(globalParams).enlistPlatform( + platformHash, + deployerAddress, // Initially deployer is platform admin + platformFeePercent, + platformAdapter // Platform adapter (trusted forwarder) - can be set later with setPlatformAdapter + ); if (simulate) { vm.stopPrank(); @@ -256,12 +260,11 @@ contract DeployAllAndSetupAllOrNothing is DeployBase { vm.startPrank(deployerAddress); } - TreasuryFactory(treasuryFactory) - .registerTreasuryImplementation( - platformHash, - 0, // Implementation ID - allOrNothingImplementation - ); + TreasuryFactory(treasuryFactory).registerTreasuryImplementation( + platformHash, + 0, // Implementation ID + allOrNothingImplementation + ); if (simulate) { vm.stopPrank(); @@ -284,11 +287,10 @@ contract DeployAllAndSetupAllOrNothing is DeployBase { vm.startPrank(deployerAddress); } - TreasuryFactory(treasuryFactory) - .approveTreasuryImplementation( - platformHash, - 0 // Implementation ID - ); + TreasuryFactory(treasuryFactory).approveTreasuryImplementation( + platformHash, + 0 // Implementation ID + ); if (simulate) { vm.stopPrank(); @@ -391,17 +393,20 @@ contract DeployAllAndSetupAllOrNothing is DeployBase { if (campaignInfoFactoryImplementation != address(0)) { console2.log(" Implementation:", campaignInfoFactoryImplementation); } - + console2.log("\n--- Treasury Implementation Contracts ---"); if (campaignInfoImplementation != address(0)) { console2.log("CAMPAIGN_INFO_IMPLEMENTATION:", campaignInfoImplementation); } console2.log("ALL_OR_NOTHING_IMPLEMENTATION:", allOrNothingImplementation); - + console2.log("\n--- Platform Configuration ---"); console2.log("Platform Name Hash:", vm.toString(platformHash)); console2.log("Protocol Admin:", finalProtocolAdmin); console2.log("Platform Admin:", finalPlatformAdmin); + console2.log("Platform Adapter (Trusted Forwarder):", platformAdapter); + console2.log("GlobalParams owner:", GlobalParams(globalParams).owner()); + console2.log("CampaignInfoFactory owner:", CampaignInfoFactory(campaignInfoFactory).owner()); console2.log("\n--- Supported Currencies & Tokens ---"); string memory currenciesConfig = vm.envOr("CURRENCIES", string("")); @@ -409,11 +414,11 @@ contract DeployAllAndSetupAllOrNothing is DeployBase { string[] memory currencyStrings = _split(currenciesConfig, ","); string memory tokensConfig = vm.envOr("TOKENS_PER_CURRENCY", string("")); string[] memory perCurrencyConfigs = _split(tokensConfig, ";"); - + for (uint256 i = 0; i < currencyStrings.length; i++) { string memory currency = _trimWhitespace(currencyStrings[i]); console2.log(string(abi.encodePacked("Currency: ", currency))); - + string[] memory tokenStrings = _split(perCurrencyConfigs[i], ","); for (uint256 j = 0; j < tokenStrings.length; j++) { console2.log(" Token:", _trimWhitespace(tokenStrings[j])); diff --git a/script/DeployAllAndSetupKeepWhatsRaised.s.sol b/script/DeployAllAndSetupKeepWhatsRaised.s.sol index 31281917..caef1c0c 100644 --- a/script/DeployAllAndSetupKeepWhatsRaised.s.sol +++ b/script/DeployAllAndSetupKeepWhatsRaised.s.sol @@ -43,6 +43,7 @@ contract DeployAllAndSetupKeepWhatsRaised is DeployBase { address deployerAddress; address finalProtocolAdmin; address finalPlatformAdmin; + address platformAdapter; address backer1; address backer2; @@ -79,6 +80,7 @@ contract DeployAllAndSetupKeepWhatsRaised is DeployBase { // These are the final admin addresses that will receive control finalProtocolAdmin = vm.envOr("PROTOCOL_ADMIN_ADDRESS", deployerAddress); finalPlatformAdmin = vm.envOr("PLATFORM_ADMIN_ADDRESS", deployerAddress); + platformAdapter = vm.envOr("PLATFORM_ADAPTER_ADDRESS", address(0)); backer1 = vm.envOr("BACKER1_ADDRESS", address(0)); backer2 = vm.envOr("BACKER2_ADDRESS", address(0)); @@ -96,6 +98,7 @@ contract DeployAllAndSetupKeepWhatsRaised is DeployBase { console2.log("Deployer address:", deployerAddress); console2.log("Final protocol admin:", finalProtocolAdmin); console2.log("Final platform admin:", finalPlatformAdmin); + console2.log("Platform adapter (trusted forwarder):", platformAdapter); console2.log("Buffer time (seconds):", bufferTime); console2.log("Campaign launch buffer (seconds):", campaignLaunchBuffer); console2.log("Minimum campaign duration (seconds):", minimumCampaignDuration); @@ -110,8 +113,9 @@ contract DeployAllAndSetupKeepWhatsRaised is DeployBase { console2.log("Setting registry values on GlobalParams"); GlobalParams(globalParams).addToRegistry(DataRegistryKeys.BUFFER_TIME, bytes32(bufferTime)); GlobalParams(globalParams).addToRegistry(DataRegistryKeys.CAMPAIGN_LAUNCH_BUFFER, bytes32(campaignLaunchBuffer)); - GlobalParams(globalParams) - .addToRegistry(DataRegistryKeys.MINIMUM_CAMPAIGN_DURATION, bytes32(minimumCampaignDuration)); + GlobalParams(globalParams).addToRegistry( + DataRegistryKeys.MINIMUM_CAMPAIGN_DURATION, bytes32(minimumCampaignDuration) + ); } // Deploy or reuse contracts @@ -224,12 +228,12 @@ contract DeployAllAndSetupKeepWhatsRaised is DeployBase { vm.startPrank(deployerAddress); } - GlobalParams(globalParams) - .enlistPlatform( - platformHash, - deployerAddress, // Initially deployer is platform admin - platformFeePercent - ); + GlobalParams(globalParams).enlistPlatform( + platformHash, + deployerAddress, // Initially deployer is platform admin + platformFeePercent, + platformAdapter // Platform adapter (trusted forwarder) - can be set later with setPlatformAdapter + ); if (simulate) { vm.stopPrank(); @@ -252,12 +256,11 @@ contract DeployAllAndSetupKeepWhatsRaised is DeployBase { vm.startPrank(deployerAddress); } - TreasuryFactory(treasuryFactory) - .registerTreasuryImplementation( - platformHash, - 0, // Implementation ID - keepWhatsRaisedImplementation - ); + TreasuryFactory(treasuryFactory).registerTreasuryImplementation( + platformHash, + 0, // Implementation ID + keepWhatsRaisedImplementation + ); if (simulate) { vm.stopPrank(); @@ -280,11 +283,10 @@ contract DeployAllAndSetupKeepWhatsRaised is DeployBase { vm.startPrank(deployerAddress); } - TreasuryFactory(treasuryFactory) - .approveTreasuryImplementation( - platformHash, - 0 // Implementation ID - ); + TreasuryFactory(treasuryFactory).approveTreasuryImplementation( + platformHash, + 0 // Implementation ID + ); if (simulate) { vm.stopPrank(); @@ -387,17 +389,20 @@ contract DeployAllAndSetupKeepWhatsRaised is DeployBase { if (campaignInfoFactoryImplementation != address(0)) { console2.log(" Implementation:", campaignInfoFactoryImplementation); } - + console2.log("\n--- Treasury Implementation Contracts ---"); if (campaignInfo != address(0)) { console2.log("CAMPAIGN_INFO_IMPLEMENTATION:", campaignInfo); } console2.log("KEEP_WHATS_RAISED_IMPLEMENTATION:", keepWhatsRaisedImplementation); - + console2.log("\n--- Platform Configuration ---"); console2.log("Platform Name Hash:", vm.toString(platformHash)); console2.log("Protocol Admin:", finalProtocolAdmin); console2.log("Platform Admin:", finalPlatformAdmin); + console2.log("Platform Adapter (Trusted Forwarder):", platformAdapter); + console2.log("GlobalParams owner:", GlobalParams(globalParams).owner()); + console2.log("CampaignInfoFactory owner:", CampaignInfoFactory(campaignInfoFactory).owner()); console2.log("\n--- Supported Currencies & Tokens ---"); string memory currenciesConfig = vm.envOr("CURRENCIES", string("")); @@ -405,11 +410,11 @@ contract DeployAllAndSetupKeepWhatsRaised is DeployBase { string[] memory currencyStrings = _split(currenciesConfig, ","); string memory tokensConfig = vm.envOr("TOKENS_PER_CURRENCY", string("")); string[] memory perCurrencyConfigs = _split(tokensConfig, ";"); - + for (uint256 i = 0; i < currencyStrings.length; i++) { string memory currency = _trimWhitespace(currencyStrings[i]); console2.log(string(abi.encodePacked("Currency: ", currency))); - + string[] memory tokenStrings = _split(perCurrencyConfigs[i], ","); for (uint256 j = 0; j < tokenStrings.length; j++) { console2.log(" Token:", _trimWhitespace(tokenStrings[j])); diff --git a/script/DeployAllAndSetupPaymentTreasury.s.sol b/script/DeployAllAndSetupPaymentTreasury.s.sol index f772594e..629c4ad6 100644 --- a/script/DeployAllAndSetupPaymentTreasury.s.sol +++ b/script/DeployAllAndSetupPaymentTreasury.s.sol @@ -43,6 +43,7 @@ contract DeployAllAndSetupPaymentTreasury is DeployBase { address deployerAddress; address finalProtocolAdmin; address finalPlatformAdmin; + address platformAdapter; address backer1; address backer2; @@ -85,6 +86,7 @@ contract DeployAllAndSetupPaymentTreasury is DeployBase { // These are the final admin addresses that will receive control finalProtocolAdmin = vm.envOr("PROTOCOL_ADMIN_ADDRESS", deployerAddress); finalPlatformAdmin = vm.envOr("PLATFORM_ADMIN_ADDRESS", deployerAddress); + platformAdapter = vm.envOr("PLATFORM_ADAPTER_ADDRESS", address(0)); backer1 = vm.envOr("BACKER1_ADDRESS", address(0)); backer2 = vm.envOr("BACKER2_ADDRESS", address(0)); @@ -102,6 +104,7 @@ contract DeployAllAndSetupPaymentTreasury is DeployBase { console2.log("Deployer address:", deployerAddress); console2.log("Final protocol admin:", finalProtocolAdmin); console2.log("Final platform admin:", finalPlatformAdmin); + console2.log("Platform adapter (trusted forwarder):", platformAdapter); console2.log("Buffer time (seconds):", bufferTime); console2.log("Campaign launch buffer (seconds):", campaignLaunchBuffer); console2.log("Minimum campaign duration (seconds):", minimumCampaignDuration); @@ -117,8 +120,9 @@ contract DeployAllAndSetupPaymentTreasury is DeployBase { console2.log("Setting registry values on GlobalParams"); GlobalParams(globalParams).addToRegistry(DataRegistryKeys.BUFFER_TIME, bytes32(bufferTime)); GlobalParams(globalParams).addToRegistry(DataRegistryKeys.CAMPAIGN_LAUNCH_BUFFER, bytes32(campaignLaunchBuffer)); - GlobalParams(globalParams) - .addToRegistry(DataRegistryKeys.MINIMUM_CAMPAIGN_DURATION, bytes32(minimumCampaignDuration)); + GlobalParams(globalParams).addToRegistry( + DataRegistryKeys.MINIMUM_CAMPAIGN_DURATION, bytes32(minimumCampaignDuration) + ); } function setPlatformScopedMaxPaymentExpiration() internal { @@ -250,12 +254,12 @@ contract DeployAllAndSetupPaymentTreasury is DeployBase { vm.startPrank(deployerAddress); } - GlobalParams(globalParams) - .enlistPlatform( - platformHash, - deployerAddress, // Initially deployer is platform admin - platformFeePercent - ); + GlobalParams(globalParams).enlistPlatform( + platformHash, + deployerAddress, // Initially deployer is platform admin + platformFeePercent, + platformAdapter // Platform adapter (trusted forwarder) - can be set later with setPlatformAdapter + ); if (simulate) { vm.stopPrank(); @@ -278,12 +282,11 @@ contract DeployAllAndSetupPaymentTreasury is DeployBase { vm.startPrank(deployerAddress); } - TreasuryFactory(treasuryFactory) - .registerTreasuryImplementation( - platformHash, - 0, // Implementation ID - paymentTreasuryImplementation - ); + TreasuryFactory(treasuryFactory).registerTreasuryImplementation( + platformHash, + 0, // Implementation ID + paymentTreasuryImplementation + ); if (simulate) { vm.stopPrank(); @@ -306,11 +309,10 @@ contract DeployAllAndSetupPaymentTreasury is DeployBase { vm.startPrank(deployerAddress); } - TreasuryFactory(treasuryFactory) - .approveTreasuryImplementation( - platformHash, - 0 // Implementation ID - ); + TreasuryFactory(treasuryFactory).approveTreasuryImplementation( + platformHash, + 0 // Implementation ID + ); if (simulate) { vm.stopPrank(); @@ -414,17 +416,20 @@ contract DeployAllAndSetupPaymentTreasury is DeployBase { if (campaignInfoFactoryImplementation != address(0)) { console2.log(" Implementation:", campaignInfoFactoryImplementation); } - + console2.log("\n--- Treasury Implementation Contracts ---"); if (campaignInfoImplementation != address(0)) { console2.log("CAMPAIGN_INFO_IMPLEMENTATION:", campaignInfoImplementation); } console2.log("PAYMENT_TREASURY_IMPLEMENTATION:", paymentTreasuryImplementation); - + console2.log("\n--- Platform Configuration ---"); console2.log("Platform Name Hash:", vm.toString(platformHash)); console2.log("Protocol Admin:", finalProtocolAdmin); console2.log("Platform Admin:", finalPlatformAdmin); + console2.log("Platform Adapter (Trusted Forwarder):", platformAdapter); + console2.log("GlobalParams owner:", GlobalParams(globalParams).owner()); + console2.log("CampaignInfoFactory owner:", CampaignInfoFactory(campaignInfoFactory).owner()); console2.log("\n--- Supported Currencies & Tokens ---"); string memory currenciesConfig = vm.envOr("CURRENCIES", string("")); @@ -432,11 +437,11 @@ contract DeployAllAndSetupPaymentTreasury is DeployBase { string[] memory currencyStrings = _split(currenciesConfig, ","); string memory tokensConfig = vm.envOr("TOKENS_PER_CURRENCY", string("")); string[] memory perCurrencyConfigs = _split(tokensConfig, ";"); - + for (uint256 i = 0; i < currencyStrings.length; i++) { string memory currency = _trimWhitespace(currencyStrings[i]); console2.log(string(abi.encodePacked("Currency: ", currency))); - + string[] memory tokenStrings = _split(perCurrencyConfigs[i], ","); for (uint256 j = 0; j < tokenStrings.length; j++) { console2.log(" Token:", _trimWhitespace(tokenStrings[j])); diff --git a/script/DeployAllOrNothingImplementation.s.sol b/script/DeployAllOrNothingImplementation.s.sol index 0eb025f5..2b046be0 100644 --- a/script/DeployAllOrNothingImplementation.s.sol +++ b/script/DeployAllOrNothingImplementation.s.sol @@ -9,10 +9,7 @@ contract DeployAllOrNothingImplementation is Script { function deploy() public returns (address) { console2.log("Deploying AllOrNothingImplementation..."); AllOrNothing allOrNothingImplementation = new AllOrNothing(); - console2.log( - "AllOrNothingImplementation deployed at:", - address(allOrNothingImplementation) - ); + console2.log("AllOrNothingImplementation deployed at:", address(allOrNothingImplementation)); return address(allOrNothingImplementation); } @@ -30,9 +27,6 @@ contract DeployAllOrNothingImplementation is Script { vm.stopBroadcast(); } - console2.log( - "ALL_OR_NOTHING_IMPLEMENTATION_ADDRESS", - implementationAddress - ); + console2.log("ALL_OR_NOTHING_IMPLEMENTATION_ADDRESS", implementationAddress); } } diff --git a/script/DeployCampaignInfoFactory.s.sol b/script/DeployCampaignInfoFactory.s.sol index 6bb17a58..c2c5b0d0 100644 --- a/script/DeployCampaignInfoFactory.s.sol +++ b/script/DeployCampaignInfoFactory.s.sol @@ -11,10 +11,7 @@ import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.s import {DeployBase} from "./lib/DeployBase.s.sol"; contract DeployCampaignInfoFactory is DeployBase { - function deploy( - address globalParams, - address treasuryFactory - ) public returns (address) { + function deploy(address globalParams, address treasuryFactory) public returns (address) { console2.log("Deploying CampaignInfoFactory..."); address deployer = vm.addr(vm.envUint("PRIVATE_KEY")); @@ -40,10 +37,7 @@ contract DeployCampaignInfoFactory is DeployBase { // Deploy proxy ERC1967Proxy proxy = new ERC1967Proxy(address(factoryImplementation), initData); - console2.log( - "CampaignInfoFactory proxy deployed and initialized at:", - address(proxy) - ); + console2.log("CampaignInfoFactory proxy deployed and initialized at:", address(proxy)); return address(proxy); } diff --git a/script/DeployCampaignInfoImplementation.s.sol b/script/DeployCampaignInfoImplementation.s.sol index 4fe1465b..85b44fc3 100644 --- a/script/DeployCampaignInfoImplementation.s.sol +++ b/script/DeployCampaignInfoImplementation.s.sol @@ -11,10 +11,7 @@ contract DeployCampaignInfoImplementation is Script { // Implementation will use the script address as admin, but this will be replaced // when the factory creates new instances CampaignInfo campaignInfo = new CampaignInfo(); - console2.log( - "CampaignInfo implementation deployed at:", - address(campaignInfo) - ); + console2.log("CampaignInfo implementation deployed at:", address(campaignInfo)); return address(campaignInfo); } diff --git a/script/DeployKeepWhatsRaised.s.sol b/script/DeployKeepWhatsRaised.s.sol index 45a450d8..79f4593d 100644 --- a/script/DeployKeepWhatsRaised.s.sol +++ b/script/DeployKeepWhatsRaised.s.sol @@ -9,10 +9,7 @@ contract DeployKeepWhatsRaisedImplementation is Script { function deploy() public returns (address) { console2.log("Deploying KeepWhatsRaisedImplementation..."); KeepWhatsRaised keepWhatsRaisedImplementation = new KeepWhatsRaised(); - console2.log( - "KeepWhatsRaisedImplementation deployed at:", - address(keepWhatsRaisedImplementation) - ); + console2.log("KeepWhatsRaisedImplementation deployed at:", address(keepWhatsRaisedImplementation)); return address(keepWhatsRaisedImplementation); } @@ -30,9 +27,6 @@ contract DeployKeepWhatsRaisedImplementation is Script { vm.stopBroadcast(); } - console2.log( - "KEEP_WHATS_RAISED_IMPLEMENTATION_ADDRESS", - implementationAddress - ); + console2.log("KEEP_WHATS_RAISED_IMPLEMENTATION_ADDRESS", implementationAddress); } -} \ No newline at end of file +} diff --git a/script/DeployTreasuryFactory.s.sol b/script/DeployTreasuryFactory.s.sol index 36625a5c..d62142b9 100644 --- a/script/DeployTreasuryFactory.s.sol +++ b/script/DeployTreasuryFactory.s.sol @@ -10,19 +10,17 @@ import {DeployBase} from "./lib/DeployBase.s.sol"; contract DeployTreasuryFactory is DeployBase { function deploy(address _globalParams) public returns (address) { require(_globalParams != address(0), "GlobalParams not set"); - + // Deploy implementation TreasuryFactory implementation = new TreasuryFactory(); - + // Prepare initialization data - bytes memory initData = abi.encodeWithSelector( - TreasuryFactory.initialize.selector, - IGlobalParams(_globalParams) - ); - + bytes memory initData = + abi.encodeWithSelector(TreasuryFactory.initialize.selector, IGlobalParams(_globalParams)); + // Deploy proxy ERC1967Proxy proxy = new ERC1967Proxy(address(implementation), initData); - + return address(proxy); } diff --git a/script/UpgradeCampaignInfoFactory.s.sol b/script/UpgradeCampaignInfoFactory.s.sol index bc460fa8..7fa95100 100644 --- a/script/UpgradeCampaignInfoFactory.s.sol +++ b/script/UpgradeCampaignInfoFactory.s.sol @@ -14,7 +14,7 @@ contract UpgradeCampaignInfoFactory is Script { function run() external { uint256 deployerKey = vm.envUint("PRIVATE_KEY"); address proxyAddress = vm.envAddress("CAMPAIGN_INFO_FACTORY_ADDRESS"); - + require(proxyAddress != address(0), "Proxy address must be set"); vm.startBroadcast(deployerKey); @@ -26,7 +26,7 @@ contract UpgradeCampaignInfoFactory is Script { // Upgrade the proxy to point to the new implementation CampaignInfoFactory proxy = CampaignInfoFactory(proxyAddress); proxy.upgradeToAndCall(address(newImplementation), ""); - + console2.log("CampaignInfoFactory proxy upgraded successfully"); console2.log("Proxy address:", proxyAddress); console2.log("New implementation address:", address(newImplementation)); @@ -34,4 +34,3 @@ contract UpgradeCampaignInfoFactory is Script { vm.stopBroadcast(); } } - diff --git a/script/UpgradeGlobalParams.s.sol b/script/UpgradeGlobalParams.s.sol index 8f1dab67..0400f5fe 100644 --- a/script/UpgradeGlobalParams.s.sol +++ b/script/UpgradeGlobalParams.s.sol @@ -14,7 +14,7 @@ contract UpgradeGlobalParams is Script { function run() external { uint256 deployerKey = vm.envUint("PRIVATE_KEY"); address proxyAddress = vm.envAddress("GLOBAL_PARAMS_ADDRESS"); - + require(proxyAddress != address(0), "Proxy address must be set"); vm.startBroadcast(deployerKey); @@ -26,7 +26,7 @@ contract UpgradeGlobalParams is Script { // Upgrade the proxy to point to the new implementation GlobalParams proxy = GlobalParams(proxyAddress); proxy.upgradeToAndCall(address(newImplementation), ""); - + console2.log("GlobalParams proxy upgraded successfully"); console2.log("Proxy address:", proxyAddress); console2.log("New implementation address:", address(newImplementation)); @@ -34,4 +34,3 @@ contract UpgradeGlobalParams is Script { vm.stopBroadcast(); } } - diff --git a/script/UpgradeTreasuryFactory.s.sol b/script/UpgradeTreasuryFactory.s.sol index 2a62fd5a..f8859700 100644 --- a/script/UpgradeTreasuryFactory.s.sol +++ b/script/UpgradeTreasuryFactory.s.sol @@ -14,7 +14,7 @@ contract UpgradeTreasuryFactory is Script { function run() external { uint256 deployerKey = vm.envUint("PRIVATE_KEY"); address proxyAddress = vm.envAddress("TREASURY_FACTORY_ADDRESS"); - + require(proxyAddress != address(0), "Proxy address must be set"); vm.startBroadcast(deployerKey); @@ -26,7 +26,7 @@ contract UpgradeTreasuryFactory is Script { // Upgrade the proxy to point to the new implementation TreasuryFactory proxy = TreasuryFactory(proxyAddress); proxy.upgradeToAndCall(address(newImplementation), ""); - + console2.log("TreasuryFactory proxy upgraded successfully"); console2.log("Proxy address:", proxyAddress); console2.log("New implementation address:", address(newImplementation)); @@ -34,4 +34,3 @@ contract UpgradeTreasuryFactory is Script { vm.stopBroadcast(); } } - diff --git a/src/CampaignInfo.sol b/src/CampaignInfo.sol index 93114444..89061ffa 100644 --- a/src/CampaignInfo.sol +++ b/src/CampaignInfo.sol @@ -43,19 +43,15 @@ contract CampaignInfo is mapping(bytes32 => bytes32) private s_platformData; bytes32[] private s_approvedPlatformHashes; - + // Multi-token support - address[] private s_acceptedTokens; // Accepted tokens for this campaign - mapping(address => bool) private s_isAcceptedToken; // O(1) token validation - + address[] private s_acceptedTokens; // Accepted tokens for this campaign + mapping(address => bool) private s_isAcceptedToken; // O(1) token validation + // Lock mechanism - prevents certain operations after treasury deployment bool private s_isLocked; - function getApprovedPlatformHashes() - external - view - returns (bytes32[] memory) - { + function getApprovedPlatformHashes() external view returns (bytes32[] memory) { return s_approvedPlatformHashes; } @@ -90,30 +86,21 @@ contract CampaignInfo is * @param platformHash The bytes32 identifier of the platform. * @param selection The new selection state. */ - event CampaignInfoSelectedPlatformUpdated( - bytes32 indexed platformHash, - bool selection - ); + event CampaignInfoSelectedPlatformUpdated(bytes32 indexed platformHash, bool selection); /** * @dev Emitted when platform information is updated for the campaign. * @param platformHash The bytes32 identifier of the platform. * @param platformTreasury The address of the platform's treasury. */ - event CampaignInfoPlatformInfoUpdated( - bytes32 indexed platformHash, - address indexed platformTreasury - ); + event CampaignInfoPlatformInfoUpdated(bytes32 indexed platformHash, address indexed platformTreasury); /** * @dev Emitted when an invalid platform update is attempted. * @param platformHash The bytes32 identifier of the platform. * @param selection The selection state (true/false). */ - error CampaignInfoInvalidPlatformUpdate( - bytes32 platformHash, - bool selection - ); + error CampaignInfoInvalidPlatformUpdate(bytes32 platformHash, bool selection); /** * @dev Emitted when an unauthorized action is attempted. @@ -142,7 +129,6 @@ contract CampaignInfo is */ error CampaignInfoIsLocked(); - /** * @dev Modifier that checks if the campaign is not locked. */ @@ -152,7 +138,7 @@ contract CampaignInfo is } _; } - + /** * @notice Constructor passes empty strings to ERC721 */ @@ -176,7 +162,7 @@ contract CampaignInfo is __AccessChecker_init(globalParams); _transferOwnership(creator); s_campaignData = campaignData; - + // Store accepted tokens uint256 tokenLen = acceptedTokens.length; for (uint256 i = 0; i < tokenLen; ++i) { @@ -184,18 +170,18 @@ contract CampaignInfo is s_acceptedTokens.push(token); s_isAcceptedToken[token] = true; } - + uint256 len = selectedPlatformHash.length; for (uint256 i = 0; i < len; ++i) { - s_platformFeePercent[selectedPlatformHash[i]] = _getGlobalParams() - .getPlatformFeePercent(selectedPlatformHash[i]); + s_platformFeePercent[selectedPlatformHash[i]] = + _getGlobalParams().getPlatformFeePercent(selectedPlatformHash[i]); s_isSelectedPlatform[selectedPlatformHash[i]] = true; } len = platformDataKey.length; for (uint256 i = 0; i < len; ++i) { s_platformData[platformDataKey[i]] = platformDataValue[i]; } - + // Initialize NFT metadata _initializeNFT(nftName, nftSymbol, nftImageURI, nftContractURI); } @@ -208,19 +194,14 @@ contract CampaignInfo is function getCampaignConfig() public view returns (Config memory config) { bytes memory args = Clones.fetchCloneArgs(address(this)); - ( - config.treasuryFactory, - config.protocolFeePercent, - config.identifierHash - ) = abi.decode(args, (address, uint256, bytes32)); + (config.treasuryFactory, config.protocolFeePercent, config.identifierHash) = + abi.decode(args, (address, uint256, bytes32)); } /** * @inheritdoc ICampaignInfo */ - function checkIfPlatformSelected( - bytes32 platformHash - ) public view override returns (bool) { + function checkIfPlatformSelected(bytes32 platformHash) public view override returns (bool) { return s_isSelectedPlatform[platformHash]; } @@ -229,21 +210,14 @@ contract CampaignInfo is * @param platformHash The bytes32 identifier of the platform. * @return True if the platform is already approved, false otherwise. */ - function checkIfPlatformApproved( - bytes32 platformHash - ) public view returns (bool) { + function checkIfPlatformApproved(bytes32 platformHash) public view returns (bool) { return s_isApprovedPlatform[platformHash]; } /** * @inheritdoc ICampaignInfo */ - function owner() - public - view - override(ICampaignInfo, Ownable) - returns (address account) - { + function owner() public view override(ICampaignInfo, Ownable) returns (address account) { account = super.owner(); } @@ -253,7 +227,7 @@ contract CampaignInfo is function getProtocolAdminAddress() public view override returns (address) { return _getGlobalParams().getProtocolAdminAddress(); } - + /** * @inheritdoc ICampaignInfo */ @@ -358,9 +332,7 @@ contract CampaignInfo is /** * @inheritdoc ICampaignInfo */ - function getPlatformAdminAddress( - bytes32 platformHash - ) external view override returns (address) { + function getPlatformAdminAddress(bytes32 platformHash) external view override returns (address) { return _getGlobalParams().getPlatformAdminAddress(platformHash); } @@ -417,51 +389,35 @@ contract CampaignInfo is /** * @inheritdoc ICampaignInfo */ - function paused() - public - view - override(ICampaignInfo, PausableCancellable) - returns (bool) - { + function paused() public view override(ICampaignInfo, PausableCancellable) returns (bool) { return super.paused(); } /** * @inheritdoc ICampaignInfo */ - function cancelled() - public - view - override(ICampaignInfo, PausableCancellable) - returns (bool) - { + function cancelled() public view override(ICampaignInfo, PausableCancellable) returns (bool) { return super.cancelled(); } /** * @inheritdoc ICampaignInfo */ - function getPlatformFeePercent( - bytes32 platformHash - ) external view override returns (uint256) { + function getPlatformFeePercent(bytes32 platformHash) external view override returns (uint256) { return s_platformFeePercent[platformHash]; } /** * @inheritdoc ICampaignInfo */ - function getPlatformClaimDelay( - bytes32 platformHash - ) external view override returns (uint256) { + function getPlatformClaimDelay(bytes32 platformHash) external view override returns (uint256) { return _getGlobalParams().getPlatformClaimDelay(platformHash); } /** * @inheritdoc ICampaignInfo */ - function getPlatformData( - bytes32 platformDataKey - ) external view override returns (bytes32) { + function getPlatformData(bytes32 platformDataKey) external view override returns (bytes32) { bytes32 platformDataValue = s_platformData[platformDataKey]; if (platformDataValue == bytes32(0)) { revert CampaignInfoInvalidInput(); @@ -495,10 +451,7 @@ contract CampaignInfo is /** * @inheritdoc ICampaignInfo */ - function getLineItemType( - bytes32 platformHash, - bytes32 typeId - ) + function getLineItemType(bytes32 platformHash, bytes32 typeId) external view override @@ -517,9 +470,7 @@ contract CampaignInfo is /** * @inheritdoc Ownable */ - function transferOwnership( - address newOwner - ) + function transferOwnership(address newOwner) public override(ICampaignInfo, Ownable) onlyOwner @@ -532,9 +483,7 @@ contract CampaignInfo is /** * @inheritdoc ICampaignInfo */ - function updateLaunchTime( - uint256 launchTime - ) + function updateLaunchTime(uint256 launchTime) external override onlyOwner @@ -542,7 +491,7 @@ contract CampaignInfo is whenNotCancelled whenNotLocked { - if (launchTime < block.timestamp || getDeadline() <= launchTime) { + if (launchTime < s_campaignData.launchTime || getDeadline() <= launchTime) { revert CampaignInfoInvalidInput(); } s_campaignData.launchTime = launchTime; @@ -552,9 +501,7 @@ contract CampaignInfo is /** * @inheritdoc ICampaignInfo */ - function updateDeadline( - uint256 deadline - ) + function updateDeadline(uint256 deadline) external override onlyOwner @@ -562,7 +509,11 @@ contract CampaignInfo is whenNotCancelled whenNotLocked { - if (deadline <= getLaunchTime()) { + uint256 launchTime = getLaunchTime(); + uint256 minimumCampaignDuration = + uint256(_getGlobalParams().getFromRegistry(DataRegistryKeys.MINIMUM_CAMPAIGN_DURATION)); + + if (deadline <= launchTime || deadline < launchTime + minimumCampaignDuration) { revert CampaignInfoInvalidInput(); } @@ -573,9 +524,7 @@ contract CampaignInfo is /** * @inheritdoc ICampaignInfo */ - function updateGoalAmount( - uint256 goalAmount - ) + function updateGoalAmount(uint256 goalAmount) external override onlyOwner @@ -598,25 +547,19 @@ contract CampaignInfo is bool selection, bytes32[] calldata platformDataKey, bytes32[] calldata platformDataValue - ) - external - override - onlyOwner - currentTimeIsLess(getLaunchTime()) - whenNotPaused - whenNotCancelled - { + ) external override onlyOwner currentTimeIsLess(getLaunchTime()) whenNotPaused whenNotCancelled { if (checkIfPlatformSelected(platformHash) == selection) { revert CampaignInfoInvalidInput(); } - if (!_getGlobalParams().checkIfPlatformIsListed(platformHash)) { + + IGlobalParams globalParams = _getGlobalParams(); + + if (!globalParams.checkIfPlatformIsListed(platformHash)) { revert CampaignInfoInvalidPlatformUpdate(platformHash, selection); } - if (!selection && checkIfPlatformApproved(platformHash)) { revert CampaignInfoPlatformAlreadyApproved(platformHash); } - if (platformDataKey.length != platformDataValue.length) { revert CampaignInfoInvalidInput(); } @@ -624,9 +567,7 @@ contract CampaignInfo is if (selection) { bool isValid; for (uint256 i = 0; i < platformDataKey.length; i++) { - isValid = _getGlobalParams().checkIfPlatformDataKeyValid( - platformDataKey[i] - ); + isValid = globalParams.checkIfPlatformDataKeyValid(platformDataKey[i]); if (!isValid) { revert CampaignInfoInvalidInput(); } @@ -640,11 +581,11 @@ contract CampaignInfo is s_isSelectedPlatform[platformHash] = selection; if (selection) { - s_platformFeePercent[platformHash] = _getGlobalParams() - .getPlatformFeePercent(platformHash); + s_platformFeePercent[platformHash] = globalParams.getPlatformFeePercent(platformHash); } else { s_platformFeePercent[platformHash] = 0; } + emit CampaignInfoSelectedPlatformUpdated(platformHash, selection); } @@ -677,9 +618,12 @@ contract CampaignInfo is * @dev Can only be updated before campaign launch * @param newImageURI The new image URI */ - function setImageURI( - string calldata newImageURI - ) external override(ICampaignInfo, PledgeNFT) onlyOwner currentTimeIsLess(getLaunchTime()) { + function setImageURI(string calldata newImageURI) + external + override(ICampaignInfo, PledgeNFT) + onlyOwner + currentTimeIsLess(getLaunchTime()) + { s_imageURI = newImageURI; emit ImageURIUpdated(newImageURI); } @@ -689,9 +633,12 @@ contract CampaignInfo is * @dev Can only be updated before campaign launch * @param newContractURI The new contract URI */ - function updateContractURI( - string calldata newContractURI - ) external override(ICampaignInfo, PledgeNFT) onlyOwner currentTimeIsLess(getLaunchTime()) { + function updateContractURI(string calldata newContractURI) + external + override(ICampaignInfo, PledgeNFT) + onlyOwner + currentTimeIsLess(getLaunchTime()) + { s_contractURI = newContractURI; emit ContractURIUpdated(newContractURI); } @@ -716,10 +663,7 @@ contract CampaignInfo is * @param platformHash The bytes32 identifier of the platform. * @param platformTreasuryAddress The address of the platform's treasury. */ - function _setPlatformInfo( - bytes32 platformHash, - address platformTreasuryAddress - ) external whenNotPaused { + function _setPlatformInfo(bytes32 platformHash, address platformTreasuryAddress) external whenNotPaused { Config memory config = getCampaignConfig(); if (_msgSender() != config.treasuryFactory) { revert CampaignInfoUnauthorized(); @@ -742,10 +686,6 @@ contract CampaignInfo is s_isLocked = true; } - emit CampaignInfoPlatformInfoUpdated( - platformHash, - platformTreasuryAddress - ); + emit CampaignInfoPlatformInfoUpdated(platformHash, platformTreasuryAddress); } - } diff --git a/src/CampaignInfoFactory.sol b/src/CampaignInfoFactory.sol index 76ae146c..c29acd1a 100644 --- a/src/CampaignInfoFactory.sol +++ b/src/CampaignInfoFactory.sol @@ -17,7 +17,6 @@ import {DataRegistryKeys} from "./constants/DataRegistryKeys.sol"; * @dev UUPS Upgradeable contract with ERC-7201 namespaced storage */ contract CampaignInfoFactory is Initializable, ICampaignInfoFactory, OwnableUpgradeable, UUPSUpgradeable { - /** * @dev Emitted when invalid input is provided. */ @@ -28,10 +27,7 @@ contract CampaignInfoFactory is Initializable, ICampaignInfoFactory, OwnableUpgr */ error CampaignInfoFactoryCampaignInitializationFailed(); error CampaignInfoFactoryPlatformNotListed(bytes32 platformHash); - error CampaignInfoFactoryCampaignWithSameIdentifierExists( - bytes32 identifierHash, - address cloneExists - ); + error CampaignInfoFactoryCampaignWithSameIdentifierExists(bytes32 identifierHash, address cloneExists); /** * @dev Emitted when the campaign currency has no tokens. @@ -59,10 +55,8 @@ contract CampaignInfoFactory is Initializable, ICampaignInfoFactory, OwnableUpgr address treasuryFactoryAddress ) public initializer { if ( - address(globalParams) == address(0) || - campaignImplementation == address(0) || - treasuryFactoryAddress == address(0) || - initialOwner == address(0) + address(globalParams) == address(0) || campaignImplementation == address(0) + || treasuryFactoryAddress == address(0) || initialOwner == address(0) ) { revert CampaignInfoFactoryInvalidInput(); } @@ -116,13 +110,14 @@ contract CampaignInfoFactory is Initializable, ICampaignInfoFactory, OwnableUpgr } CampaignInfoFactoryStorage.Storage storage $ = CampaignInfoFactoryStorage._getCampaignInfoFactoryStorage(); - + // Cache globalParams to save gas on repeated storage reads IGlobalParams globalParams = $.globalParams; // Retrieve time constraints from GlobalParams dataRegistry uint256 campaignLaunchBuffer = uint256(globalParams.getFromRegistry(DataRegistryKeys.CAMPAIGN_LAUNCH_BUFFER)); - uint256 minimumCampaignDuration = uint256(globalParams.getFromRegistry(DataRegistryKeys.MINIMUM_CAMPAIGN_DURATION)); + uint256 minimumCampaignDuration = + uint256(globalParams.getFromRegistry(DataRegistryKeys.MINIMUM_CAMPAIGN_DURATION)); // Validate campaign timing constraints if (campaignData.launchTime < block.timestamp + campaignLaunchBuffer) { @@ -131,12 +126,10 @@ contract CampaignInfoFactory is Initializable, ICampaignInfoFactory, OwnableUpgr if (campaignData.deadline < campaignData.launchTime + minimumCampaignDuration) { revert CampaignInfoFactoryInvalidInput(); } - + bool isValid; for (uint256 i = 0; i < platformDataKey.length; i++) { - isValid = globalParams.checkIfPlatformDataKeyValid( - platformDataKey[i] - ); + isValid = globalParams.checkIfPlatformDataKeyValid(platformDataKey[i]); if (!isValid) { revert CampaignInfoFactoryInvalidInput(); } @@ -146,10 +139,7 @@ contract CampaignInfoFactory is Initializable, ICampaignInfoFactory, OwnableUpgr } address cloneExists = $.identifierToCampaignInfo[identifierHash]; if (cloneExists != address(0)) { - revert CampaignInfoFactoryCampaignWithSameIdentifierExists( - identifierHash, - cloneExists - ); + revert CampaignInfoFactoryCampaignWithSameIdentifierExists(identifierHash, cloneExists); } bool isListed; bytes32 platformHash; @@ -167,15 +157,11 @@ contract CampaignInfoFactory is Initializable, ICampaignInfoFactory, OwnableUpgr revert CampaignInfoInvalidTokenList(); } - bytes memory args = abi.encode( - $.treasuryFactoryAddress, - globalParams.getProtocolFeePercent(), - identifierHash - ); + bytes memory args = abi.encode($.treasuryFactoryAddress, globalParams.getProtocolFeePercent(), identifierHash); address clone = Clones.cloneWithImmutableArgs($.implementation, args); - + // Initialize with all parameters including NFT metadata - (bool success, ) = clone.call( + (bool success,) = clone.call( abi.encodeWithSignature( "initialize(address,address,bytes32[],bytes32[],bytes32[],(uint256,uint256,uint256,bytes32),address[],string,string,string,string)", creator, @@ -203,9 +189,7 @@ contract CampaignInfoFactory is Initializable, ICampaignInfoFactory, OwnableUpgr /** * @inheritdoc ICampaignInfoFactory */ - function updateImplementation( - address newImplementation - ) external override onlyOwner { + function updateImplementation(address newImplementation) external override onlyOwner { if (newImplementation == address(0)) { revert CampaignInfoFactoryInvalidInput(); } diff --git a/src/GlobalParams.sol b/src/GlobalParams.sol index 2dae5d11..8c6078ab 100644 --- a/src/GlobalParams.sol +++ b/src/GlobalParams.sol @@ -17,8 +17,7 @@ import {GlobalParamsStorage} from "./storage/GlobalParamsStorage.sol"; contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSUpgradeable { using Counters for Counters.Counter; - bytes32 private constant ZERO_BYTES = - 0x0000000000000000000000000000000000000000000000000000000000000000; + bytes32 private constant ZERO_BYTES = 0x0000000000000000000000000000000000000000000000000000000000000000; /** * @dev Emitted when a platform is enlisted. @@ -27,9 +26,7 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU * @param platformFeePercent The fee percentage of the enlisted platform. */ event PlatformEnlisted( - bytes32 indexed platformHash, - address indexed platformAdminAddress, - uint256 platformFeePercent + bytes32 indexed platformHash, address indexed platformAdminAddress, uint256 platformFeePercent ); /** @@ -69,36 +66,27 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU * @param platformHash The identifier of the platform. * @param newAdminAddress The new admin address of the platform. */ - event PlatformAdminAddressUpdated( - bytes32 indexed platformHash, - address indexed newAdminAddress - ); + event PlatformAdminAddressUpdated(bytes32 indexed platformHash, address indexed newAdminAddress); /** * @dev Emitted when platform data is added. * @param platformHash The identifier of the platform. * @param platformDataKey The data key added to the platform. */ - event PlatformDataAdded( - bytes32 indexed platformHash, - bytes32 indexed platformDataKey - ); + event PlatformDataAdded(bytes32 indexed platformHash, bytes32 indexed platformDataKey); /** * @dev Emitted when platform data is removed. * @param platformHash The identifier of the platform. * @param platformDataKey The data key removed from the platform. */ - event PlatformDataRemoved( - bytes32 indexed platformHash, - bytes32 platformDataKey - ); + event PlatformDataRemoved(bytes32 indexed platformHash, bytes32 platformDataKey); - /** + /** * @dev Emitted when data is added to the registry. - * @param key The registry key. - * @param value The registry value. - */ + * @param key The registry key. + * @param value The registry value. + */ event DataAddedToRegistry(bytes32 indexed key, bytes32 value); /** @@ -122,6 +110,13 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU ); event PlatformClaimDelayUpdated(bytes32 indexed platformHash, uint256 claimDelay); + /** + * @dev Emitted when a platform adapter (trusted forwarder) is set. + * @param platformHash The identifier of the platform. + * @param adapter The address of the adapter contract. + */ + event PlatformAdapterSet(bytes32 indexed platformHash, address indexed adapter); + /** * @dev Emitted when a platform-specific line item type is removed. * @param platformHash The identifier of the platform. @@ -183,7 +178,6 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU */ error GlobalParamsCurrencyTokenLengthMismatch(); - /** * @dev Throws when a currency has no tokens registered. * @param currency The currency identifier. @@ -203,7 +197,7 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU * @param typeId The identifier of the line item type. */ error GlobalParamsPlatformLineItemTypeNotFound(bytes32 platformHash, bytes32 typeId); - + /** * @dev Reverts if the input address is zero. */ @@ -255,15 +249,15 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); $.protocolAdminAddress = protocolAdminAddress; $.protocolFeePercent = protocolFeePercent; - + uint256 currencyLength = currencies.length; - if(currencyLength != tokensPerCurrency.length) { + if (currencyLength != tokensPerCurrency.length) { revert GlobalParamsCurrencyTokenLengthMismatch(); } - - for (uint256 i = 0; i < currencyLength; ) { - for (uint256 j = 0; j < tokensPerCurrency[i].length; ) { + + for (uint256 i = 0; i < currencyLength;) { + for (uint256 j = 0; j < tokensPerCurrency[i].length;) { address token = tokensPerCurrency[i][j]; if (token == address(0)) { revert GlobalParamsInvalidInput(); @@ -286,14 +280,11 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU function _authorizeUpgrade(address newImplementation) internal override onlyOwner {} /** - * @notice Adds a key-value pair to the data registry. - * @param key The registry key. - * @param value The registry value. - */ - function addToRegistry( - bytes32 key, - bytes32 value - ) external onlyOwner { + * @notice Adds a key-value pair to the data registry. + * @param key The registry key. + * @param value The registry value. + */ + function addToRegistry(bytes32 key, bytes32 value) external onlyOwner { if (key == ZERO_BYTES) { revert GlobalParamsInvalidInput(); } @@ -303,13 +294,11 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU } /** - * @notice Retrieves a value from the data registry. - * @param key The registry key. - * @return value The registry value. - */ - function getFromRegistry( - bytes32 key - ) external view returns (bytes32 value) { + * @notice Retrieves a value from the data registry. + * @param key The registry key. + * @return value The registry value. + */ + function getFromRegistry(bytes32 key) external view returns (bytes32 value) { GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); value = $.dataRegistry[key]; } @@ -317,9 +306,7 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU /** * @inheritdoc IGlobalParams */ - function getPlatformAdminAddress( - bytes32 platformHash - ) + function getPlatformAdminAddress(bytes32 platformHash) external view override @@ -336,12 +323,7 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU /** * @inheritdoc IGlobalParams */ - function getNumberOfListedPlatforms() - external - view - override - returns (uint256) - { + function getNumberOfListedPlatforms() external view override returns (uint256) { GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); return $.numberOfListedPlatforms.current(); } @@ -349,12 +331,7 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU /** * @inheritdoc IGlobalParams */ - function getProtocolAdminAddress() - external - view - override - returns (address) - { + function getProtocolAdminAddress() external view override returns (address) { GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); return $.protocolAdminAddress; } @@ -370,9 +347,7 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU /** * @inheritdoc IGlobalParams */ - function getPlatformFeePercent( - bytes32 platformHash - ) + function getPlatformFeePercent(bytes32 platformHash) external view override @@ -386,9 +361,7 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU /** * @inheritdoc IGlobalParams */ - function getPlatformClaimDelay( - bytes32 platformHash - ) + function getPlatformClaimDelay(bytes32 platformHash) external view override @@ -402,9 +375,7 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU /** * @inheritdoc IGlobalParams */ - function getPlatformDataOwner( - bytes32 platformDataKey - ) external view override returns (bytes32 platformHash) { + function getPlatformDataOwner(bytes32 platformDataKey) external view override returns (bytes32 platformHash) { GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); platformHash = $.platformDataOwner[platformDataKey]; } @@ -412,9 +383,7 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU /** * @inheritdoc IGlobalParams */ - function checkIfPlatformIsListed( - bytes32 platformHash - ) public view override returns (bool) { + function checkIfPlatformIsListed(bytes32 platformHash) public view override returns (bool) { GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); return $.platformIsListed[platformHash]; } @@ -422,24 +391,24 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU /** * @inheritdoc IGlobalParams */ - function checkIfPlatformDataKeyValid( - bytes32 platformDataKey - ) external view override returns (bool isValid) { + function checkIfPlatformDataKeyValid(bytes32 platformDataKey) external view override returns (bool isValid) { GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); isValid = $.platformData[platformDataKey]; } /** - * @notice Enlists a platform with its admin address and fee percentage. + * @notice Enlists a platform with its admin address, fee percentage, and optional adapter. * @dev The platformFeePercent can be any value including zero. * @param platformHash The platform's identifier. * @param platformAdminAddress The platform's admin address. * @param platformFeePercent The platform's fee percentage. + * @param platformAdapter The platform's adapter (trusted forwarder) address for ERC-2771 meta-transactions. Can be address(0) if not needed. */ function enlistPlatform( bytes32 platformHash, address platformAdminAddress, - uint256 platformFeePercent + uint256 platformFeePercent, + address platformAdapter ) external onlyOwner notAddressZero(platformAdminAddress) { if (platformHash == ZERO_BYTES) { revert GlobalParamsInvalidInput(); @@ -451,12 +420,12 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU $.platformIsListed[platformHash] = true; $.platformAdminAddress[platformHash] = platformAdminAddress; $.platformFeePercent[platformHash] = platformFeePercent; + $.platformAdapter[platformHash] = platformAdapter; $.numberOfListedPlatforms.increment(); - emit PlatformEnlisted( - platformHash, - platformAdminAddress, - platformFeePercent - ); + emit PlatformEnlisted(platformHash, platformAdminAddress, platformFeePercent); + if (platformAdapter != address(0)) { + emit PlatformAdapterSet(platformHash, platformAdapter); + } } } @@ -464,9 +433,7 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU * @notice Delists a platform. * @param platformHash The platform's identifier. */ - function delistPlatform( - bytes32 platformHash - ) external onlyOwner platformIsListed(platformHash) { + function delistPlatform(bytes32 platformHash) external onlyOwner platformIsListed(platformHash) { GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); $.platformIsListed[platformHash] = false; $.platformAdminAddress[platformHash] = address(0); @@ -480,10 +447,11 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU * @param platformHash The platform's identifier. * @param platformDataKey The platform data key. */ - function addPlatformData( - bytes32 platformHash, - bytes32 platformDataKey - ) external platformIsListed(platformHash) onlyPlatformAdmin(platformHash) { + function addPlatformData(bytes32 platformHash, bytes32 platformDataKey) + external + platformIsListed(platformHash) + onlyPlatformAdmin(platformHash) + { if (platformDataKey == ZERO_BYTES) { revert GlobalParamsInvalidInput(); } @@ -501,10 +469,11 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU * @param platformHash The platform's identifier. * @param platformDataKey The platform data key. */ - function removePlatformData( - bytes32 platformHash, - bytes32 platformDataKey - ) external platformIsListed(platformHash) onlyPlatformAdmin(platformHash) { + function removePlatformData(bytes32 platformHash, bytes32 platformDataKey) + external + platformIsListed(platformHash) + onlyPlatformAdmin(platformHash) + { if (platformDataKey == ZERO_BYTES) { revert GlobalParamsInvalidInput(); } @@ -520,9 +489,12 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU /** * @inheritdoc IGlobalParams */ - function updateProtocolAdminAddress( - address protocolAdminAddress - ) external override onlyOwner notAddressZero(protocolAdminAddress) { + function updateProtocolAdminAddress(address protocolAdminAddress) + external + override + onlyOwner + notAddressZero(protocolAdminAddress) + { GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); $.protocolAdminAddress = protocolAdminAddress; emit ProtocolAdminAddressUpdated(protocolAdminAddress); @@ -531,9 +503,7 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU /** * @inheritdoc IGlobalParams */ - function updateProtocolFeePercent( - uint256 protocolFeePercent - ) external override onlyOwner { + function updateProtocolFeePercent(uint256 protocolFeePercent) external override onlyOwner { GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); $.protocolFeePercent = protocolFeePercent; emit ProtocolFeePercentUpdated(protocolFeePercent); @@ -542,10 +512,7 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU /** * @inheritdoc IGlobalParams */ - function updatePlatformAdminAddress( - bytes32 platformHash, - address platformAdminAddress - ) + function updatePlatformAdminAddress(bytes32 platformHash, address platformAdminAddress) external override onlyOwner @@ -560,10 +527,7 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU /** * @inheritdoc IGlobalParams */ - function updatePlatformClaimDelay( - bytes32 platformHash, - uint256 claimDelay - ) + function updatePlatformClaimDelay(bytes32 platformHash, uint256 claimDelay) external override platformIsListed(platformHash) @@ -577,10 +541,35 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU /** * @inheritdoc IGlobalParams */ - function addTokenToCurrency( - bytes32 currency, - address token - ) external override onlyOwner notAddressZero(token) { + function getPlatformAdapter(bytes32 platformHash) + external + view + override + platformIsListed(platformHash) + returns (address) + { + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + return $.platformAdapter[platformHash]; + } + + /** + * @inheritdoc IGlobalParams + */ + function setPlatformAdapter(bytes32 platformHash, address adapter) + external + override + onlyOwner + platformIsListed(platformHash) + { + GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); + $.platformAdapter[platformHash] = adapter; + emit PlatformAdapterSet(platformHash, adapter); + } + + /** + * @inheritdoc IGlobalParams + */ + function addTokenToCurrency(bytes32 currency, address token) external override onlyOwner notAddressZero(token) { if (currency == ZERO_BYTES) { revert GlobalParamsInvalidInput(); } @@ -592,25 +581,29 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU /** * @inheritdoc IGlobalParams */ - function removeTokenFromCurrency( - bytes32 currency, - address token - ) external override onlyOwner notAddressZero(token) { + function removeTokenFromCurrency(bytes32 currency, address token) + external + override + onlyOwner + notAddressZero(token) + { GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); address[] storage tokens = $.currencyToTokens[currency]; uint256 length = tokens.length; bool found = false; - - for (uint256 i = 0; i < length; ) { + + for (uint256 i = 0; i < length;) { if (tokens[i] == token) { tokens[i] = tokens[length - 1]; tokens.pop(); found = true; break; } - unchecked { ++i; } + unchecked { + ++i; + } } - + if (!found) { revert GlobalParamsTokenNotInCurrency(currency, token); } @@ -620,9 +613,7 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU /** * @inheritdoc IGlobalParams */ - function getTokensForCurrency( - bytes32 currency - ) external view override returns (address[] memory) { + function getTokensForCurrency(bytes32 currency) external view override returns (address[] memory) { GlobalParamsStorage.Storage storage $ = GlobalParamsStorage._getGlobalParamsStorage(); return $.currencyToTokens[currency]; } @@ -637,7 +628,7 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU * @param applyProtocolFee Whether this line item is included in protocol fee calculation. * @param canRefund Whether this line item can be refunded. * @param instantTransfer Whether this line item amount can be instantly transferred. - * + * * Constraints: * - If countsTowardGoal is true, then applyProtocolFee must be false, canRefund must be true, and instantTransfer must be false. * - Non-goal instant transfer items cannot be refundable. @@ -654,7 +645,7 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU if (typeId == ZERO_BYTES) { revert GlobalParamsInvalidInput(); } - + // Validation constraint 1: If countsTowardGoal is true, then applyProtocolFee must be false, canRefund must be true, and instantTransfer must be false if (countsTowardGoal) { if (applyProtocolFee) { @@ -683,13 +674,7 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU instantTransfer: instantTransfer }); emit PlatformLineItemTypeSet( - platformHash, - typeId, - label, - countsTowardGoal, - applyProtocolFee, - canRefund, - instantTransfer + platformHash, typeId, label, countsTowardGoal, applyProtocolFee, canRefund, instantTransfer ); } @@ -699,10 +684,11 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU * @param platformHash The identifier of the platform. * @param typeId The identifier of the line item type to remove. */ - function removePlatformLineItemType( - bytes32 platformHash, - bytes32 typeId - ) external platformIsListed(platformHash) onlyPlatformAdmin(platformHash) { + function removePlatformLineItemType(bytes32 platformHash, bytes32 typeId) + external + platformIsListed(platformHash) + onlyPlatformAdmin(platformHash) + { if (typeId == ZERO_BYTES) { revert GlobalParamsInvalidInput(); } @@ -725,10 +711,7 @@ contract GlobalParams is Initializable, IGlobalParams, OwnableUpgradeable, UUPSU * @return canRefund Whether this line item can be refunded. * @return instantTransfer Whether this line item amount can be instantly transferred to platform admin after payment confirmation. */ - function getPlatformLineItemType( - bytes32 platformHash, - bytes32 typeId - ) + function getPlatformLineItemType(bytes32 platformHash, bytes32 typeId) external view returns ( diff --git a/src/TreasuryFactory.sol b/src/TreasuryFactory.sol index b96ff4bc..37a55a16 100644 --- a/src/TreasuryFactory.sol +++ b/src/TreasuryFactory.sol @@ -15,7 +15,6 @@ import {TreasuryFactoryStorage} from "./storage/TreasuryFactoryStorage.sol"; * @dev UUPS Upgradeable contract with ERC-7201 namespaced storage */ contract TreasuryFactory is Initializable, ITreasuryFactory, AdminAccessChecker, UUPSUpgradeable { - error TreasuryFactoryUnauthorized(); error TreasuryFactoryInvalidKey(); error TreasuryFactoryTreasuryCreationFailed(); @@ -50,11 +49,11 @@ contract TreasuryFactory is Initializable, ITreasuryFactory, AdminAccessChecker, /** * @inheritdoc ITreasuryFactory */ - function registerTreasuryImplementation( - bytes32 platformHash, - uint256 implementationId, - address implementation - ) external override onlyPlatformAdmin(platformHash) { + function registerTreasuryImplementation(bytes32 platformHash, uint256 implementationId, address implementation) + external + override + onlyPlatformAdmin(platformHash) + { if (implementation == address(0)) { revert TreasuryFactoryInvalidAddress(); } @@ -65,10 +64,11 @@ contract TreasuryFactory is Initializable, ITreasuryFactory, AdminAccessChecker, /** * @inheritdoc ITreasuryFactory */ - function approveTreasuryImplementation( - bytes32 platformHash, - uint256 implementationId - ) external override onlyProtocolAdmin { + function approveTreasuryImplementation(bytes32 platformHash, uint256 implementationId) + external + override + onlyProtocolAdmin + { TreasuryFactoryStorage.Storage storage $ = TreasuryFactoryStorage._getTreasuryFactoryStorage(); address implementation = $.implementationMap[platformHash][implementationId]; if (implementation == address(0)) { @@ -80,9 +80,7 @@ contract TreasuryFactory is Initializable, ITreasuryFactory, AdminAccessChecker, /** * @inheritdoc ITreasuryFactory */ - function disapproveTreasuryImplementation( - address implementation - ) external override onlyProtocolAdmin { + function disapproveTreasuryImplementation(address implementation) external override onlyProtocolAdmin { TreasuryFactoryStorage.Storage storage $ = TreasuryFactoryStorage._getTreasuryFactoryStorage(); $.approvedImplementations[implementation] = false; } @@ -90,10 +88,11 @@ contract TreasuryFactory is Initializable, ITreasuryFactory, AdminAccessChecker, /** * @inheritdoc ITreasuryFactory */ - function removeTreasuryImplementation( - bytes32 platformHash, - uint256 implementationId - ) external override onlyPlatformAdmin(platformHash) { + function removeTreasuryImplementation(bytes32 platformHash, uint256 implementationId) + external + override + onlyPlatformAdmin(platformHash) + { TreasuryFactoryStorage.Storage storage $ = TreasuryFactoryStorage._getTreasuryFactoryStorage(); delete $.implementationMap[platformHash][implementationId]; } @@ -101,11 +100,7 @@ contract TreasuryFactory is Initializable, ITreasuryFactory, AdminAccessChecker, /** * @inheritdoc ITreasuryFactory */ - function deploy( - bytes32 platformHash, - address infoAddress, - uint256 implementationId - ) + function deploy(bytes32 platformHash, address infoAddress, uint256 implementationId) external override onlyPlatformAdmin(platformHash) @@ -119,31 +114,19 @@ contract TreasuryFactory is Initializable, ITreasuryFactory, AdminAccessChecker, clone = Clones.clone(implementation); - (bool success, ) = clone.call( - abi.encodeWithSignature( - "initialize(bytes32,address)", - platformHash, - infoAddress - ) + // Fetch the platform adapter (trusted forwarder) from GlobalParams + address platformAdapter = _getGlobalParams().getPlatformAdapter(platformHash); + + (bool success,) = clone.call( + abi.encodeWithSignature("initialize(bytes32,address,address)", platformHash, infoAddress, platformAdapter) ); if (!success) { revert TreasuryFactoryTreasuryInitializationFailed(); } - (success, ) = infoAddress.call( - abi.encodeWithSignature( - "_setPlatformInfo(bytes32,address)", - platformHash, - clone - ) - ); + (success,) = infoAddress.call(abi.encodeWithSignature("_setPlatformInfo(bytes32,address)", platformHash, clone)); if (!success) { revert TreasuryFactorySettingPlatformInfoFailed(); } - emit TreasuryFactoryTreasuryDeployed( - platformHash, - implementationId, - infoAddress, - clone - ); + emit TreasuryFactoryTreasuryDeployed(platformHash, implementationId, infoAddress, clone); } } diff --git a/src/interfaces/ICampaignInfo.sol b/src/interfaces/ICampaignInfo.sol index a24a7962..9fc9854a 100644 --- a/src/interfaces/ICampaignInfo.sol +++ b/src/interfaces/ICampaignInfo.sol @@ -20,9 +20,7 @@ interface ICampaignInfo is IERC721 { * @param platformHash The bytes32 identifier of the platform to check. * @return True if the platform is selected, false otherwise. */ - function checkIfPlatformSelected( - bytes32 platformHash - ) external view returns (bool); + function checkIfPlatformSelected(bytes32 platformHash) external view returns (bool); /** * @notice Retrieves the total amount raised across non-cancelled treasuries. @@ -86,9 +84,7 @@ interface ICampaignInfo is IERC721 { * @param platformHash The bytes32 identifier of the platform. * @return The address of the platform administrator. */ - function getPlatformAdminAddress( - bytes32 platformHash - ) external view returns (address); + function getPlatformAdminAddress(bytes32 platformHash) external view returns (address); /** * @notice Retrieves the campaign's launch time. @@ -138,27 +134,21 @@ interface ICampaignInfo is IERC721 { * @param platformHash The bytes32 identifier of the platform. * @return The platform fee percentage applied to the campaign on the platform. */ - function getPlatformFeePercent( - bytes32 platformHash - ) external view returns (uint256); + function getPlatformFeePercent(bytes32 platformHash) external view returns (uint256); /** * @notice Retrieves the claim delay (in seconds) configured for the given platform. * @param platformHash The identifier of the platform. * @return The claim delay in seconds. */ - function getPlatformClaimDelay( - bytes32 platformHash - ) external view returns (uint256); + function getPlatformClaimDelay(bytes32 platformHash) external view returns (uint256); /** * @notice Retrieves platform-specific data for the campaign. * @param platformDataKey The bytes32 identifier of the platform-specific data. * @return The platform-specific data associated with the given key. */ - function getPlatformData( - bytes32 platformDataKey - ) external view returns (bytes32); + function getPlatformData(bytes32 platformDataKey) external view returns (bytes32); /** * @notice Retrieves the unique identifier hash of the campaign. @@ -239,10 +229,7 @@ interface ICampaignInfo is IERC721 { * @return canRefund Whether this line item can be refunded. * @return instantTransfer Whether this line item amount can be instantly transferred. */ - function getLineItemType( - bytes32 platformHash, - bytes32 typeId - ) + function getLineItemType(bytes32 platformHash, bytes32 typeId) external view returns ( diff --git a/src/interfaces/ICampaignInfoFactory.sol b/src/interfaces/ICampaignInfoFactory.sol index e6b1a44a..6e366b9b 100644 --- a/src/interfaces/ICampaignInfoFactory.sol +++ b/src/interfaces/ICampaignInfoFactory.sol @@ -13,10 +13,7 @@ interface ICampaignInfoFactory is ICampaignData { * @param identifierHash The unique identifier hash of the campaign. * @param campaignInfoAddress The address of the created campaign information contract. */ - event CampaignInfoFactoryCampaignCreated( - bytes32 indexed identifierHash, - address indexed campaignInfoAddress - ); + event CampaignInfoFactoryCampaignCreated(bytes32 indexed identifierHash, address indexed campaignInfoAddress); /** * @notice Emitted when the campaign after creation is initialized. @@ -25,10 +22,10 @@ interface ICampaignInfoFactory is ICampaignData { /** * @notice Creates a new campaign information contract with NFT. - * @dev IMPORTANT: Protocol and platform fees are retrieved at execution time and locked - * permanently in the campaign contract. Users should verify current fees before - * calling this function or using intermediate contracts that check fees haven't - * changed from expected values. The protocol fee is stored as immutable in the cloned + * @dev IMPORTANT: Protocol and platform fees are retrieved at execution time and locked + * permanently in the campaign contract. Users should verify current fees before + * calling this function or using intermediate contracts that check fees haven't + * changed from expected values. The protocol fee is stored as immutable in the cloned * contract and platform fees are stored during initialization. * @param creator The address of the creator of the campaign. * @param identifierHash The unique identifier hash of the campaign. diff --git a/src/interfaces/ICampaignPaymentTreasury.sol b/src/interfaces/ICampaignPaymentTreasury.sol index d43ade4a..48bbde4c 100644 --- a/src/interfaces/ICampaignPaymentTreasury.sol +++ b/src/interfaces/ICampaignPaymentTreasury.sol @@ -6,7 +6,6 @@ pragma solidity ^0.8.22; * @notice An interface for managing campaign payment treasury contracts. */ interface ICampaignPaymentTreasury { - /** * @notice Represents a stored line item with its configuration snapshot. * @param typeId The type identifier of the line item. @@ -145,29 +144,21 @@ interface ICampaignPaymentTreasury { * @notice Cancels an existing payment with the given payment ID. * @param paymentId The unique identifier of the payment to cancel. */ - function cancelPayment( - bytes32 paymentId - ) external; + function cancelPayment(bytes32 paymentId) external; /** * @notice Confirms and finalizes the payment associated with the given payment ID. * @param paymentId The unique identifier of the payment to confirm. * @param buyerAddress Optional buyer address to mint NFT to. Pass address(0) to skip NFT minting. */ - function confirmPayment( - bytes32 paymentId, - address buyerAddress - ) external; + function confirmPayment(bytes32 paymentId, address buyerAddress) external; /** * @notice Confirms and finalizes multiple payments in a single transaction. * @param paymentIds An array of unique payment identifiers to be confirmed. * @param buyerAddresses Array of buyer addresses to mint NFTs to. Must match paymentIds length. Pass address(0) to skip NFT minting for specific payments. */ - function confirmPaymentBatch( - bytes32[] calldata paymentIds, - address[] calldata buyerAddresses - ) external; + function confirmPaymentBatch(bytes32[] calldata paymentIds, address[] calldata buyerAddresses) external; /** * @notice Disburses fees collected by the treasury. @@ -193,9 +184,7 @@ interface ICampaignPaymentTreasury { * Used for processCryptoPayment and confirmPayment (with buyer address) transactions. * @param paymentId The unique identifier of the refundable payment (must have an NFT). */ - function claimRefund( - bytes32 paymentId - ) external; + function claimRefund(bytes32 paymentId) external; /** * @notice Allows platform admin to claim all remaining funds once the claim window has opened. diff --git a/src/interfaces/IGlobalParams.sol b/src/interfaces/IGlobalParams.sol index 60d3461a..0f155ebc 100644 --- a/src/interfaces/IGlobalParams.sol +++ b/src/interfaces/IGlobalParams.sol @@ -11,18 +11,14 @@ interface IGlobalParams { * @param _platformHash The unique identifier of the platform. * @return True if the platform is listed; otherwise, false. */ - function checkIfPlatformIsListed( - bytes32 _platformHash - ) external view returns (bool); + function checkIfPlatformIsListed(bytes32 _platformHash) external view returns (bool); /** * @notice Retrieves the admin address of a platform. * @param _platformHash The unique identifier of the platform. * @return The admin address of the platform. */ - function getPlatformAdminAddress( - bytes32 _platformHash - ) external view returns (address); + function getPlatformAdminAddress(bytes32 _platformHash) external view returns (address); /** * @notice Retrieves the number of listed platforms in the protocol. @@ -47,36 +43,28 @@ interface IGlobalParams { * @param platformDataKey The key of the platform-specific data. * @return platformHash The platform identifier associated with the data. */ - function getPlatformDataOwner( - bytes32 platformDataKey - ) external view returns (bytes32 platformHash); + function getPlatformDataOwner(bytes32 platformDataKey) external view returns (bytes32 platformHash); /** * @notice Retrieves the platform fee percentage for a specific platform. * @param platformHash The unique identifier of the platform. * @return The platform fee percentage as a uint256 value. */ - function getPlatformFeePercent( - bytes32 platformHash - ) external view returns (uint256); + function getPlatformFeePercent(bytes32 platformHash) external view returns (uint256); /** * @notice Retrieves the claim delay (in seconds) for a specific platform. * @param platformHash The unique identifier of the platform. * @return The claim delay in seconds. */ - function getPlatformClaimDelay( - bytes32 platformHash - ) external view returns (uint256); + function getPlatformClaimDelay(bytes32 platformHash) external view returns (uint256); /** * @notice Checks if a platform-specific data key is valid. * @param platformDataKey The key of the platform-specific data. * @return isValid True if the data key is valid; otherwise, false. */ - function checkIfPlatformDataKeyValid( - bytes32 platformDataKey - ) external view returns (bool isValid); + function checkIfPlatformDataKeyValid(bytes32 platformDataKey) external view returns (bool isValid); /** * @notice Updates the admin address of the protocol. @@ -95,20 +83,29 @@ interface IGlobalParams { * @param _platformHash The unique identifier of the platform. * @param _platformAdminAddress The new admin address of the platform. */ - function updatePlatformAdminAddress( - bytes32 _platformHash, - address _platformAdminAddress - ) external; + function updatePlatformAdminAddress(bytes32 _platformHash, address _platformAdminAddress) external; /** * @notice Updates the claim delay for a specific platform. * @param platformHash The unique identifier of the platform. * @param claimDelay The claim delay in seconds. */ - function updatePlatformClaimDelay( - bytes32 platformHash, - uint256 claimDelay - ) external; + function updatePlatformClaimDelay(bytes32 platformHash, uint256 claimDelay) external; + + /** + * @notice Retrieves the adapter (trusted forwarder) address for a platform. + * @param platformHash The unique identifier of the platform. + * @return The adapter address for ERC-2771 meta-transactions. + */ + function getPlatformAdapter(bytes32 platformHash) external view returns (address); + + /** + * @notice Sets the adapter (trusted forwarder) address for a platform. + * @dev Only callable by the protocol admin (owner). + * @param platformHash The unique identifier of the platform. + * @param adapter The address of the adapter contract. + */ + function setPlatformAdapter(bytes32 platformHash, address adapter) external; /** * @notice Adds a token to a currency. @@ -129,9 +126,7 @@ interface IGlobalParams { * @param currency The currency identifier. * @return An array of token addresses accepted for the currency. */ - function getTokensForCurrency( - bytes32 currency - ) external view returns (address[] memory); + function getTokensForCurrency(bytes32 currency) external view returns (address[] memory); /** * @notice Retrieves a value from the data registry. @@ -178,10 +173,7 @@ interface IGlobalParams { * @return canRefund Whether this line item can be refunded. * @return instantTransfer Whether this line item amount can be instantly transferred. */ - function getPlatformLineItemType( - bytes32 platformHash, - bytes32 typeId - ) + function getPlatformLineItemType(bytes32 platformHash, bytes32 typeId) external view returns ( diff --git a/src/interfaces/IItem.sol b/src/interfaces/IItem.sol index 09dd6dc7..d85a537b 100644 --- a/src/interfaces/IItem.sol +++ b/src/interfaces/IItem.sol @@ -24,10 +24,7 @@ interface IItem { * @param itemId The unique identifier of the item. * @return item The attributes of the item as an `Item` struct. */ - function getItem( - address owner, - bytes32 itemId - ) external view returns (Item memory item); + function getItem(address owner, bytes32 itemId) external view returns (Item memory item); /** * @notice Adds a new item with the given attributes. diff --git a/src/interfaces/ITreasuryFactory.sol b/src/interfaces/ITreasuryFactory.sol index 3782d60c..8e9f9f29 100644 --- a/src/interfaces/ITreasuryFactory.sol +++ b/src/interfaces/ITreasuryFactory.sol @@ -27,11 +27,8 @@ interface ITreasuryFactory { * @param implementationId The ID to assign to the implementation. * @param implementation The contract address of the implementation. */ - function registerTreasuryImplementation( - bytes32 platformHash, - uint256 implementationId, - address implementation - ) external; + function registerTreasuryImplementation(bytes32 platformHash, uint256 implementationId, address implementation) + external; /** * @notice Approves a previously registered implementation. @@ -39,10 +36,7 @@ interface ITreasuryFactory { * @param platformHash The platform identifier. * @param implementationId The ID of the implementation to approve. */ - function approveTreasuryImplementation( - bytes32 platformHash, - uint256 implementationId - ) external; + function approveTreasuryImplementation(bytes32 platformHash, uint256 implementationId) external; /** * @notice Disapproves a previously approved treasury implementation. @@ -55,10 +49,7 @@ interface ITreasuryFactory { * @param platformHash The platform identifier. * @param implementationId The implementation ID to remove. */ - function removeTreasuryImplementation( - bytes32 platformHash, - uint256 implementationId - ) external; + function removeTreasuryImplementation(bytes32 platformHash, uint256 implementationId) external; /** * @notice Deploys a treasury clone using an approved implementation. @@ -68,9 +59,7 @@ interface ITreasuryFactory { * @param implementationId The ID of the implementation to use. * @return clone The address of the deployed treasury contract. */ - function deploy( - bytes32 platformHash, - address infoAddress, - uint256 implementationId - ) external returns (address clone); + function deploy(bytes32 platformHash, address infoAddress, uint256 implementationId) + external + returns (address clone); } diff --git a/src/storage/AdminAccessCheckerStorage.sol b/src/storage/AdminAccessCheckerStorage.sol index ba3352e6..455904b2 100644 --- a/src/storage/AdminAccessCheckerStorage.sol +++ b/src/storage/AdminAccessCheckerStorage.sol @@ -15,7 +15,7 @@ library AdminAccessCheckerStorage { } // keccak256(abi.encode(uint256(keccak256("ccprotocol.storage.AdminAccessChecker")) - 1)) & ~bytes32(uint256(0xff)) - bytes32 private constant ADMIN_ACCESS_CHECKER_STORAGE_LOCATION = + bytes32 private constant ADMIN_ACCESS_CHECKER_STORAGE_LOCATION = 0x7c2f08fa04c2c7c7ab255a45dbf913d4c236b91c59858917e818398e997f8800; function _getAdminAccessCheckerStorage() internal pure returns (Storage storage $) { diff --git a/src/storage/CampaignInfoFactoryStorage.sol b/src/storage/CampaignInfoFactoryStorage.sol index 3edb2e5e..d96d66db 100644 --- a/src/storage/CampaignInfoFactoryStorage.sol +++ b/src/storage/CampaignInfoFactoryStorage.sol @@ -19,7 +19,7 @@ library CampaignInfoFactoryStorage { } // keccak256(abi.encode(uint256(keccak256("ccprotocol.storage.CampaignInfoFactory")) - 1)) & ~bytes32(uint256(0xff)) - bytes32 private constant CAMPAIGN_INFO_FACTORY_STORAGE_LOCATION = + bytes32 private constant CAMPAIGN_INFO_FACTORY_STORAGE_LOCATION = 0x2857858a392b093e1f8b3f368c2276ce911f27cef445605a2932ebe945968d00; function _getCampaignInfoFactoryStorage() internal pure returns (Storage storage $) { diff --git a/src/storage/GlobalParamsStorage.sol b/src/storage/GlobalParamsStorage.sol index 3d8232ee..22988f0a 100644 --- a/src/storage/GlobalParamsStorage.sol +++ b/src/storage/GlobalParamsStorage.sol @@ -43,11 +43,13 @@ library GlobalParamsStorage { // Platform-specific line item types: mapping(platformHash => mapping(typeId => LineItemType)) mapping(bytes32 => mapping(bytes32 => LineItemType)) platformLineItemTypes; mapping(bytes32 => uint256) platformClaimDelay; + // Platform adapter (trusted forwarder) for ERC-2771 meta-transactions: mapping(platformHash => adapterAddress) + mapping(bytes32 => address) platformAdapter; Counters.Counter numberOfListedPlatforms; } // keccak256(abi.encode(uint256(keccak256("ccprotocol.storage.GlobalParams")) - 1)) & ~bytes32(uint256(0xff)) - bytes32 private constant GLOBAL_PARAMS_STORAGE_LOCATION = + bytes32 private constant GLOBAL_PARAMS_STORAGE_LOCATION = 0x83d0145f7c1378f10048390769ec94f999b3ba6d94904b8fd7251512962b1c00; function _getGlobalParamsStorage() internal pure returns (Storage storage $) { diff --git a/src/storage/TreasuryFactoryStorage.sol b/src/storage/TreasuryFactoryStorage.sol index fe40a181..67337c1a 100644 --- a/src/storage/TreasuryFactoryStorage.sol +++ b/src/storage/TreasuryFactoryStorage.sol @@ -14,7 +14,7 @@ library TreasuryFactoryStorage { } // keccak256(abi.encode(uint256(keccak256("ccprotocol.storage.TreasuryFactory")) - 1)) & ~bytes32(uint256(0xff)) - bytes32 private constant TREASURY_FACTORY_STORAGE_LOCATION = + bytes32 private constant TREASURY_FACTORY_STORAGE_LOCATION = 0x96b7de8c171ef460648aea35787d043e89feb6b6de2623a1e6f17a91b9c9e900; function _getTreasuryFactoryStorage() internal pure returns (Storage storage $) { diff --git a/src/treasuries/AllOrNothing.sol b/src/treasuries/AllOrNothing.sol index c8fa304d..fb9391da 100644 --- a/src/treasuries/AllOrNothing.sol +++ b/src/treasuries/AllOrNothing.sol @@ -15,12 +15,7 @@ import {IReward} from "../interfaces/IReward.sol"; * @title AllOrNothing * @notice A contract for handling crowdfunding campaigns with rewards. */ -contract AllOrNothing is - IReward, - BaseTreasury, - TimestampChecker, - ReentrancyGuard -{ +contract AllOrNothing is IReward, BaseTreasury, TimestampChecker, ReentrancyGuard { using Counters for Counters.Counter; using SafeERC20 for IERC20; @@ -31,7 +26,7 @@ contract AllOrNothing is // Mapping to store reward details by name mapping(bytes32 => Reward) private s_reward; // Mapping to store the token used for each pledge - mapping(uint256 => address) private s_tokenIdToPledgeToken; + mapping(uint256 => address) private s_tokenIdToPledgeToken; // Counter for reward tiers Counters.Counter private s_rewardCounter; @@ -126,11 +121,8 @@ contract AllOrNothing is */ constructor() {} - function initialize( - bytes32 _platformHash, - address _infoAddress - ) external initializer { - __BaseContract_init(_platformHash, _infoAddress); + function initialize(bytes32 _platformHash, address _infoAddress, address _trustedForwarder) external initializer { + __BaseContract_init(_platformHash, _infoAddress, _trustedForwarder); } /** @@ -138,9 +130,7 @@ contract AllOrNothing is * @param rewardName The name of the reward. * @return reward The details of the reward as a `Reward` struct. */ - function getReward( - bytes32 rewardName - ) external view returns (Reward memory reward) { + function getReward(bytes32 rewardName) external view returns (Reward memory reward) { if (s_reward[rewardName].rewardValue == 0) { revert AllOrNothingInvalidInput(); } @@ -153,7 +143,7 @@ contract AllOrNothing is function getRaisedAmount() external view override returns (uint256) { address[] memory acceptedTokens = INFO.getAcceptedTokens(); uint256 totalNormalized = 0; - + for (uint256 i = 0; i < acceptedTokens.length; i++) { address token = acceptedTokens[i]; uint256 amount = s_tokenRaisedAmounts[token]; @@ -161,7 +151,7 @@ contract AllOrNothing is totalNormalized += _normalizeAmount(token, amount); } } - + return totalNormalized; } @@ -171,7 +161,7 @@ contract AllOrNothing is function getLifetimeRaisedAmount() external view override returns (uint256) { address[] memory acceptedTokens = INFO.getAcceptedTokens(); uint256 totalNormalized = 0; - + for (uint256 i = 0; i < acceptedTokens.length; i++) { address token = acceptedTokens[i]; uint256 amount = s_tokenLifetimeRaisedAmounts[token]; @@ -179,7 +169,7 @@ contract AllOrNothing is totalNormalized += _normalizeAmount(token, amount); } } - + return totalNormalized; } @@ -189,7 +179,7 @@ contract AllOrNothing is function getRefundedAmount() external view override returns (uint256) { address[] memory acceptedTokens = INFO.getAcceptedTokens(); uint256 totalNormalized = 0; - + for (uint256 i = 0; i < acceptedTokens.length; i++) { address token = acceptedTokens[i]; uint256 lifetimeAmount = s_tokenLifetimeRaisedAmounts[token]; @@ -199,7 +189,7 @@ contract AllOrNothing is totalNormalized += _normalizeAmount(token, refundedAmount); } } - + return totalNormalized; } @@ -212,10 +202,7 @@ contract AllOrNothing is * @param rewardNames An array of reward names. * @param rewards An array of `Reward` structs containing reward details. */ - function addRewards( - bytes32[] calldata rewardNames, - Reward[] calldata rewards - ) + function addRewards(bytes32[] calldata rewardNames, Reward[] calldata rewards) external onlyCampaignOwner whenCampaignNotPaused @@ -238,8 +225,8 @@ contract AllOrNothing is // If there are any items, their arrays must match in length if ( - (reward.itemId.length != reward.itemValue.length) || - (reward.itemId.length != reward.itemQuantity.length) + (reward.itemId.length != reward.itemValue.length) + || (reward.itemId.length != reward.itemQuantity.length) ) { revert AllOrNothingInvalidInput(); } @@ -259,9 +246,7 @@ contract AllOrNothing is * @notice Removes a reward from the campaign. * @param rewardName The name of the reward. */ - function removeReward( - bytes32 rewardName - ) + function removeReward(bytes32 rewardName) external onlyCampaignOwner whenCampaignNotPaused @@ -286,12 +271,7 @@ contract AllOrNothing is * @param shippingFee The shipping fee amount. * @param reward An array of reward names. */ - function pledgeForAReward( - address backer, - address pledgeToken, - uint256 shippingFee, - bytes32[] calldata reward - ) + function pledgeForAReward(address backer, address pledgeToken, uint256 shippingFee, bytes32[] calldata reward) external nonReentrant currentTimeIsWithinRange(INFO.getLaunchTime(), INFO.getDeadline()) @@ -303,10 +283,8 @@ contract AllOrNothing is uint256 rewardLen = reward.length; Reward storage tempReward = s_reward[reward[0]]; if ( - backer == address(0) || - rewardLen > s_rewardCounter.current() || - reward[0] == ZERO_BYTES || - !tempReward.isRewardTier + backer == address(0) || rewardLen > s_rewardCounter.current() || reward[0] == ZERO_BYTES + || !tempReward.isRewardTier ) { revert AllOrNothingInvalidInput(); } @@ -330,11 +308,7 @@ contract AllOrNothing is * @param pledgeToken The token address to use for the pledge. * @param pledgeAmount The amount of the pledge. */ - function pledgeWithoutAReward( - address backer, - address pledgeToken, - uint256 pledgeAmount - ) + function pledgeWithoutAReward(address backer, address pledgeToken, uint256 pledgeAmount) external nonReentrant currentTimeIsWithinRange(INFO.getLaunchTime(), INFO.getDeadline()) @@ -352,9 +326,7 @@ contract AllOrNothing is * @notice Allows a backer to claim a refund. * @param tokenId The ID of the token representing the pledge. */ - function claimRefund( - uint256 tokenId - ) + function claimRefund(uint256 tokenId) external currentTimeIsGreater(INFO.getLaunchTime()) whenCampaignNotPaused @@ -363,26 +335,26 @@ contract AllOrNothing is if (block.timestamp >= INFO.getDeadline() && _checkSuccessCondition()) { revert AllOrNothingNotClaimable(tokenId); } - + // Get NFT owner before burning address nftOwner = INFO.ownerOf(tokenId); - + uint256 amountToRefund = s_tokenToTotalCollectedAmount[tokenId]; uint256 pledgedAmount = s_tokenToPledgedAmount[tokenId]; address pledgeToken = s_tokenIdToPledgeToken[tokenId]; - + if (amountToRefund == 0) { revert AllOrNothingNotClaimable(tokenId); } - + s_tokenToTotalCollectedAmount[tokenId] = 0; s_tokenToPledgedAmount[tokenId] = 0; s_tokenRaisedAmounts[pledgeToken] -= pledgedAmount; delete s_tokenIdToPledgeToken[tokenId]; - + // Burn the NFT (requires treasury approval from owner) INFO.burn(tokenId); - + IERC20(pledgeToken).safeTransfer(nftOwner, amountToRefund); emit RefundClaimed(tokenId, amountToRefund, nftOwner); } @@ -390,13 +362,7 @@ contract AllOrNothing is /** * @inheritdoc ICampaignTreasury */ - function disburseFees() - public - override - currentTimeIsGreater(INFO.getDeadline()) - whenNotPaused - whenNotCancelled - { + function disburseFees() public override currentTimeIsGreater(INFO.getDeadline()) whenNotPaused whenNotCancelled { if (s_feesDisbursed) { revert AllOrNothingFeeAlreadyDisbursed(); } @@ -415,10 +381,7 @@ contract AllOrNothing is * @dev This function is overridden to allow the platform admin and the campaign owner to cancel a treasury. */ function cancelTreasury(bytes32 message) public override { - if ( - _msgSender() != INFO.getPlatformAdminAddress(PLATFORM_HASH) && - _msgSender() != INFO.owner() - ) { + if (_msgSender() != INFO.getPlatformAdminAddress(PLATFORM_HASH) && _msgSender() != INFO.owner()) { revert AllOrNothingUnAuthorized(); } _cancel(message); @@ -427,13 +390,7 @@ contract AllOrNothing is /** * @inheritdoc BaseTreasury */ - function _checkSuccessCondition() - internal - view - virtual - override - returns (bool) - { + function _checkSuccessCondition() internal view virtual override returns (bool) { return INFO.getTotalRaisedAmount() >= INFO.getGoalAmount(); } @@ -445,16 +402,16 @@ contract AllOrNothing is uint256 shippingFee, bytes32[] memory rewards ) private { - // Validate token is accepted + // Validate token is accepted if (!INFO.isTokenAccepted(pledgeToken)) { revert AllOrNothingTokenNotAccepted(pledgeToken); } - + // If this is for a reward, pledgeAmount and shippingFee are in 18 decimals // If not for a reward, amounts are already in token decimals uint256 pledgeAmountInTokenDecimals; uint256 shippingFeeInTokenDecimals; - + if (reward != ZERO_BYTES) { // Reward pledge: denormalize from 18 decimals to token decimals pledgeAmountInTokenDecimals = _denormalizeAmount(pledgeToken, pledgeAmount); @@ -464,35 +421,21 @@ contract AllOrNothing is pledgeAmountInTokenDecimals = pledgeAmount; shippingFeeInTokenDecimals = shippingFee; } - + uint256 totalAmount = pledgeAmountInTokenDecimals + shippingFeeInTokenDecimals; - + IERC20(pledgeToken).safeTransferFrom(backer, address(this), totalAmount); - + uint256 tokenId = INFO.mintNFTForPledge( - backer, - reward, - pledgeToken, - pledgeAmountInTokenDecimals, - shippingFeeInTokenDecimals, - 0 + backer, reward, pledgeToken, pledgeAmountInTokenDecimals, shippingFeeInTokenDecimals, 0 ); - + s_tokenToPledgedAmount[tokenId] = pledgeAmountInTokenDecimals; s_tokenToTotalCollectedAmount[tokenId] = totalAmount; s_tokenIdToPledgeToken[tokenId] = pledgeToken; s_tokenRaisedAmounts[pledgeToken] += pledgeAmountInTokenDecimals; s_tokenLifetimeRaisedAmounts[pledgeToken] += pledgeAmountInTokenDecimals; - - emit Receipt( - backer, - pledgeToken, - reward, - pledgeAmount, - shippingFee, - tokenId, - rewards - ); - } + emit Receipt(backer, pledgeToken, reward, pledgeAmount, shippingFee, tokenId, rewards); + } } diff --git a/src/treasuries/KeepWhatsRaised.sol b/src/treasuries/KeepWhatsRaised.sol index d4b61b23..673e039d 100644 --- a/src/treasuries/KeepWhatsRaised.sol +++ b/src/treasuries/KeepWhatsRaised.sol @@ -17,13 +17,7 @@ import {ICampaignData} from "../interfaces/ICampaignData.sol"; * @title KeepWhatsRaised * @notice A contract that keeps all the funds raised, regardless of the success condition. */ -contract KeepWhatsRaised is - IReward, - BaseTreasury, - TimestampChecker, - ICampaignData, - ReentrancyGuard -{ +contract KeepWhatsRaised is IReward, BaseTreasury, TimestampChecker, ICampaignData, ReentrancyGuard { using Counters for Counters.Counter; using SafeERC20 for IERC20; @@ -41,7 +35,7 @@ contract KeepWhatsRaised is mapping(bytes32 => uint256) public s_paymentGatewayFees; /// Mapping that stores fee values indexed by their corresponding fee keys. mapping(bytes32 => uint256) private s_feeValues; - + // Multi-token support mapping(uint256 => address) private s_tokenIdToPledgeToken; // Token used for each pledge mapping(address => uint256) private s_protocolFeePerToken; // Protocol fees per token @@ -59,10 +53,8 @@ contract KeepWhatsRaised is struct FeeKeys { /// @dev Key for a flat fee applied to an operation. bytes32 flatFeeKey; - /// @dev Key for a cumulative flat fee, potentially across multiple actions. bytes32 cumulativeFlatFeeKey; - /// @dev Keys for gross percentage-based fees (calculated before deductions). bytes32[] grossPercentageFeeKeys; } @@ -75,29 +67,24 @@ contract KeepWhatsRaised is struct FeeValues { /// @dev Value for a flat fee applied to an operation. uint256 flatFeeValue; - /// @dev Value for a cumulative flat fee, potentially across multiple actions. uint256 cumulativeFlatFeeValue; - /// @dev Values for gross percentage-based fees (calculated before deductions). uint256[] grossPercentageFeeValues; } /** * @dev System configuration parameters related to withdrawal and refund behavior. */ + struct Config { /// @dev The minimum withdrawal amount required to qualify for fee exemption. uint256 minimumWithdrawalForFeeExemption; - /// @dev Time delay (in timestamp) enforced before a withdrawal can be completed. uint256 withdrawalDelay; - /// @dev Time delay (in timestamp) before a refund becomes claimable or processed. uint256 refundDelay; - /// @dev Duration (in timestamp) for which config changes are locked to prevent immediate updates. uint256 configLockPeriod; - /// @dev True if the creator is Colombian, false otherwise. bool isColombianCreator; } @@ -153,12 +140,7 @@ contract KeepWhatsRaised is * @param feeKeys The set of keys used to determine applicable fees. * @param feeValues The fee values corresponding to the fee keys. */ - event TreasuryConfigured( - Config config, - CampaignData campaignData, - FeeKeys feeKeys, - FeeValues feeValues - ); + event TreasuryConfigured(Config config, CampaignData campaignData, FeeKeys feeKeys, FeeValues feeValues); /** * @dev Emitted when a withdrawal is successfully processed along with the applied fee. @@ -236,7 +218,7 @@ contract KeepWhatsRaised is /** * @dev Emitted when any functionality is already enabled and cannot be re-enabled. - */ + */ error KeepWhatsRaisedAlreadyEnabled(); /** @@ -244,8 +226,10 @@ contract KeepWhatsRaised is * @param availableAmount The maximum amount that can be withdrawn. * @param withdrawalAmount The attempted withdrawal amount. * @param fee The fee that would be applied to the withdrawal. - */ - error KeepWhatsRaisedInsufficientFundsForWithdrawalAndFee(uint256 availableAmount, uint256 withdrawalAmount, uint256 fee); + */ + error KeepWhatsRaisedInsufficientFundsForWithdrawalAndFee( + uint256 availableAmount, uint256 withdrawalAmount, uint256 fee + ); /** * @notice Emitted when the fee exceeds the requested withdrawal amount. @@ -275,7 +259,7 @@ contract KeepWhatsRaised is * @dev Emitted when an admin attempts to claim funds that are not yet claimable according to the rules. */ error KeepWhatsRaisedNotClaimableAdmin(); - + /** * @dev Emitted when a configuration change is attempted during the lock period. */ @@ -297,7 +281,7 @@ contract KeepWhatsRaised is * Reverts with `KeepWhatsRaisedDisabled` if the withdrawal approval flag is not set. */ modifier withdrawalEnabled() { - if(!s_isWithdrawalApproved){ + if (!s_isWithdrawalApproved) { revert KeepWhatsRaisedDisabled(); } _; @@ -309,7 +293,7 @@ contract KeepWhatsRaised is * The lock period is defined as the duration before the deadline during which configuration changes are not allowed. */ modifier onlyBeforeConfigLock() { - if(block.timestamp > s_campaignData.deadline - s_config.configLockPeriod){ + if (block.timestamp > s_campaignData.deadline - s_config.configLockPeriod) { revert KeepWhatsRaisedConfigLocked(); } _; @@ -319,10 +303,7 @@ contract KeepWhatsRaised is /// @dev Checks if `_msgSender()` is either the platform admin (via `INFO.getPlatformAdminAddress`) /// or the campaign owner (via `INFO.owner()`). Reverts with `KeepWhatsRaisedUnAuthorized` if not authorized. modifier onlyPlatformAdminOrCampaignOwner() { - if ( - _msgSender() != INFO.getPlatformAdminAddress(PLATFORM_HASH) && - _msgSender() != INFO.owner() - ) { + if (_msgSender() != INFO.getPlatformAdminAddress(PLATFORM_HASH) && _msgSender() != INFO.owner()) { revert KeepWhatsRaisedUnAuthorized(); } _; @@ -333,11 +314,8 @@ contract KeepWhatsRaised is */ constructor() {} - function initialize( - bytes32 _platformHash, - address _infoAddress - ) external initializer { - __BaseContract_init(_platformHash, _infoAddress); + function initialize(bytes32 _platformHash, address _infoAddress, address _trustedForwarder) external initializer { + __BaseContract_init(_platformHash, _infoAddress, _trustedForwarder); } /** @@ -352,9 +330,7 @@ contract KeepWhatsRaised is * @param rewardName The name of the reward. * @return reward The details of the reward as a `Reward` struct. */ - function getReward( - bytes32 rewardName - ) external view returns (Reward memory reward) { + function getReward(bytes32 rewardName) external view returns (Reward memory reward) { if (s_reward[rewardName].rewardValue == 0) { revert KeepWhatsRaisedInvalidInput(); } @@ -367,7 +343,7 @@ contract KeepWhatsRaised is function getRaisedAmount() external view override returns (uint256) { address[] memory acceptedTokens = INFO.getAcceptedTokens(); uint256 totalNormalized = 0; - + for (uint256 i = 0; i < acceptedTokens.length; i++) { address token = acceptedTokens[i]; uint256 amount = s_tokenRaisedAmounts[token]; @@ -375,7 +351,7 @@ contract KeepWhatsRaised is totalNormalized += _normalizeAmount(token, amount); } } - + return totalNormalized; } @@ -385,7 +361,7 @@ contract KeepWhatsRaised is function getLifetimeRaisedAmount() external view override returns (uint256) { address[] memory acceptedTokens = INFO.getAcceptedTokens(); uint256 totalNormalized = 0; - + for (uint256 i = 0; i < acceptedTokens.length; i++) { address token = acceptedTokens[i]; uint256 amount = s_tokenLifetimeRaisedAmounts[token]; @@ -393,7 +369,7 @@ contract KeepWhatsRaised is totalNormalized += _normalizeAmount(token, amount); } } - + return totalNormalized; } @@ -403,7 +379,7 @@ contract KeepWhatsRaised is function getRefundedAmount() external view override returns (uint256) { address[] memory acceptedTokens = INFO.getAcceptedTokens(); uint256 totalNormalized = 0; - + for (uint256 i = 0; i < acceptedTokens.length; i++) { address token = acceptedTokens[i]; uint256 lifetimeAmount = s_tokenLifetimeRaisedAmounts[token]; @@ -413,7 +389,7 @@ contract KeepWhatsRaised is totalNormalized += _normalizeAmount(token, refundedAmount); } } - + return totalNormalized; } @@ -424,7 +400,7 @@ contract KeepWhatsRaised is function getAvailableRaisedAmount() external view returns (uint256) { address[] memory acceptedTokens = INFO.getAcceptedTokens(); uint256 totalNormalized = 0; - + for (uint256 i = 0; i < acceptedTokens.length; i++) { address token = acceptedTokens[i]; uint256 amount = s_availablePerToken[token]; @@ -432,7 +408,7 @@ contract KeepWhatsRaised is totalNormalized += _normalizeAmount(token, amount); } } - + return totalNormalized; } @@ -469,11 +445,11 @@ contract KeepWhatsRaised is return s_paymentGatewayFees[pledgeId]; } - /** + /** * @dev Retrieves the fee value associated with a specific fee key from storage. * @param {bytes32} feeKey - The unique identifier key used to reference a specific fee type. - * - * @return {uint256} The fee value corresponding to the provided fee key. + * + * @return {uint256} The fee value corresponding to the provided fee key. */ function getFeeValue(bytes32 feeKey) public view returns (uint256) { return s_feeValues[feeKey]; @@ -484,8 +460,8 @@ contract KeepWhatsRaised is * @param pledgeId The unique identifier of the pledge. * @param fee The gateway fee amount to be associated with the given pledge ID. */ - function setPaymentGatewayFee(bytes32 pledgeId, uint256 fee) - public + function setPaymentGatewayFee(bytes32 pledgeId, uint256 fee) + public onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenNotPaused @@ -500,18 +476,18 @@ contract KeepWhatsRaised is /** * @notice Approves the withdrawal of the treasury by the platform admin. */ - function approveWithdrawal() - external + function approveWithdrawal() + external onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenNotPaused whenCampaignNotCancelled whenNotCancelled { - if(s_isWithdrawalApproved){ + if (s_isWithdrawalApproved) { revert KeepWhatsRaisedAlreadyEnabled(); } - + s_isWithdrawalApproved = true; emit WithdrawalApproved(); @@ -520,69 +496,57 @@ contract KeepWhatsRaised is /** * @dev Configures the treasury for a campaign by setting the system parameters, * campaign-specific data, and fee configuration keys. - * - * @param config The configuration settings including withdrawal delay, refund delay, + * + * @param config The configuration settings including withdrawal delay, refund delay, * fee exemption threshold, and configuration lock period. * @param campaignData The campaign-related metadata such as deadlines and funding goals. * @param feeKeys The set of keys used to reference applicable flat and percentage-based fees. * @param feeValues The fee values corresponding to the fee keys. - */ + */ function configureTreasury( Config memory config, CampaignData memory campaignData, FeeKeys memory feeKeys, FeeValues memory feeValues - ) - external + ) + external onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenNotPaused whenCampaignNotCancelled whenNotCancelled { - if ( - campaignData.launchTime < block.timestamp || - campaignData.deadline <= campaignData.launchTime - ) { + if (campaignData.launchTime < block.timestamp || campaignData.deadline <= campaignData.launchTime) { revert KeepWhatsRaisedInvalidInput(); } - if( - feeKeys.grossPercentageFeeKeys.length != feeValues.grossPercentageFeeValues.length - ) { + if (feeKeys.grossPercentageFeeKeys.length != feeValues.grossPercentageFeeValues.length) { revert KeepWhatsRaisedInvalidInput(); } - + s_config = config; s_feeKeys = feeKeys; s_campaignData = campaignData; s_feeValues[feeKeys.flatFeeKey] = feeValues.flatFeeValue; s_feeValues[feeKeys.cumulativeFlatFeeKey] = feeValues.cumulativeFlatFeeValue; - + for (uint256 i = 0; i < feeKeys.grossPercentageFeeKeys.length; i++) { s_feeValues[feeKeys.grossPercentageFeeKeys[i]] = feeValues.grossPercentageFeeValues[i]; } - emit TreasuryConfigured( - config, - campaignData, - feeKeys, - feeValues - ); + emit TreasuryConfigured(config, campaignData, feeKeys, feeValues); } /** * @dev Updates the campaign's deadline. - * + * * @param deadline The new deadline timestamp for the campaign. - * + * * Requirements: * - Must be called before the configuration lock period (see `onlyBeforeConfigLock`). * - The new deadline must be a future timestamp. */ - function updateDeadline( - uint256 deadline - ) + function updateDeadline(uint256 deadline) external onlyPlatformAdminOrCampaignOwner onlyBeforeConfigLock @@ -599,15 +563,13 @@ contract KeepWhatsRaised is /** * @dev Updates the funding goal amount for the campaign. - * + * * @param goalAmount The new goal amount. - * + * * Requirements: * - Must be called before the configuration lock period (see `onlyBeforeConfigLock`). */ - function updateGoalAmount( - uint256 goalAmount - ) + function updateGoalAmount(uint256 goalAmount) external onlyPlatformAdminOrCampaignOwner onlyBeforeConfigLock @@ -630,10 +592,7 @@ contract KeepWhatsRaised is * @param rewardNames An array of reward names. * @param rewards An array of `Reward` structs containing reward details. */ - function addRewards( - bytes32[] calldata rewardNames, - Reward[] calldata rewards - ) + function addRewards(bytes32[] calldata rewardNames, Reward[] calldata rewards) external onlyCampaignOwner whenCampaignNotPaused @@ -656,8 +615,8 @@ contract KeepWhatsRaised is // If there are any items, their arrays must match in length if ( - (reward.itemId.length != reward.itemValue.length) || - (reward.itemId.length != reward.itemQuantity.length) + (reward.itemId.length != reward.itemValue.length) + || (reward.itemId.length != reward.itemQuantity.length) ) { revert KeepWhatsRaisedInvalidInput(); } @@ -677,9 +636,7 @@ contract KeepWhatsRaised is * @notice Removes a reward from the campaign. * @param rewardName The name of the reward. */ - function removeReward( - bytes32 rewardName - ) + function removeReward(bytes32 rewardName) external onlyCampaignOwner whenCampaignNotPaused @@ -714,8 +671,8 @@ contract KeepWhatsRaised is uint256 fee, bytes32[] calldata reward, bool isPledgeForAReward - ) - external + ) + external nonReentrant onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused @@ -726,9 +683,9 @@ contract KeepWhatsRaised is //Set Payment Gateway Fee setPaymentGatewayFee(pledgeId, fee); - if(isPledgeForAReward){ + if (isPledgeForAReward) { _pledgeForAReward(pledgeId, backer, pledgeToken, tip, reward, _msgSender()); // Pass admin as token source - }else { + } else { _pledgeWithoutAReward(pledgeId, backer, pledgeToken, pledgeAmount, tip, _msgSender()); // Pass admin as token source } } @@ -765,7 +722,7 @@ contract KeepWhatsRaised is * @notice Internal function that allows a backer to pledge for a reward with tokens transferred from a specified source. * @dev The first element of the `reward` array must be a reward tier and the other elements can be either reward tiers or non-reward tiers. * The non-reward tiers cannot be pledged for without a reward. - * This function is called internally by both public pledgeForAReward (with backer as token source) and + * This function is called internally by both public pledgeForAReward (with backer as token source) and * setFeeAndPledge (with admin as token source). * @param pledgeId The unique identifier of the pledge. * @param backer The address of the backer making the pledge (receives the NFT). @@ -781,12 +738,10 @@ contract KeepWhatsRaised is uint256 tip, bytes32[] calldata reward, address tokenSource - ) - internal - { + ) internal { bytes32 internalPledgeId = keccak256(abi.encodePacked(pledgeId, _msgSender())); - if(s_processedPledges[internalPledgeId]){ + if (s_processedPledges[internalPledgeId]) { revert KeepWhatsRaisedPledgeAlreadyProcessed(internalPledgeId); } s_processedPledges[internalPledgeId] = true; @@ -794,10 +749,8 @@ contract KeepWhatsRaised is uint256 rewardLen = reward.length; Reward memory tempReward = s_reward[reward[0]]; if ( - backer == address(0) || - rewardLen > s_rewardCounter.current() || - reward[0] == ZERO_BYTES || - !tempReward.isRewardTier + backer == address(0) || rewardLen > s_rewardCounter.current() || reward[0] == ZERO_BYTES + || !tempReward.isRewardTier ) { revert KeepWhatsRaisedInvalidInput(); } @@ -843,7 +796,7 @@ contract KeepWhatsRaised is /** * @notice Internal function that allows a backer to pledge without selecting a reward with tokens transferred from a specified source. - * @dev This function is called internally by both public pledgeWithoutAReward (with backer as token source) and + * @dev This function is called internally by both public pledgeWithoutAReward (with backer as token source) and * setFeeAndPledge (with admin as token source). * @param pledgeId The unique identifier of the pledge. * @param backer The address of the backer making the pledge (receives the NFT). @@ -859,12 +812,10 @@ contract KeepWhatsRaised is uint256 pledgeAmount, uint256 tip, address tokenSource - ) - internal - { + ) internal { bytes32 internalPledgeId = keccak256(abi.encodePacked(pledgeId, _msgSender())); - if(s_processedPledges[internalPledgeId]){ + if (s_processedPledges[internalPledgeId]) { revert KeepWhatsRaisedPledgeAlreadyProcessed(internalPledgeId); } s_processedPledges[internalPledgeId] = true; @@ -907,10 +858,7 @@ contract KeepWhatsRaised is * Emits: * - `WithdrawalWithFeeSuccessful`. */ - function withdraw( - address token, - uint256 amount - ) + function withdraw(address token, uint256 amount) public onlyPlatformAdminOrCampaignOwner currentTimeIsLess(getDeadline() + s_config.withdrawalDelay) @@ -926,7 +874,7 @@ contract KeepWhatsRaised is uint256 flatFee = _denormalizeAmount(token, getFeeValue(s_feeKeys.flatFeeKey)); uint256 cumulativeFee = _denormalizeAmount(token, getFeeValue(s_feeKeys.cumulativeFlatFeeKey)); uint256 minimumWithdrawalForFeeExemption = _denormalizeAmount(token, s_config.minimumWithdrawalForFeeExemption); - + uint256 currentTime = block.timestamp; uint256 withdrawalAmount = s_availablePerToken[token]; uint256 totalFee = 0; @@ -934,28 +882,29 @@ contract KeepWhatsRaised is bool isFinalWithdrawal = (currentTime > getDeadline()); //Main Fees - if(isFinalWithdrawal){ - if(withdrawalAmount == 0){ + if (isFinalWithdrawal) { + if (withdrawalAmount == 0) { revert KeepWhatsRaisedAlreadyWithdrawn(); } - if(withdrawalAmount < minimumWithdrawalForFeeExemption){ - s_platformFeePerToken[token] += flatFee; - totalFee += flatFee; + if (withdrawalAmount < minimumWithdrawalForFeeExemption) { + s_platformFeePerToken[token] += flatFee; + totalFee += flatFee; } - - }else { + } else { withdrawalAmount = amount; - if(withdrawalAmount == 0){ + if (withdrawalAmount == 0) { revert KeepWhatsRaisedInvalidInput(); } - if(withdrawalAmount > s_availablePerToken[token]){ - revert KeepWhatsRaisedInsufficientFundsForWithdrawalAndFee(s_availablePerToken[token], withdrawalAmount, totalFee); + if (withdrawalAmount > s_availablePerToken[token]) { + revert KeepWhatsRaisedInsufficientFundsForWithdrawalAndFee( + s_availablePerToken[token], withdrawalAmount, totalFee + ); } - if(withdrawalAmount < minimumWithdrawalForFeeExemption){ - s_platformFeePerToken[token] += cumulativeFee; - totalFee += cumulativeFee; - }else { + if (withdrawalAmount < minimumWithdrawalForFeeExemption) { + s_platformFeePerToken[token] += cumulativeFee; + totalFee += cumulativeFee; + } else { s_platformFeePerToken[token] += flatFee; totalFee += flatFee; } @@ -975,37 +924,39 @@ contract KeepWhatsRaised is totalFee += columbianCreatorTax; } - if(isFinalWithdrawal) { - if(withdrawalAmount < totalFee) { + if (isFinalWithdrawal) { + if (withdrawalAmount < totalFee) { revert KeepWhatsRaisedInsufficientFundsForFee(withdrawalAmount, totalFee); } - + s_availablePerToken[token] = 0; IERC20(token).safeTransfer(recipient, withdrawalAmount - totalFee); } else { - if(s_availablePerToken[token] < (withdrawalAmount + totalFee)) { - revert KeepWhatsRaisedInsufficientFundsForWithdrawalAndFee(s_availablePerToken[token], withdrawalAmount, totalFee); + if (s_availablePerToken[token] < (withdrawalAmount + totalFee)) { + revert KeepWhatsRaisedInsufficientFundsForWithdrawalAndFee( + s_availablePerToken[token], withdrawalAmount, totalFee + ); } - + s_availablePerToken[token] -= (withdrawalAmount + totalFee); IERC20(token).safeTransfer(recipient, withdrawalAmount); } - emit WithdrawalWithFeeSuccessful(recipient, isFinalWithdrawal ? withdrawalAmount - totalFee : withdrawalAmount, totalFee); + emit WithdrawalWithFeeSuccessful( + recipient, isFinalWithdrawal ? withdrawalAmount - totalFee : withdrawalAmount, totalFee + ); } /** * @dev Allows a backer to claim a refund associated with a specific pledge (token ID). - * + * * @param tokenId The ID of the token representing the backer's pledge. - * + * * Requirements: * - Refund delay must have passed. * - The token must be eligible for a refund and not previously claimed. */ - function claimRefund( - uint256 tokenId - ) + function claimRefund(uint256 tokenId) external currentTimeIsGreater(getLaunchTime()) whenCampaignNotPaused @@ -1026,7 +977,7 @@ contract KeepWhatsRaised is if (netRefundAmount == 0 || s_availablePerToken[pledgeToken] < netRefundAmount) { revert KeepWhatsRaisedNotClaimable(tokenId); } - + s_tokenToPledgedAmount[tokenId] = 0; s_tokenRaisedAmounts[pledgeToken] -= amountToRefund; s_availablePerToken[pledgeToken] -= netRefundAmount; @@ -1034,44 +985,39 @@ contract KeepWhatsRaised is // Burn the NFT (requires treasury approval from owner) INFO.burn(tokenId); - + IERC20(pledgeToken).safeTransfer(nftOwner, netRefundAmount); emit RefundClaimed(tokenId, netRefundAmount, nftOwner); } /** * @dev Disburses all accumulated fees to the appropriate fee collector or treasury. - * + * * Requirements: * - Only callable when fees are available. */ - function disburseFees() - public - override - whenNotPaused - whenNotCancelled - { + function disburseFees() public override whenNotPaused whenNotCancelled { address[] memory acceptedTokens = INFO.getAcceptedTokens(); address protocolAdmin = INFO.getProtocolAdminAddress(); address platformAdmin = INFO.getPlatformAdminAddress(PLATFORM_HASH); - + for (uint256 i = 0; i < acceptedTokens.length; i++) { address token = acceptedTokens[i]; uint256 protocolShare = s_protocolFeePerToken[token]; uint256 platformShare = s_platformFeePerToken[token]; - + if (protocolShare > 0 || platformShare > 0) { s_protocolFeePerToken[token] = 0; s_platformFeePerToken[token] = 0; - + if (protocolShare > 0) { IERC20(token).safeTransfer(protocolAdmin, protocolShare); } - + if (platformShare > 0) { IERC20(token).safeTransfer(platformAdmin, platformShare); } - + emit FeesDisbursed(token, protocolShare, platformShare); } } @@ -1079,22 +1025,17 @@ contract KeepWhatsRaised is /** * @dev Allows an authorized claimer to collect tips contributed during the campaign. - * + * * Requirements: * - Caller must be authorized to claim tips. * - Tip amount must be non-zero. */ - function claimTip() - external - onlyPlatformAdmin(PLATFORM_HASH) - whenCampaignNotPaused - whenNotPaused - { - if(s_cancellationTime == 0 && block.timestamp <= getDeadline()){ + function claimTip() external onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenNotPaused { + if (s_cancellationTime == 0 && block.timestamp <= getDeadline()) { revert KeepWhatsRaisedNotClaimableAdmin(); } - if(s_tipClaimed){ + if (s_tipClaimed) { revert KeepWhatsRaisedAlreadyClaimed(); } @@ -1105,7 +1046,7 @@ contract KeepWhatsRaised is for (uint256 i = 0; i < acceptedTokens.length; i++) { address token = acceptedTokens[i]; uint256 tip = s_tipPerToken[token]; - + if (tip > 0) { s_tipPerToken[token] = 0; IERC20(token).safeTransfer(platformAdmin, tip); @@ -1115,18 +1056,13 @@ contract KeepWhatsRaised is } /** - * @dev Allows the platform admin to claim the remaining funds from a campaign. - * - * Requirements: - * - Claim period must have started and funds must be available. - * - Cannot be previously claimed. - */ - function claimFund() - external - onlyPlatformAdmin(PLATFORM_HASH) - whenCampaignNotPaused - whenNotPaused - { + * @dev Allows the platform admin to claim the remaining funds from a campaign. + * + * Requirements: + * - Claim period must have started and funds must be available. + * - Cannot be previously claimed. + */ + function claimFund() external onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenNotPaused { bool isCancelled = s_cancellationTime > 0; uint256 cancelLimit = s_cancellationTime + s_config.refundDelay; uint256 deadlineLimit = getDeadline() + s_config.withdrawalDelay; @@ -1135,7 +1071,7 @@ contract KeepWhatsRaised is revert KeepWhatsRaisedNotClaimableAdmin(); } - if(s_fundClaimed){ + if (s_fundClaimed) { revert KeepWhatsRaisedAlreadyClaimed(); } @@ -1146,7 +1082,7 @@ contract KeepWhatsRaised is for (uint256 i = 0; i < acceptedTokens.length; i++) { address token = acceptedTokens[i]; uint256 amountToClaim = s_availablePerToken[token]; - + if (amountToClaim > 0) { s_availablePerToken[token] = 0; IERC20(token).safeTransfer(platformAdmin, amountToClaim); @@ -1167,13 +1103,7 @@ contract KeepWhatsRaised is /** * @inheritdoc BaseTreasury */ - function _checkSuccessCondition() - internal - view - virtual - override - returns (bool) - { + function _checkSuccessCondition() internal view virtual override returns (bool) { return true; } @@ -1191,7 +1121,7 @@ contract KeepWhatsRaised is if (!INFO.isTokenAccepted(pledgeToken)) { revert KeepWhatsRaisedTokenNotAccepted(pledgeToken); } - + // If this is for a reward, pledgeAmount is in 18 decimals and needs to be denormalized // If not for a reward (pledgeWithoutAReward), pledgeAmount is already in token decimals // Tip is always in the pledgeToken's decimals (same token used for payment) @@ -1203,20 +1133,13 @@ contract KeepWhatsRaised is // Non-reward pledge: already in token decimals pledgeAmountInTokenDecimals = pledgeAmount; } - + uint256 totalAmount = pledgeAmountInTokenDecimals + tip; - + IERC20(pledgeToken).safeTransferFrom(tokenSource, address(this), totalAmount); - - uint256 tokenId = INFO.mintNFTForPledge( - backer, - reward, - pledgeToken, - pledgeAmountInTokenDecimals, - 0, - tip - ); - + + uint256 tokenId = INFO.mintNFTForPledge(backer, reward, pledgeToken, pledgeAmountInTokenDecimals, 0, tip); + s_tokenToPledgedAmount[tokenId] = pledgeAmountInTokenDecimals; s_tokenToTippedAmount[tokenId] = tip; s_tokenIdToPledgeToken[tokenId] = pledgeToken; @@ -1227,19 +1150,11 @@ contract KeepWhatsRaised is uint256 netAvailable = _calculateNetAvailable(pledgeId, pledgeToken, tokenId, pledgeAmountInTokenDecimals); s_availablePerToken[pledgeToken] += netAvailable; - emit Receipt( - backer, - pledgeToken, - reward, - pledgeAmount, - tip, - tokenId, - rewards - ); + emit Receipt(backer, pledgeToken, reward, pledgeAmount, tip, tokenId, rewards); } /** - * @notice Calculates the net amount available from a pledge after deducting + * @notice Calculates the net amount available from a pledge after deducting * all applicable fees. * * @dev The function performs the following: @@ -1256,14 +1171,16 @@ contract KeepWhatsRaised is * * @return The net available amount after all fees are deducted */ - function _calculateNetAvailable(bytes32 pledgeId, address pledgeToken, uint256 tokenId, uint256 pledgeAmount) internal returns (uint256) { + function _calculateNetAvailable(bytes32 pledgeId, address pledgeToken, uint256 tokenId, uint256 pledgeAmount) + internal + returns (uint256) + { uint256 totalFee = 0; // Gross Percentage Fee Calculation (correct as-is) uint256 len = s_feeKeys.grossPercentageFeeKeys.length; for (uint256 i = 0; i < len; i++) { - uint256 fee = (pledgeAmount * getFeeValue(s_feeKeys.grossPercentageFeeKeys[i])) - / PERCENT_DIVIDER; + uint256 fee = (pledgeAmount * getFeeValue(s_feeKeys.grossPercentageFeeKeys[i])) / PERCENT_DIVIDER; s_platformFeePerToken[pledgeToken] += fee; totalFee += fee; } @@ -1275,8 +1192,7 @@ contract KeepWhatsRaised is totalFee += paymentGatewayFee; // Protocol Fee Calculation (correct as-is) - uint256 protocolFee = (pledgeAmount * INFO.getProtocolFeePercent()) / - PERCENT_DIVIDER; + uint256 protocolFee = (pledgeAmount * INFO.getProtocolFeePercent()) / PERCENT_DIVIDER; s_protocolFeePerToken[pledgeToken] += protocolFee; totalFee += protocolFee; @@ -1289,20 +1205,20 @@ contract KeepWhatsRaised is * @dev Checks the refund period status based on campaign state * @param checkIfOver If true, returns whether refund period is over; if false, returns whether currently within refund period * @return bool Status based on checkIfOver parameter - * + * * @notice Refund period logic: * - If campaign is cancelled: refund period is active until s_cancellationTime + s_config.refundDelay * - If campaign is not cancelled: refund period is active until deadline + s_config.refundDelay * - Before deadline (non-cancelled): not in refund period - * + * * @dev This function handles both cancelled and non-cancelled campaign scenarios */ function _checkRefundPeriodStatus(bool checkIfOver) internal view returns (bool) { uint256 deadline = getDeadline(); bool isCancelled = s_cancellationTime > 0; - + bool refundPeriodOver; - + if (isCancelled) { // If cancelled, refund period ends after s_config.refundDelay from cancellation time refundPeriodOver = block.timestamp > s_cancellationTime + s_config.refundDelay; @@ -1310,7 +1226,7 @@ contract KeepWhatsRaised is // If not cancelled, refund period ends after s_config.refundDelay from deadline refundPeriodOver = block.timestamp > deadline + s_config.refundDelay; } - + if (checkIfOver) { return refundPeriodOver; } else { @@ -1321,5 +1237,4 @@ contract KeepWhatsRaised is return !refundPeriodOver; } } - } diff --git a/src/treasuries/PaymentTreasury.sol b/src/treasuries/PaymentTreasury.sol index d7179b01..4063fced 100644 --- a/src/treasuries/PaymentTreasury.sol +++ b/src/treasuries/PaymentTreasury.sol @@ -6,9 +6,7 @@ import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeE import {BasePaymentTreasury} from "../utils/BasePaymentTreasury.sol"; import {ICampaignPaymentTreasury} from "../interfaces/ICampaignPaymentTreasury.sol"; -contract PaymentTreasury is - BasePaymentTreasury -{ +contract PaymentTreasury is BasePaymentTreasury { using SafeERC20 for IERC20; /** @@ -21,11 +19,8 @@ contract PaymentTreasury is */ constructor() {} - function initialize( - bytes32 _platformHash, - address _infoAddress - ) external initializer { - __BaseContract_init(_platformHash, _infoAddress); + function initialize(bytes32 _platformHash, address _infoAddress, address _trustedForwarder) external initializer { + __BaseContract_init(_platformHash, _infoAddress, _trustedForwarder); } /** @@ -57,7 +52,9 @@ contract PaymentTreasury is ICampaignPaymentTreasury.LineItem[][] calldata lineItemsArray, ICampaignPaymentTreasury.ExternalFees[][] calldata externalFeesArray ) public override whenNotPaused whenNotCancelled { - super.createPaymentBatch(paymentIds, buyerIds, itemIds, paymentTokens, amounts, expirations, lineItemsArray, externalFeesArray); + super.createPaymentBatch( + paymentIds, buyerIds, itemIds, paymentTokens, amounts, expirations, lineItemsArray, externalFeesArray + ); } /** @@ -78,70 +75,64 @@ contract PaymentTreasury is /** * @inheritdoc ICampaignPaymentTreasury */ - function cancelPayment( - bytes32 paymentId - ) public override whenNotPaused whenNotCancelled { + function cancelPayment(bytes32 paymentId) public override whenNotPaused whenNotCancelled { super.cancelPayment(paymentId); } /** * @inheritdoc ICampaignPaymentTreasury */ - function confirmPayment( - bytes32 paymentId, - address buyerAddress - ) public override whenNotPaused whenNotCancelled { + function confirmPayment(bytes32 paymentId, address buyerAddress) public override whenNotPaused whenNotCancelled { super.confirmPayment(paymentId, buyerAddress); } /** * @inheritdoc ICampaignPaymentTreasury */ - function confirmPaymentBatch( - bytes32[] calldata paymentIds, - address[] calldata buyerAddresses - ) public override whenNotPaused whenNotCancelled { + function confirmPaymentBatch(bytes32[] calldata paymentIds, address[] calldata buyerAddresses) + public + override + whenNotPaused + whenNotCancelled + { super.confirmPaymentBatch(paymentIds, buyerAddresses); } /** * @inheritdoc ICampaignPaymentTreasury */ - function claimRefund( - bytes32 paymentId, - address refundAddress - ) public override whenNotPaused whenNotCancelled { + function claimRefund(bytes32 paymentId, address refundAddress) public override whenNotPaused whenNotCancelled { super.claimRefund(paymentId, refundAddress); } /** * @inheritdoc ICampaignPaymentTreasury */ - function claimRefund( - bytes32 paymentId - ) public override whenNotPaused whenNotCancelled { + function claimRefund(bytes32 paymentId) public override whenNotPaused whenNotCancelled { super.claimRefund(paymentId); } /** * @inheritdoc ICampaignPaymentTreasury */ - function claimExpiredFunds() public override whenNotPaused whenNotCancelled { + function claimExpiredFunds() public override whenNotPaused { super.claimExpiredFunds(); } /** * @inheritdoc ICampaignPaymentTreasury */ - function disburseFees() - public - override - whenNotPaused - whenNotCancelled - { + function disburseFees() public override whenNotPaused { super.disburseFees(); } + /** + * @inheritdoc BasePaymentTreasury + */ + function claimNonGoalLineItems(address token) public override whenNotPaused { + super.claimNonGoalLineItems(token); + } + /** * @inheritdoc ICampaignPaymentTreasury */ @@ -154,10 +145,7 @@ contract PaymentTreasury is * @dev This function is overridden to allow the platform admin and the campaign owner to cancel a treasury. */ function cancelTreasury(bytes32 message) public override { - if ( - _msgSender() != INFO.getPlatformAdminAddress(PLATFORM_HASH) && - _msgSender() != INFO.owner() - ) { + if (_msgSender() != INFO.getPlatformAdminAddress(PLATFORM_HASH) && _msgSender() != INFO.owner()) { revert PaymentTreasuryUnAuthorized(); } _cancel(message); @@ -166,13 +154,7 @@ contract PaymentTreasury is /** * @inheritdoc BasePaymentTreasury */ - function _checkSuccessCondition() - internal - view - virtual - override - returns (bool) - { + function _checkSuccessCondition() internal view virtual override returns (bool) { return true; } -} \ No newline at end of file +} diff --git a/src/treasuries/TimeConstrainedPaymentTreasury.sol b/src/treasuries/TimeConstrainedPaymentTreasury.sol index 49cf3ec7..cf2f1820 100644 --- a/src/treasuries/TimeConstrainedPaymentTreasury.sol +++ b/src/treasuries/TimeConstrainedPaymentTreasury.sol @@ -7,10 +7,7 @@ import {BasePaymentTreasury} from "../utils/BasePaymentTreasury.sol"; import {ICampaignPaymentTreasury} from "../interfaces/ICampaignPaymentTreasury.sol"; import {TimestampChecker} from "../utils/TimestampChecker.sol"; -contract TimeConstrainedPaymentTreasury is - BasePaymentTreasury, - TimestampChecker -{ +contract TimeConstrainedPaymentTreasury is BasePaymentTreasury, TimestampChecker { using SafeERC20 for IERC20; /** @@ -23,11 +20,8 @@ contract TimeConstrainedPaymentTreasury is */ constructor() {} - function initialize( - bytes32 _platformHash, - address _infoAddress - ) external initializer { - __BaseContract_init(_platformHash, _infoAddress); + function initialize(bytes32 _platformHash, address _infoAddress, address _trustedForwarder) external initializer { + __BaseContract_init(_platformHash, _infoAddress, _trustedForwarder); } /** @@ -60,7 +54,7 @@ contract TimeConstrainedPaymentTreasury is uint256 expiration, ICampaignPaymentTreasury.LineItem[] calldata lineItems, ICampaignPaymentTreasury.ExternalFees[] calldata externalFees - ) public override whenCampaignNotPaused whenCampaignNotCancelled { + ) public override whenNotPaused whenNotCancelled { _checkTimeWithinRange(); super.createPayment(paymentId, buyerId, itemId, paymentToken, amount, expiration, lineItems, externalFees); } @@ -77,9 +71,11 @@ contract TimeConstrainedPaymentTreasury is uint256[] calldata expirations, ICampaignPaymentTreasury.LineItem[][] calldata lineItemsArray, ICampaignPaymentTreasury.ExternalFees[][] calldata externalFeesArray - ) public override whenCampaignNotPaused whenCampaignNotCancelled { + ) public override whenNotPaused whenNotCancelled { _checkTimeWithinRange(); - super.createPaymentBatch(paymentIds, buyerIds, itemIds, paymentTokens, amounts, expirations, lineItemsArray, externalFeesArray); + super.createPaymentBatch( + paymentIds, buyerIds, itemIds, paymentTokens, amounts, expirations, lineItemsArray, externalFeesArray + ); } /** @@ -93,7 +89,7 @@ contract TimeConstrainedPaymentTreasury is uint256 amount, ICampaignPaymentTreasury.LineItem[] calldata lineItems, ICampaignPaymentTreasury.ExternalFees[] calldata externalFees - ) public override whenCampaignNotPaused whenCampaignNotCancelled { + ) public override whenNotPaused whenNotCancelled { _checkTimeWithinRange(); super.processCryptoPayment(paymentId, itemId, buyerAddress, paymentToken, amount, lineItems, externalFees); } @@ -101,9 +97,7 @@ contract TimeConstrainedPaymentTreasury is /** * @inheritdoc ICampaignPaymentTreasury */ - function cancelPayment( - bytes32 paymentId - ) public override whenCampaignNotPaused whenCampaignNotCancelled { + function cancelPayment(bytes32 paymentId) public override whenNotPaused whenNotCancelled { _checkTimeWithinRange(); super.cancelPayment(paymentId); } @@ -111,10 +105,7 @@ contract TimeConstrainedPaymentTreasury is /** * @inheritdoc ICampaignPaymentTreasury */ - function confirmPayment( - bytes32 paymentId, - address buyerAddress - ) public override whenCampaignNotPaused whenCampaignNotCancelled { + function confirmPayment(bytes32 paymentId, address buyerAddress) public override whenNotPaused whenNotCancelled { _checkTimeWithinRange(); super.confirmPayment(paymentId, buyerAddress); } @@ -122,10 +113,12 @@ contract TimeConstrainedPaymentTreasury is /** * @inheritdoc ICampaignPaymentTreasury */ - function confirmPaymentBatch( - bytes32[] calldata paymentIds, - address[] calldata buyerAddresses - ) public override whenCampaignNotPaused whenCampaignNotCancelled { + function confirmPaymentBatch(bytes32[] calldata paymentIds, address[] calldata buyerAddresses) + public + override + whenNotPaused + whenNotCancelled + { _checkTimeWithinRange(); super.confirmPaymentBatch(paymentIds, buyerAddresses); } @@ -133,10 +126,7 @@ contract TimeConstrainedPaymentTreasury is /** * @inheritdoc ICampaignPaymentTreasury */ - function claimRefund( - bytes32 paymentId, - address refundAddress - ) public override whenCampaignNotPaused whenCampaignNotCancelled { + function claimRefund(bytes32 paymentId, address refundAddress) public override whenNotPaused whenNotCancelled { _checkTimeIsGreater(); super.claimRefund(paymentId, refundAddress); } @@ -144,9 +134,7 @@ contract TimeConstrainedPaymentTreasury is /** * @inheritdoc ICampaignPaymentTreasury */ - function claimRefund( - bytes32 paymentId - ) public override whenCampaignNotPaused whenCampaignNotCancelled { + function claimRefund(bytes32 paymentId) public override whenNotPaused whenNotCancelled { _checkTimeIsGreater(); super.claimRefund(paymentId); } @@ -154,7 +142,7 @@ contract TimeConstrainedPaymentTreasury is /** * @inheritdoc ICampaignPaymentTreasury */ - function claimExpiredFunds() public override whenCampaignNotPaused whenCampaignNotCancelled { + function claimExpiredFunds() public override whenNotPaused { _checkTimeIsGreater(); super.claimExpiredFunds(); } @@ -162,20 +150,23 @@ contract TimeConstrainedPaymentTreasury is /** * @inheritdoc ICampaignPaymentTreasury */ - function disburseFees() - public - override - whenCampaignNotPaused - whenCampaignNotCancelled - { + function disburseFees() public override whenNotPaused { _checkTimeIsGreater(); super.disburseFees(); } + /** + * @inheritdoc BasePaymentTreasury + */ + function claimNonGoalLineItems(address token) public override whenNotPaused { + _checkTimeIsGreater(); + super.claimNonGoalLineItems(token); + } + /** * @inheritdoc ICampaignPaymentTreasury */ - function withdraw() public override whenCampaignNotPaused whenCampaignNotCancelled { + function withdraw() public override whenNotPaused whenNotCancelled { _checkTimeIsGreater(); super.withdraw(); } @@ -185,10 +176,7 @@ contract TimeConstrainedPaymentTreasury is * @dev This function is overridden to allow the platform admin and the campaign owner to cancel a treasury. */ function cancelTreasury(bytes32 message) public override { - if ( - _msgSender() != INFO.getPlatformAdminAddress(PLATFORM_HASH) && - _msgSender() != INFO.owner() - ) { + if (_msgSender() != INFO.getPlatformAdminAddress(PLATFORM_HASH) && _msgSender() != INFO.owner()) { revert TimeConstrainedPaymentTreasuryUnAuthorized(); } _cancel(message); @@ -197,13 +185,7 @@ contract TimeConstrainedPaymentTreasury is /** * @inheritdoc BasePaymentTreasury */ - function _checkSuccessCondition() - internal - view - virtual - override - returns (bool) - { + function _checkSuccessCondition() internal view virtual override returns (bool) { return true; } } diff --git a/src/utils/AdminAccessChecker.sol b/src/utils/AdminAccessChecker.sol index ac0a5050..d65d2e58 100644 --- a/src/utils/AdminAccessChecker.sol +++ b/src/utils/AdminAccessChecker.sol @@ -12,7 +12,6 @@ import {AdminAccessCheckerStorage} from "../storage/AdminAccessCheckerStorage.so * @dev Updated to use ERC-7201 namespaced storage for upgradeable contracts */ abstract contract AdminAccessChecker is Context { - /** * @dev Throws when the caller is not authorized. */ diff --git a/src/utils/BasePaymentTreasury.sol b/src/utils/BasePaymentTreasury.sol index feee6e77..f7e45f44 100644 --- a/src/utils/BasePaymentTreasury.sol +++ b/src/utils/BasePaymentTreasury.sol @@ -11,7 +11,12 @@ import {CampaignAccessChecker} from "./CampaignAccessChecker.sol"; import {PausableCancellable} from "./PausableCancellable.sol"; import {DataRegistryKeys} from "../constants/DataRegistryKeys.sol"; -abstract contract BasePaymentTreasury is +/** + * @title BasePaymentTreasury + * @notice Base contract for payment treasury implementations. + * @dev Supports ERC-2771 meta-transactions via adapter contracts for platform admin operations. + */ +abstract contract BasePaymentTreasury is Initializable, ICampaignPaymentTreasury, CampaignAccessChecker, @@ -20,20 +25,21 @@ abstract contract BasePaymentTreasury is { using SafeERC20 for IERC20; - bytes32 internal constant ZERO_BYTES = - 0x0000000000000000000000000000000000000000000000000000000000000000; + bytes32 internal constant ZERO_BYTES = 0x0000000000000000000000000000000000000000000000000000000000000000; uint256 internal constant PERCENT_DIVIDER = 10000; uint256 internal constant STANDARD_DECIMALS = 18; + address internal constant ZERO_ADDRESS = address(0); bytes32 internal PLATFORM_HASH; uint256 internal PLATFORM_FEE_PERCENT; - + // Multi-token support mapping(bytes32 => address) internal s_paymentIdToToken; // Track token used for each payment mapping(address => uint256) internal s_platformFeePerToken; // Platform fees per token mapping(address => uint256) internal s_protocolFeePerToken; // Protocol fees per token mapping(bytes32 => uint256) internal s_paymentIdToTokenId; // Track NFT token ID for each payment (0 means no NFT) - + mapping(bytes32 => address) internal s_paymentIdToCreator; // Track creator address for on-chain payments (for getPaymentData lookup) + /** * @dev Stores information about a payment in the treasury. * @param buyerAddress The address of the buyer who made the payment. @@ -56,20 +62,20 @@ abstract contract BasePaymentTreasury is uint256 lineItemCount; } - mapping (bytes32 => PaymentInfo) internal s_payment; - + mapping(bytes32 => PaymentInfo) internal s_payment; + // Combined line items with their configuration snapshots per payment ID - mapping (bytes32 => ICampaignPaymentTreasury.PaymentLineItem[]) internal s_paymentLineItems; // paymentId => array of stored line items - + mapping(bytes32 => ICampaignPaymentTreasury.PaymentLineItem[]) internal s_paymentLineItems; // paymentId => array of stored line items + // External fee metadata per payment ID (information only, no financial impact) - mapping (bytes32 => ICampaignPaymentTreasury.ExternalFees[]) internal s_paymentExternalFeeMetadata; // paymentId => array of external fee metadata - + mapping(bytes32 => ICampaignPaymentTreasury.ExternalFees[]) internal s_paymentExternalFeeMetadata; // paymentId => array of external fee metadata + // Multi-token balances (all in token's native decimals) mapping(address => uint256) internal s_pendingPaymentPerToken; // Pending payment amounts per token mapping(address => uint256) internal s_confirmedPaymentPerToken; // Confirmed payment amounts per token (decreases on refunds) mapping(address => uint256) internal s_lifetimeConfirmedPaymentPerToken; // Lifetime confirmed payment amounts per token (never decreases) mapping(address => uint256) internal s_availableConfirmedPerToken; // Available confirmed amounts per token - + // Tracking for non-goal line items (countTowardsGoal = False) per token mapping(address => uint256) internal s_nonGoalLineItemPendingPerToken; // Pending non-goal line items per token mapping(address => uint256) internal s_nonGoalLineItemConfirmedPerToken; // Confirmed non-goal line items per token @@ -102,33 +108,25 @@ abstract contract BasePaymentTreasury is * @dev Emitted when a payment is cancelled and removed from the treasury. * @param paymentId The unique identifier of the cancelled payment. */ - event PaymentCancelled( - bytes32 indexed paymentId - ); + event PaymentCancelled(bytes32 indexed paymentId); /** * @dev Emitted when a payment is confirmed. * @param paymentId The unique identifier of the confirmed payment. */ - event PaymentConfirmed( - bytes32 indexed paymentId - ); + event PaymentConfirmed(bytes32 indexed paymentId); /** * @dev Emitted when multiple payments are confirmed in a single batch operation. * @param paymentIds An array of unique identifiers for the confirmed payments. */ - event PaymentBatchConfirmed( - bytes32[] paymentIds - ); + event PaymentBatchConfirmed(bytes32[] paymentIds); /** * @dev Emitted when multiple payments are created in a single batch operation. * @param paymentIds An array of unique identifiers for the created payments. */ - event PaymentBatchCreated( - bytes32[] paymentIds - ); + event PaymentBatchCreated(bytes32[] paymentIds); /** * @notice Emitted when fees are successfully disbursed. @@ -269,16 +267,66 @@ abstract contract BasePaymentTreasury is */ error PaymentTreasuryNoFundsToClaim(); + /** + * @dev Scopes a payment ID for off-chain payments (createPayment/createPaymentBatch). + * @param paymentId The external payment ID. + * @return The scoped internal payment ID. + */ + function _scopePaymentIdForOffChain(bytes32 paymentId) internal pure returns (bytes32) { + return keccak256(abi.encodePacked(paymentId, ZERO_ADDRESS)); + } + + /** + * @dev Scopes a payment ID for on-chain crypto payments (processCryptoPayment). + * @param paymentId The external payment ID. + * @return The scoped internal payment ID. + */ + function _scopePaymentIdForOnChain(bytes32 paymentId) internal view returns (bytes32) { + return keccak256(abi.encodePacked(paymentId, _msgSender())); + } + + /** + * @dev Tries to find a payment by checking both off-chain and on-chain scopes. + * - Off-chain payments (createPayment) can be looked up by anyone (scoped with address(0)) + * - On-chain payments (processCryptoPayment) can be looked up by anyone using the stored creator address + * @param paymentId The external payment ID. + * @return internalPaymentId The scoped internal payment ID if found, or ZERO_BYTES if not found. + */ + function _findPaymentId(bytes32 paymentId) internal view returns (bytes32 internalPaymentId) { + // Try off-chain scope first (for createPayment) - anyone can look these up + internalPaymentId = _scopePaymentIdForOffChain(paymentId); + if ( + s_payment[internalPaymentId].buyerId != ZERO_BYTES + || s_payment[internalPaymentId].buyerAddress != address(0) + ) { + return internalPaymentId; + } + + // Try on-chain scope (for processCryptoPayment) - use stored creator address + // Since paymentIds are globally unique, there's only one creator per paymentId + address creatorAddress = s_paymentIdToCreator[paymentId]; + if (creatorAddress != address(0)) { + internalPaymentId = keccak256(abi.encodePacked(paymentId, creatorAddress)); + if ( + s_payment[internalPaymentId].buyerId != ZERO_BYTES + || s_payment[internalPaymentId].buyerAddress != address(0) + ) { + return internalPaymentId; + } + } + + // Not found in either scope + return ZERO_BYTES; + } + /** * @dev Retrieves the max expiration duration configured for the current platform or globally. * @return hasLimit Indicates whether a max expiration duration is configured. * @return duration The max expiration duration in seconds. */ function _getMaxExpirationDuration() internal view returns (bool hasLimit, uint256 duration) { - bytes32 platformScopedKey = DataRegistryKeys.scopedToPlatform( - DataRegistryKeys.MAX_PAYMENT_EXPIRATION, - PLATFORM_HASH - ); + bytes32 platformScopedKey = + DataRegistryKeys.scopedToPlatform(DataRegistryKeys.MAX_PAYMENT_EXPIRATION, PLATFORM_HASH); // Prefer platform-specific value stored in GlobalParams via registry. bytes32 maxExpirationBytes = INFO.getDataFromRegistry(platformScopedKey); @@ -300,13 +348,25 @@ abstract contract BasePaymentTreasury is hasLimit = true; } - function __BaseContract_init( - bytes32 platformHash, - address infoAddress - ) internal { + function __BaseContract_init(bytes32 platformHash, address infoAddress, address trustedForwarder_) internal { __CampaignAccessChecker_init(infoAddress); PLATFORM_HASH = platformHash; PLATFORM_FEE_PERCENT = INFO.getPlatformFeePercent(platformHash); + _trustedForwarder = trustedForwarder_; + } + + /** + * @dev Override _msgSender to support ERC-2771 meta-transactions. + * When called by the trusted forwarder (adapter), extracts the actual sender from calldata. + */ + function _msgSender() internal view virtual override returns (address sender) { + if (msg.sender == _trustedForwarder && msg.data.length >= 20) { + assembly { + sender := shr(96, calldataload(sub(calldatasize(), 20))) + } + } else { + sender = msg.sender; + } } /** @@ -322,6 +382,18 @@ abstract contract BasePaymentTreasury is _; } + /** + * @dev Restricts access to only the platform admin or the campaign owner. + * @dev Checks if `_msgSender()` is either the platform admin (via `INFO.getPlatformAdminAddress`) + * or the campaign owner (via `INFO.owner()`). Reverts with `AccessCheckerUnauthorized` if not authorized. + */ + modifier onlyPlatformAdminOrCampaignOwner() { + if (_msgSender() != INFO.getPlatformAdminAddress(PLATFORM_HASH) && _msgSender() != INFO.owner()) { + revert AccessCheckerUnauthorized(); + } + _; + } + /** * @inheritdoc ICampaignPaymentTreasury */ @@ -339,10 +411,10 @@ abstract contract BasePaymentTreasury is /** * @inheritdoc ICampaignPaymentTreasury */ - function getRaisedAmount() public view override virtual returns (uint256) { + function getRaisedAmount() public view virtual override returns (uint256) { address[] memory acceptedTokens = INFO.getAcceptedTokens(); uint256 totalNormalized = 0; - + for (uint256 i = 0; i < acceptedTokens.length; i++) { address token = acceptedTokens[i]; uint256 amount = s_confirmedPaymentPerToken[token]; @@ -350,7 +422,7 @@ abstract contract BasePaymentTreasury is totalNormalized += _normalizeAmount(token, amount); } } - + return totalNormalized; } @@ -360,7 +432,7 @@ abstract contract BasePaymentTreasury is function getAvailableRaisedAmount() external view returns (uint256) { address[] memory acceptedTokens = INFO.getAcceptedTokens(); uint256 totalNormalized = 0; - + for (uint256 i = 0; i < acceptedTokens.length; i++) { address token = acceptedTokens[i]; uint256 amount = s_availableConfirmedPerToken[token]; @@ -368,7 +440,7 @@ abstract contract BasePaymentTreasury is totalNormalized += _normalizeAmount(token, amount); } } - + return totalNormalized; } @@ -378,7 +450,7 @@ abstract contract BasePaymentTreasury is function getLifetimeRaisedAmount() external view returns (uint256) { address[] memory acceptedTokens = INFO.getAcceptedTokens(); uint256 totalNormalized = 0; - + for (uint256 i = 0; i < acceptedTokens.length; i++) { address token = acceptedTokens[i]; uint256 amount = s_lifetimeConfirmedPaymentPerToken[token]; @@ -386,7 +458,7 @@ abstract contract BasePaymentTreasury is totalNormalized += _normalizeAmount(token, amount); } } - + return totalNormalized; } @@ -396,7 +468,7 @@ abstract contract BasePaymentTreasury is function getRefundedAmount() external view returns (uint256) { address[] memory acceptedTokens = INFO.getAcceptedTokens(); uint256 totalNormalized = 0; - + for (uint256 i = 0; i < acceptedTokens.length; i++) { address token = acceptedTokens[i]; uint256 lifetimeAmount = s_lifetimeConfirmedPaymentPerToken[token]; @@ -406,7 +478,7 @@ abstract contract BasePaymentTreasury is totalNormalized += _normalizeAmount(token, refundedAmount); } } - + return totalNormalized; } @@ -416,7 +488,7 @@ abstract contract BasePaymentTreasury is function getExpectedAmount() external view returns (uint256) { address[] memory acceptedTokens = INFO.getAcceptedTokens(); uint256 totalNormalized = 0; - + for (uint256 i = 0; i < acceptedTokens.length; i++) { address token = acceptedTokens[i]; uint256 amount = s_pendingPaymentPerToken[token]; @@ -424,22 +496,19 @@ abstract contract BasePaymentTreasury is totalNormalized += _normalizeAmount(token, amount); } } - + return totalNormalized; } - + /** * @dev Normalizes token amounts to 18 decimals for consistent comparisons. * @param token The token address. * @param amount The amount to normalize. * @return The normalized amount (scaled to 18 decimals). */ - function _normalizeAmount( - address token, - uint256 amount - ) internal view returns (uint256) { + function _normalizeAmount(address token, uint256 amount) internal view returns (uint256) { uint8 decimals = IERC20Metadata(token).decimals(); - + if (decimals == STANDARD_DECIMALS) { return amount; } else if (decimals < STANDARD_DECIMALS) { @@ -474,12 +543,12 @@ abstract contract BasePaymentTreasury is ) internal { for (uint256 i = 0; i < lineItems.length; i++) { ICampaignPaymentTreasury.LineItem calldata item = lineItems[i]; - + // Validate line item if (item.typeId == ZERO_BYTES || item.amount == 0) { revert PaymentTreasuryInvalidInput(); } - + // Get line item type configuration (single call per item) ( bool exists, @@ -489,22 +558,24 @@ abstract contract BasePaymentTreasury is bool canRefund, bool instantTransfer ) = INFO.getLineItemType(PLATFORM_HASH, item.typeId); - + if (!exists) { revert PaymentTreasuryInvalidInput(); } - + // Store line item with configuration snapshot - s_paymentLineItems[paymentId].push(ICampaignPaymentTreasury.PaymentLineItem({ - typeId: item.typeId, - amount: item.amount, - label: label, - countsTowardGoal: countsTowardGoal, - applyProtocolFee: applyProtocolFee, - canRefund: canRefund, - instantTransfer: instantTransfer - })); - + s_paymentLineItems[paymentId].push( + ICampaignPaymentTreasury.PaymentLineItem({ + typeId: item.typeId, + amount: item.amount, + label: label, + countsTowardGoal: countsTowardGoal, + applyProtocolFee: applyProtocolFee, + canRefund: canRefund, + instantTransfer: instantTransfer + }) + ); + // Track pending amounts based on whether it counts toward goal if (countsTowardGoal) { s_pendingPaymentPerToken[paymentToken] += item.amount; @@ -526,15 +597,11 @@ abstract contract BasePaymentTreasury is uint256 expiration, ICampaignPaymentTreasury.LineItem[] calldata lineItems, ICampaignPaymentTreasury.ExternalFees[] calldata externalFees - ) public override virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { - - if(buyerId == ZERO_BYTES || - amount == 0 || - expiration <= block.timestamp || - paymentId == ZERO_BYTES || - itemId == ZERO_BYTES || - paymentToken == address(0) - ){ + ) public virtual override onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { + if ( + buyerId == ZERO_BYTES || amount == 0 || expiration <= block.timestamp || paymentId == ZERO_BYTES + || itemId == ZERO_BYTES || paymentToken == address(0) + ) { revert PaymentTreasuryInvalidInput(); } @@ -552,11 +619,22 @@ abstract contract BasePaymentTreasury is revert PaymentTreasuryTokenNotAccepted(paymentToken); } - if(s_payment[paymentId].buyerId != ZERO_BYTES || s_payment[paymentId].buyerAddress != address(0)){ - revert PaymentTreasuryPaymentAlreadyExist(paymentId); + // Check if an on-chain payment with the same paymentId already exists + address creatorAddress = s_paymentIdToCreator[paymentId]; + if (creatorAddress != address(0)) { + bytes32 onChainPaymentId = keccak256(abi.encodePacked(paymentId, creatorAddress)); + revert PaymentTreasuryPaymentAlreadyExist(onChainPaymentId); + } + + bytes32 internalPaymentId = _scopePaymentIdForOffChain(paymentId); + if ( + s_payment[internalPaymentId].buyerId != ZERO_BYTES + || s_payment[internalPaymentId].buyerAddress != address(0) + ) { + revert PaymentTreasuryPaymentAlreadyExist(internalPaymentId); } - s_payment[paymentId] = PaymentInfo({ + s_payment[internalPaymentId] = PaymentInfo({ buyerId: buyerId, buyerAddress: address(0), itemId: itemId, @@ -568,30 +646,22 @@ abstract contract BasePaymentTreasury is }); // Validate, store, and track line items - _validateStoreAndTrackLineItems(paymentId, lineItems, paymentToken); + _validateStoreAndTrackLineItems(internalPaymentId, lineItems, paymentToken); // Store external fee metadata for informational purposes only - ICampaignPaymentTreasury.ExternalFees[] storage externalFeeMetadata = s_paymentExternalFeeMetadata[paymentId]; - for (uint256 i = 0; i < externalFees.length; ) { + ICampaignPaymentTreasury.ExternalFees[] storage externalFeeMetadata = + s_paymentExternalFeeMetadata[internalPaymentId]; + for (uint256 i = 0; i < externalFees.length;) { externalFeeMetadata.push(externalFees[i]); unchecked { ++i; } } - s_paymentIdToToken[paymentId] = paymentToken; + s_paymentIdToToken[internalPaymentId] = paymentToken; s_pendingPaymentPerToken[paymentToken] += amount; - emit PaymentCreated( - address(0), - paymentId, - buyerId, - itemId, - paymentToken, - amount, - expiration, - false - ); + emit PaymentCreated(address(0), paymentId, buyerId, itemId, paymentToken, amount, expiration, false); } /** @@ -606,18 +676,14 @@ abstract contract BasePaymentTreasury is uint256[] calldata expirations, ICampaignPaymentTreasury.LineItem[][] calldata lineItemsArray, ICampaignPaymentTreasury.ExternalFees[][] calldata externalFeesArray - ) public override virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { - + ) public virtual override onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { // Validate array lengths are consistent uint256 length = paymentIds.length; - if (length == 0 || - length != buyerIds.length || - length != itemIds.length || - length != paymentTokens.length || - length != amounts.length || - length != expirations.length || - length != lineItemsArray.length || - length != externalFeesArray.length) { + if ( + length == 0 || length != buyerIds.length || length != itemIds.length || length != paymentTokens.length + || length != amounts.length || length != expirations.length || length != lineItemsArray.length + || length != externalFeesArray.length + ) { revert PaymentTreasuryInvalidInput(); } @@ -639,13 +705,10 @@ abstract contract BasePaymentTreasury is ICampaignPaymentTreasury.LineItem[] calldata lineItems = lineItemsArray[i]; // Validate individual payment parameters - if(buyerId == ZERO_BYTES || - amount == 0 || - expiration <= block.timestamp || - paymentId == ZERO_BYTES || - itemId == ZERO_BYTES || - paymentToken == address(0) - ){ + if ( + buyerId == ZERO_BYTES || amount == 0 || expiration <= block.timestamp || paymentId == ZERO_BYTES + || itemId == ZERO_BYTES || paymentToken == address(0) + ) { revert PaymentTreasuryInvalidInput(); } @@ -659,13 +722,24 @@ abstract contract BasePaymentTreasury is revert PaymentTreasuryTokenNotAccepted(paymentToken); } + // Check if an on-chain payment with the same paymentId already exists + address creatorAddress = s_paymentIdToCreator[paymentId]; + if (creatorAddress != address(0)) { + bytes32 onChainPaymentId = keccak256(abi.encodePacked(paymentId, creatorAddress)); + revert PaymentTreasuryPaymentAlreadyExist(onChainPaymentId); + } + + bytes32 internalPaymentId = _scopePaymentIdForOffChain(paymentId); // Check if payment already exists - if(s_payment[paymentId].buyerId != ZERO_BYTES || s_payment[paymentId].buyerAddress != address(0)){ - revert PaymentTreasuryPaymentAlreadyExist(paymentId); + if ( + s_payment[internalPaymentId].buyerId != ZERO_BYTES + || s_payment[internalPaymentId].buyerAddress != address(0) + ) { + revert PaymentTreasuryPaymentAlreadyExist(internalPaymentId); } // Create the payment - s_payment[paymentId] = PaymentInfo({ + s_payment[internalPaymentId] = PaymentInfo({ buyerId: buyerId, buyerAddress: address(0), itemId: itemId, @@ -677,31 +751,23 @@ abstract contract BasePaymentTreasury is }); // Validate, store, and track line items in a single loop - _validateStoreAndTrackLineItems(paymentId, lineItems, paymentToken); + _validateStoreAndTrackLineItems(internalPaymentId, lineItems, paymentToken); // Store external fee metadata for informational purposes only ICampaignPaymentTreasury.ExternalFees[] calldata externalFees = externalFeesArray[i]; - ICampaignPaymentTreasury.ExternalFees[] storage externalFeeMetadata = s_paymentExternalFeeMetadata[paymentId]; - for (uint256 j = 0; j < externalFees.length; ) { + ICampaignPaymentTreasury.ExternalFees[] storage externalFeeMetadata = + s_paymentExternalFeeMetadata[internalPaymentId]; + for (uint256 j = 0; j < externalFees.length;) { externalFeeMetadata.push(externalFees[j]); unchecked { ++j; } } - s_paymentIdToToken[paymentId] = paymentToken; + s_paymentIdToToken[internalPaymentId] = paymentToken; s_pendingPaymentPerToken[paymentToken] += amount; - emit PaymentCreated( - address(0), - paymentId, - buyerId, - itemId, - paymentToken, - amount, - expiration, - false - ); + emit PaymentCreated(address(0), paymentId, buyerId, itemId, paymentToken, amount, expiration, false); unchecked { ++i; @@ -722,14 +788,11 @@ abstract contract BasePaymentTreasury is uint256 amount, ICampaignPaymentTreasury.LineItem[] calldata lineItems, ICampaignPaymentTreasury.ExternalFees[] calldata externalFees - ) public override virtual nonReentrant whenCampaignNotPaused whenCampaignNotCancelled { - - if(buyerAddress == address(0) || - amount == 0 || - paymentId == ZERO_BYTES || - itemId == ZERO_BYTES || - paymentToken == address(0) - ){ + ) public virtual override nonReentrant whenCampaignNotPaused whenCampaignNotCancelled { + if ( + buyerAddress == address(0) || amount == 0 || paymentId == ZERO_BYTES || itemId == ZERO_BYTES + || paymentToken == address(0) + ) { revert PaymentTreasuryInvalidInput(); } @@ -738,8 +801,29 @@ abstract contract BasePaymentTreasury is revert PaymentTreasuryTokenNotAccepted(paymentToken); } - if(s_payment[paymentId].buyerAddress != address(0) || s_payment[paymentId].buyerId != ZERO_BYTES){ - revert PaymentTreasuryPaymentAlreadyExist(paymentId); + // Check if an off-chain payment with the same paymentId already exists + bytes32 offChainPaymentId = _scopePaymentIdForOffChain(paymentId); + if ( + s_payment[offChainPaymentId].buyerId != ZERO_BYTES + || s_payment[offChainPaymentId].buyerAddress != address(0) + ) { + revert PaymentTreasuryPaymentAlreadyExist(offChainPaymentId); + } + + // Check if any on-chain payment with the same paymentId already exists (globally unique) + if (s_paymentIdToCreator[paymentId] != address(0)) { + address existingCreator = s_paymentIdToCreator[paymentId]; + bytes32 existingPaymentId = keccak256(abi.encodePacked(paymentId, existingCreator)); + revert PaymentTreasuryPaymentAlreadyExist(existingPaymentId); + } + + // Check if an on-chain payment with the same paymentId already exists for this caller + bytes32 internalPaymentId = _scopePaymentIdForOnChain(paymentId); + if ( + s_payment[internalPaymentId].buyerAddress != address(0) + || s_payment[internalPaymentId].buyerId != ZERO_BYTES + ) { + revert PaymentTreasuryPaymentAlreadyExist(internalPaymentId); } // Validate, calculate total, store, and process line items @@ -750,12 +834,12 @@ abstract contract BasePaymentTreasury is for (uint256 i = 0; i < lineItems.length; i++) { ICampaignPaymentTreasury.LineItem calldata item = lineItems[i]; - + // Validate line item if (item.typeId == ZERO_BYTES || item.amount == 0) { revert PaymentTreasuryInvalidInput(); } - + // Get line item type configuration (single call per item) ( bool exists, @@ -765,25 +849,27 @@ abstract contract BasePaymentTreasury is bool canRefund, bool instantTransfer ) = INFO.getLineItemType(PLATFORM_HASH, item.typeId); - + if (!exists) { revert PaymentTreasuryInvalidInput(); } - + // Accumulate total amount totalAmount += item.amount; - + // Store line item with configuration snapshot - s_paymentLineItems[paymentId].push(ICampaignPaymentTreasury.PaymentLineItem({ - typeId: item.typeId, - amount: item.amount, - label: label, - countsTowardGoal: countsTowardGoal, - applyProtocolFee: applyProtocolFee, - canRefund: canRefund, - instantTransfer: instantTransfer - })); - + s_paymentLineItems[internalPaymentId].push( + ICampaignPaymentTreasury.PaymentLineItem({ + typeId: item.typeId, + amount: item.amount, + label: label, + countsTowardGoal: countsTowardGoal, + applyProtocolFee: applyProtocolFee, + canRefund: canRefund, + instantTransfer: instantTransfer + }) + ); + // Process line items immediately since crypto payment is confirmed if (countsTowardGoal) { // Line items that count toward goal use existing tracking variables @@ -799,14 +885,14 @@ abstract contract BasePaymentTreasury is s_protocolFeePerToken[paymentToken] += protocolFee; } uint256 netAmount = item.amount - feeAmount; - + if (instantTransfer) { // Accumulate for batch transfer after loop totalInstantTransferAmount += netAmount; } else { // Track outstanding non-goal balances using net amounts (after fees) s_nonGoalLineItemConfirmedPerToken[paymentToken] += netAmount; - + if (canRefund) { s_refundableNonGoalLineItemPerToken[paymentToken] += netAmount; } else { @@ -817,8 +903,9 @@ abstract contract BasePaymentTreasury is } // Store external fee metadata for informational purposes only - ICampaignPaymentTreasury.ExternalFees[] storage externalFeeMetadata = s_paymentExternalFeeMetadata[paymentId]; - for (uint256 i = 0; i < externalFees.length; ) { + ICampaignPaymentTreasury.ExternalFees[] storage externalFeeMetadata = + s_paymentExternalFeeMetadata[internalPaymentId]; + for (uint256 i = 0; i < externalFees.length;) { externalFeeMetadata.push(externalFees[i]); unchecked { ++i; @@ -827,18 +914,19 @@ abstract contract BasePaymentTreasury is IERC20(paymentToken).safeTransferFrom(buyerAddress, address(this), totalAmount); - s_payment[paymentId] = PaymentInfo({ + s_payment[internalPaymentId] = PaymentInfo({ buyerId: ZERO_BYTES, buyerAddress: buyerAddress, itemId: itemId, amount: amount, // Amount in token's native decimals - expiration: 0, - isConfirmed: true, + expiration: 0, + isConfirmed: true, isCryptoPayment: true, lineItemCount: lineItems.length }); - s_paymentIdToToken[paymentId] = paymentToken; + s_paymentIdToToken[internalPaymentId] = paymentToken; + s_paymentIdToCreator[paymentId] = _msgSender(); // Store creator address for getPaymentData lookup s_confirmedPaymentPerToken[paymentToken] += amount; s_lifetimeConfirmedPaymentPerToken[paymentToken] += amount; s_availableConfirmedPerToken[paymentToken] += amount; @@ -854,34 +942,30 @@ abstract contract BasePaymentTreasury is paymentToken, amount, 0, // shippingFee (0 for payment treasuries) - 0 // tipAmount (0 for payment treasuries) + 0 // tipAmount (0 for payment treasuries) ); - s_paymentIdToTokenId[paymentId] = tokenId; + s_paymentIdToTokenId[internalPaymentId] = tokenId; - emit PaymentCreated( - buyerAddress, - paymentId, - ZERO_BYTES, - itemId, - paymentToken, - amount, - 0, - true - ); + emit PaymentCreated(buyerAddress, paymentId, ZERO_BYTES, itemId, paymentToken, amount, 0, true); } /** * @inheritdoc ICampaignPaymentTreasury */ - function cancelPayment( - bytes32 paymentId - ) public override virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { - - _validatePaymentForAction(paymentId); + function cancelPayment(bytes32 paymentId) + public + virtual + override + onlyPlatformAdmin(PLATFORM_HASH) + whenCampaignNotPaused + whenCampaignNotCancelled + { + bytes32 internalPaymentId = _scopePaymentIdForOffChain(paymentId); + _validatePaymentForAction(internalPaymentId); - address paymentToken = s_paymentIdToToken[paymentId]; - uint256 amount = s_payment[paymentId].amount; - ICampaignPaymentTreasury.PaymentLineItem[] storage lineItems = s_paymentLineItems[paymentId]; + address paymentToken = s_paymentIdToToken[internalPaymentId]; + uint256 amount = s_payment[internalPaymentId].amount; + ICampaignPaymentTreasury.PaymentLineItem[] storage lineItems = s_paymentLineItems[internalPaymentId]; // Remove pending tracking for line items using snapshot from payment creation // This prevents issues if line item type configuration changed after payment creation @@ -894,10 +978,10 @@ abstract contract BasePaymentTreasury is } } - delete s_payment[paymentId]; - delete s_paymentIdToToken[paymentId]; - delete s_paymentLineItems[paymentId]; - delete s_paymentExternalFeeMetadata[paymentId]; + delete s_payment[internalPaymentId]; + delete s_paymentIdToToken[internalPaymentId]; + delete s_paymentLineItems[internalPaymentId]; + delete s_paymentExternalFeeMetadata[internalPaymentId]; s_pendingPaymentPerToken[paymentToken] -= amount; @@ -916,7 +1000,7 @@ abstract contract BasePaymentTreasury is ) internal view returns (LineItemTotals memory totals) { for (uint256 i = 0; i < lineItems.length; i++) { ICampaignPaymentTreasury.PaymentLineItem memory item = lineItems[i]; - + bool countsTowardGoal = item.countsTowardGoal; bool applyProtocolFee = item.applyProtocolFee; bool instantTransfer = item.instantTransfer; @@ -930,9 +1014,9 @@ abstract contract BasePaymentTreasury is totals.totalProtocolFeeFromLineItems += protocolFee; feeAmount += protocolFee; } - + uint256 netAmount = item.amount - feeAmount; - + if (instantTransfer) { totals.totalInstantTransferAmountForCheck += netAmount; } else if (item.canRefund) { @@ -950,29 +1034,22 @@ abstract contract BasePaymentTreasury is * @param paymentAmount The base payment amount. * @param totals Line item totals struct. */ - function _checkBalanceForConfirmation( - address paymentToken, - uint256 paymentAmount, - LineItemTotals memory totals - ) internal view { + function _checkBalanceForConfirmation(address paymentToken, uint256 paymentAmount, LineItemTotals memory totals) + internal + view + { uint256 actualBalance = IERC20(paymentToken).balanceOf(address(this)); - uint256 currentlyCommitted = s_availableConfirmedPerToken[paymentToken] + - s_protocolFeePerToken[paymentToken] + - s_platformFeePerToken[paymentToken] + - s_nonGoalLineItemClaimablePerToken[paymentToken] + - s_refundableNonGoalLineItemPerToken[paymentToken]; - - uint256 newCommitted = currentlyCommitted + - paymentAmount + - totals.totalGoalLineItemAmount + - totals.totalProtocolFeeFromLineItems + - totals.totalNonGoalClaimableAmount + - totals.totalNonGoalRefundableAmount; - + uint256 currentlyCommitted = s_availableConfirmedPerToken[paymentToken] + s_protocolFeePerToken[paymentToken] + + s_platformFeePerToken[paymentToken] + s_nonGoalLineItemClaimablePerToken[paymentToken] + + s_refundableNonGoalLineItemPerToken[paymentToken]; + + uint256 newCommitted = currentlyCommitted + paymentAmount + totals.totalGoalLineItemAmount + + totals.totalProtocolFeeFromLineItems + totals.totalNonGoalClaimableAmount + + totals.totalNonGoalRefundableAmount; + if (newCommitted + totals.totalInstantTransferAmountForCheck > actualBalance) { revert PaymentTreasuryInsufficientBalance( - newCommitted + totals.totalInstantTransferAmountForCheck, - actualBalance + newCommitted + totals.totalInstantTransferAmountForCheck, actualBalance ); } } @@ -991,7 +1068,7 @@ abstract contract BasePaymentTreasury is ) internal returns (uint256 totalInstantTransferAmount) { for (uint256 i = 0; i < lineItems.length; i++) { ICampaignPaymentTreasury.PaymentLineItem memory item = lineItems[i]; - + bool countsTowardGoal = item.countsTowardGoal; bool applyProtocolFee = item.applyProtocolFee; bool canRefund = item.canRefund; @@ -1004,23 +1081,23 @@ abstract contract BasePaymentTreasury is s_availableConfirmedPerToken[paymentToken] += item.amount; } else { s_nonGoalLineItemPendingPerToken[paymentToken] -= item.amount; - + uint256 feeAmount = 0; if (applyProtocolFee) { uint256 protocolFee = (item.amount * protocolFeePercent) / PERCENT_DIVIDER; feeAmount += protocolFee; s_protocolFeePerToken[paymentToken] += protocolFee; } - + uint256 netAmount = item.amount - feeAmount; - + if (instantTransfer) { totalInstantTransferAmount += netAmount; // Instant transfer items are not tracked in s_nonGoalLineItemConfirmedPerToken } else { // Track outstanding non-goal balances using net amounts (after fees) s_nonGoalLineItemConfirmedPerToken[paymentToken] += netAmount; - + if (canRefund) { s_refundableNonGoalLineItemPerToken[paymentToken] += netAmount; } else { @@ -1034,124 +1111,114 @@ abstract contract BasePaymentTreasury is /** * @inheritdoc ICampaignPaymentTreasury */ - function confirmPayment( - bytes32 paymentId, - address buyerAddress - ) public override virtual nonReentrant onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { - _validatePaymentForAction(paymentId); - - address paymentToken = s_paymentIdToToken[paymentId]; - uint256 paymentAmount = s_payment[paymentId].amount; - ICampaignPaymentTreasury.PaymentLineItem[] storage lineItems = s_paymentLineItems[paymentId]; - + function confirmPayment(bytes32 paymentId, address buyerAddress) + public + virtual + override + nonReentrant + onlyPlatformAdmin(PLATFORM_HASH) + whenCampaignNotPaused + whenCampaignNotCancelled + { + bytes32 internalPaymentId = _scopePaymentIdForOffChain(paymentId); + _validatePaymentForAction(internalPaymentId); + + address paymentToken = s_paymentIdToToken[internalPaymentId]; + uint256 paymentAmount = s_payment[internalPaymentId].amount; + ICampaignPaymentTreasury.PaymentLineItem[] storage lineItems = s_paymentLineItems[internalPaymentId]; + uint256 protocolFeePercent = INFO.getProtocolFeePercent(); LineItemTotals memory totals = _calculateLineItemTotals(lineItems, protocolFeePercent); - + _checkBalanceForConfirmation(paymentToken, paymentAmount, totals); - - totals.totalInstantTransferAmount = _updateLineItemsForConfirmation( - paymentToken, - lineItems, - protocolFeePercent - ); - - s_payment[paymentId].isConfirmed = true; + + totals.totalInstantTransferAmount = _updateLineItemsForConfirmation(paymentToken, lineItems, protocolFeePercent); + + s_payment[internalPaymentId].isConfirmed = true; s_pendingPaymentPerToken[paymentToken] -= paymentAmount; s_confirmedPaymentPerToken[paymentToken] += paymentAmount; s_lifetimeConfirmedPaymentPerToken[paymentToken] += paymentAmount; s_availableConfirmedPerToken[paymentToken] += paymentAmount; - + if (totals.totalInstantTransferAmount > 0) { address platformAdmin = INFO.getPlatformAdminAddress(PLATFORM_HASH); IERC20(paymentToken).safeTransfer(platformAdmin, totals.totalInstantTransferAmount); } - + if (buyerAddress != address(0)) { - s_payment[paymentId].buyerAddress = buyerAddress; - bytes32 itemId = s_payment[paymentId].itemId; - uint256 tokenId = INFO.mintNFTForPledge( - buyerAddress, - itemId, - paymentToken, - paymentAmount, - 0, - 0 - ); - s_paymentIdToTokenId[paymentId] = tokenId; + s_payment[internalPaymentId].buyerAddress = buyerAddress; + bytes32 itemId = s_payment[internalPaymentId].itemId; + uint256 tokenId = INFO.mintNFTForPledge(buyerAddress, itemId, paymentToken, paymentAmount, 0, 0); + s_paymentIdToTokenId[internalPaymentId] = tokenId; } - + emit PaymentConfirmed(paymentId); } /** * @inheritdoc ICampaignPaymentTreasury */ - function confirmPaymentBatch( - bytes32[] calldata paymentIds, - address[] calldata buyerAddresses - ) public override virtual nonReentrant onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled { - + function confirmPaymentBatch(bytes32[] calldata paymentIds, address[] calldata buyerAddresses) + public + virtual + override + nonReentrant + onlyPlatformAdmin(PLATFORM_HASH) + whenCampaignNotPaused + whenCampaignNotCancelled + { // Validate array lengths must match if (buyerAddresses.length != paymentIds.length) { revert PaymentTreasuryInvalidInput(); } - + bytes32 currentPaymentId; address currentToken; - + uint256 protocolFeePercent = INFO.getProtocolFeePercent(); address platformAdmin = INFO.getPlatformAdminAddress(PLATFORM_HASH); - - for(uint256 i = 0; i < paymentIds.length;){ + + for (uint256 i = 0; i < paymentIds.length;) { currentPaymentId = paymentIds[i]; - - _validatePaymentForAction(currentPaymentId); - - currentToken = s_paymentIdToToken[currentPaymentId]; - uint256 amount = s_payment[currentPaymentId].amount; - ICampaignPaymentTreasury.PaymentLineItem[] storage lineItems = s_paymentLineItems[currentPaymentId]; - + bytes32 internalPaymentId = _scopePaymentIdForOffChain(currentPaymentId); + + _validatePaymentForAction(internalPaymentId); + + currentToken = s_paymentIdToToken[internalPaymentId]; + uint256 amount = s_payment[internalPaymentId].amount; + ICampaignPaymentTreasury.PaymentLineItem[] storage lineItems = s_paymentLineItems[internalPaymentId]; + LineItemTotals memory totals = _calculateLineItemTotals(lineItems, protocolFeePercent); _checkBalanceForConfirmation(currentToken, amount, totals); - - totals.totalInstantTransferAmount = _updateLineItemsForConfirmation( - currentToken, - lineItems, - protocolFeePercent - ); - - s_payment[currentPaymentId].isConfirmed = true; - + + totals.totalInstantTransferAmount = + _updateLineItemsForConfirmation(currentToken, lineItems, protocolFeePercent); + + s_payment[internalPaymentId].isConfirmed = true; + s_pendingPaymentPerToken[currentToken] -= amount; s_confirmedPaymentPerToken[currentToken] += amount; s_lifetimeConfirmedPaymentPerToken[currentToken] += amount; s_availableConfirmedPerToken[currentToken] += amount; - + if (totals.totalInstantTransferAmount > 0) { IERC20(currentToken).safeTransfer(platformAdmin, totals.totalInstantTransferAmount); } if (buyerAddresses[i] != address(0)) { address buyerAddress = buyerAddresses[i]; - s_payment[currentPaymentId].buyerAddress = buyerAddress; - bytes32 itemId = s_payment[currentPaymentId].itemId; - uint256 tokenId = INFO.mintNFTForPledge( - buyerAddress, - itemId, - currentToken, - amount, - 0, - 0 - ); - s_paymentIdToTokenId[currentPaymentId] = tokenId; + s_payment[internalPaymentId].buyerAddress = buyerAddress; + bytes32 itemId = s_payment[internalPaymentId].itemId; + uint256 tokenId = INFO.mintNFTForPledge(buyerAddress, itemId, currentToken, amount, 0, 0); + s_paymentIdToTokenId[internalPaymentId] = tokenId; } unchecked { ++i; } } - + emit PaymentBatchConfirmed(paymentIds); } @@ -1159,51 +1226,55 @@ abstract contract BasePaymentTreasury is * @inheritdoc ICampaignPaymentTreasury * @dev For non-NFT payments only. Verifies that no NFT exists for this payment. */ - function claimRefund( - bytes32 paymentId, - address refundAddress - ) public override virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused whenCampaignNotCancelled + function claimRefund(bytes32 paymentId, address refundAddress) + public + virtual + override + onlyPlatformAdmin(PLATFORM_HASH) + whenCampaignNotPaused + whenCampaignNotCancelled { - if(refundAddress == address(0)){ + if (refundAddress == address(0)) { revert PaymentTreasuryInvalidInput(); } - PaymentInfo memory payment = s_payment[paymentId]; - address paymentToken = s_paymentIdToToken[paymentId]; + bytes32 internalPaymentId = _scopePaymentIdForOffChain(paymentId); + PaymentInfo memory payment = s_payment[internalPaymentId]; + address paymentToken = s_paymentIdToToken[internalPaymentId]; uint256 amountToRefund = payment.amount; uint256 availablePaymentAmount = s_availableConfirmedPerToken[paymentToken]; - uint256 tokenId = s_paymentIdToTokenId[paymentId]; + uint256 tokenId = s_paymentIdToTokenId[internalPaymentId]; if (payment.buyerId == ZERO_BYTES) { - revert PaymentTreasuryPaymentNotExist(paymentId); + revert PaymentTreasuryPaymentNotExist(internalPaymentId); } - if(!payment.isConfirmed){ - revert PaymentTreasuryPaymentNotConfirmed(paymentId); + if (!payment.isConfirmed) { + revert PaymentTreasuryPaymentNotConfirmed(internalPaymentId); } if (amountToRefund == 0 || availablePaymentAmount < amountToRefund) { - revert PaymentTreasuryPaymentNotClaimable(paymentId); + revert PaymentTreasuryPaymentNotClaimable(internalPaymentId); } // This function is for non-NFT payments only if (tokenId != 0) { - revert PaymentTreasuryCryptoPayment(paymentId); + revert PaymentTreasuryCryptoPayment(internalPaymentId); } // Use snapshots of line item type configuration from payment creation time // This prevents issues if line item type configuration changed after payment creation/confirmation - ICampaignPaymentTreasury.PaymentLineItem[] storage lineItems = s_paymentLineItems[paymentId]; + ICampaignPaymentTreasury.PaymentLineItem[] storage lineItems = s_paymentLineItems[internalPaymentId]; uint256 protocolFeePercent = INFO.getProtocolFeePercent(); - + // Calculate total line item refund amount using snapshots uint256 totalGoalLineItemRefundAmount = 0; uint256 totalNonGoalLineItemRefundAmount = 0; - + for (uint256 i = 0; i < lineItems.length; i++) { ICampaignPaymentTreasury.PaymentLineItem memory item = lineItems[i]; - + // Use snapshot flags instead of current configuration if (!item.canRefund) { continue; // Skip non-refundable line items (based on snapshot at creation time) } - + if (item.countsTowardGoal) { // Goal line items: full amount is refundable from goal tracking totalGoalLineItemRefundAmount += item.amount; @@ -1215,13 +1286,13 @@ abstract contract BasePaymentTreasury is // Skip instant transfer items - they were already sent to platform admin continue; } - + uint256 feeAmount = 0; if (item.applyProtocolFee) { feeAmount = (item.amount * protocolFeePercent) / PERCENT_DIVIDER; } uint256 netAmount = item.amount - feeAmount; - + // Only refund the net amount (fees are not refundable) totalNonGoalLineItemRefundAmount += netAmount; } @@ -1230,12 +1301,12 @@ abstract contract BasePaymentTreasury is // Check that we have enough available balance for the total refund (BEFORE modifying state) // Goal line items are in availableConfirmedPerToken, non-goal items need separate check uint256 totalRefundAmount = amountToRefund + totalGoalLineItemRefundAmount + totalNonGoalLineItemRefundAmount; - + // For goal line items and base payment, check availableConfirmedPerToken if (availablePaymentAmount < (amountToRefund + totalGoalLineItemRefundAmount)) { revert PaymentTreasuryPaymentNotClaimable(paymentId); } - + // For non-goal line items, check that we have enough claimable balance // (only non-instant transfer items are refundable, and only their net amounts after fees) if (totalNonGoalLineItemRefundAmount > 0) { @@ -1244,7 +1315,7 @@ abstract contract BasePaymentTreasury is revert PaymentTreasuryPaymentNotClaimable(paymentId); } } - + // Check that contract has enough actual balance to perform the transfer uint256 contractBalance = IERC20(paymentToken).balanceOf(address(this)); if (contractBalance < totalRefundAmount) { @@ -1254,12 +1325,12 @@ abstract contract BasePaymentTreasury is // Update state: remove tracking for refundable line items using snapshots for (uint256 i = 0; i < lineItems.length; i++) { ICampaignPaymentTreasury.PaymentLineItem memory item = lineItems[i]; - + // Use snapshot flags instead of current configuration if (!item.canRefund) { continue; // Skip non-refundable line items (based on snapshot at creation time) } - + if (item.countsTowardGoal) { // Goal line items: remove from goal tracking s_confirmedPaymentPerToken[paymentToken] -= item.amount; @@ -1271,28 +1342,28 @@ abstract contract BasePaymentTreasury is // Instant transfer items were already sent to platform admin; nothing tracked continue; } - + // Calculate fees and net amount using snapshot uint256 feeAmount = 0; if (item.applyProtocolFee) { feeAmount = (item.amount * protocolFeePercent) / PERCENT_DIVIDER; // Fees are NOT refunded - they remain in the protocol fee pool } - + uint256 netAmount = item.amount - feeAmount; - + // Remove net amount from outstanding non-goal tracking s_nonGoalLineItemConfirmedPerToken[paymentToken] -= netAmount; - + // Remove from refundable tracking (only net amount is refundable) s_refundableNonGoalLineItemPerToken[paymentToken] -= netAmount; } } - delete s_payment[paymentId]; - delete s_paymentIdToToken[paymentId]; - delete s_paymentLineItems[paymentId]; - delete s_paymentExternalFeeMetadata[paymentId]; + delete s_payment[internalPaymentId]; + delete s_paymentIdToToken[internalPaymentId]; + delete s_paymentLineItems[internalPaymentId]; + delete s_paymentExternalFeeMetadata[internalPaymentId]; s_confirmedPaymentPerToken[paymentToken] -= amountToRefund; s_availableConfirmedPerToken[paymentToken] -= amountToRefund; @@ -1305,26 +1376,28 @@ abstract contract BasePaymentTreasury is * @inheritdoc ICampaignPaymentTreasury * @dev For NFT payments only. Requires an NFT exists and burns it. Refund is sent to current NFT owner. */ - function claimRefund( - bytes32 paymentId - ) public override virtual whenCampaignNotPaused whenCampaignNotCancelled - { - PaymentInfo memory payment = s_payment[paymentId]; - address paymentToken = s_paymentIdToToken[paymentId]; + function claimRefund(bytes32 paymentId) public virtual override whenCampaignNotPaused whenCampaignNotCancelled { + // Use _findPaymentId to look up the payment using stored creator address + bytes32 internalPaymentId = _findPaymentId(paymentId); + if (internalPaymentId == ZERO_BYTES) { + revert PaymentTreasuryPaymentNotExist(paymentId); + } + PaymentInfo memory payment = s_payment[internalPaymentId]; + address paymentToken = s_paymentIdToToken[internalPaymentId]; address buyerAddress = payment.buyerAddress; uint256 amountToRefund = payment.amount; uint256 availablePaymentAmount = s_availableConfirmedPerToken[paymentToken]; - uint256 tokenId = s_paymentIdToTokenId[paymentId]; + uint256 tokenId = s_paymentIdToTokenId[internalPaymentId]; if (buyerAddress == address(0)) { - revert PaymentTreasuryPaymentNotExist(paymentId); + revert PaymentTreasuryPaymentNotExist(internalPaymentId); } if (amountToRefund == 0 || availablePaymentAmount < amountToRefund) { - revert PaymentTreasuryPaymentNotClaimable(paymentId); + revert PaymentTreasuryPaymentNotClaimable(internalPaymentId); } - // This function is for NFT payments only - NFT must exist + // NFT must exist for crypto payments if (tokenId == 0) { - revert PaymentTreasuryPaymentNotClaimable(paymentId); + revert PaymentTreasuryPaymentNotClaimable(internalPaymentId); } // Get NFT owner before burning @@ -1332,21 +1405,21 @@ abstract contract BasePaymentTreasury is // Use snapshots of line item type configuration from payment creation time // This prevents issues if line item type configuration changed after payment creation/confirmation - ICampaignPaymentTreasury.PaymentLineItem[] storage lineItems = s_paymentLineItems[paymentId]; + ICampaignPaymentTreasury.PaymentLineItem[] storage lineItems = s_paymentLineItems[internalPaymentId]; uint256 protocolFeePercent = INFO.getProtocolFeePercent(); - + // Calculate total line item refund amount using snapshots uint256 totalGoalLineItemRefundAmount = 0; uint256 totalNonGoalLineItemRefundAmount = 0; - + for (uint256 i = 0; i < lineItems.length; i++) { ICampaignPaymentTreasury.PaymentLineItem memory item = lineItems[i]; - + // Use snapshot flags instead of current configuration if (!item.canRefund) { continue; // Skip non-refundable line items (based on snapshot at creation time) } - + if (item.countsTowardGoal) { // Goal line items: full amount is refundable from goal tracking totalGoalLineItemRefundAmount += item.amount; @@ -1358,13 +1431,13 @@ abstract contract BasePaymentTreasury is // Skip instant transfer items - they were already sent to platform admin continue; } - + uint256 feeAmount = 0; if (item.applyProtocolFee) { feeAmount = (item.amount * protocolFeePercent) / PERCENT_DIVIDER; } uint256 netAmount = item.amount - feeAmount; - + // Only refund the net amount (fees are not refundable) totalNonGoalLineItemRefundAmount += netAmount; } @@ -1373,36 +1446,36 @@ abstract contract BasePaymentTreasury is // Check that we have enough available balance for the total refund (BEFORE modifying state) // Goal line items are in availableConfirmedPerToken, non-goal items need separate check uint256 totalRefundAmount = amountToRefund + totalGoalLineItemRefundAmount + totalNonGoalLineItemRefundAmount; - + // For goal line items and base payment, check availableConfirmedPerToken if (availablePaymentAmount < (amountToRefund + totalGoalLineItemRefundAmount)) { - revert PaymentTreasuryPaymentNotClaimable(paymentId); + revert PaymentTreasuryPaymentNotClaimable(internalPaymentId); } - + // For non-goal line items, check that we have enough claimable balance // (only non-instant transfer items are refundable, and only their net amounts after fees) if (totalNonGoalLineItemRefundAmount > 0) { uint256 availableRefundable = s_refundableNonGoalLineItemPerToken[paymentToken]; if (availableRefundable < totalNonGoalLineItemRefundAmount) { - revert PaymentTreasuryPaymentNotClaimable(paymentId); + revert PaymentTreasuryPaymentNotClaimable(internalPaymentId); } } - + // Check that contract has enough actual balance to perform the transfer uint256 contractBalance = IERC20(paymentToken).balanceOf(address(this)); if (contractBalance < totalRefundAmount) { - revert PaymentTreasuryPaymentNotClaimable(paymentId); + revert PaymentTreasuryPaymentNotClaimable(internalPaymentId); } // Update state: remove tracking for refundable line items using snapshots for (uint256 i = 0; i < lineItems.length; i++) { ICampaignPaymentTreasury.PaymentLineItem memory item = lineItems[i]; - + // Use snapshot flags instead of current configuration if (!item.canRefund) { continue; // Skip non-refundable line items (based on snapshot at creation time) } - + if (item.countsTowardGoal) { // Goal line items: remove from goal tracking s_confirmedPaymentPerToken[paymentToken] -= item.amount; @@ -1414,29 +1487,30 @@ abstract contract BasePaymentTreasury is // Instant transfer items were already sent to platform admin; nothing tracked continue; } - + // Calculate fees and net amount using snapshot uint256 feeAmount = 0; if (item.applyProtocolFee) { feeAmount = (item.amount * protocolFeePercent) / PERCENT_DIVIDER; // Fees are NOT refunded - they remain in the protocol fee pool } - + uint256 netAmount = item.amount - feeAmount; - + // Remove net amount from outstanding non-goal tracking s_nonGoalLineItemConfirmedPerToken[paymentToken] -= netAmount; - + // Remove from refundable tracking (only net amount is refundable) s_refundableNonGoalLineItemPerToken[paymentToken] -= netAmount; } } - delete s_payment[paymentId]; - delete s_paymentIdToToken[paymentId]; - delete s_paymentLineItems[paymentId]; - delete s_paymentExternalFeeMetadata[paymentId]; - delete s_paymentIdToTokenId[paymentId]; + delete s_payment[internalPaymentId]; + delete s_paymentIdToToken[internalPaymentId]; + delete s_paymentLineItems[internalPaymentId]; + delete s_paymentExternalFeeMetadata[internalPaymentId]; + delete s_paymentIdToTokenId[internalPaymentId]; + delete s_paymentIdToCreator[paymentId]; // Clean up creator mapping for on-chain payments s_confirmedPaymentPerToken[paymentToken] -= amountToRefund; s_availableConfirmedPerToken[paymentToken] -= amountToRefund; @@ -1451,34 +1525,28 @@ abstract contract BasePaymentTreasury is /** * @inheritdoc ICampaignPaymentTreasury */ - function disburseFees() - public - virtual - override - whenCampaignNotPaused - whenCampaignNotCancelled - { + function disburseFees() public virtual override whenCampaignNotPaused { address[] memory acceptedTokens = INFO.getAcceptedTokens(); address protocolAdmin = INFO.getProtocolAdminAddress(); address platformAdmin = INFO.getPlatformAdminAddress(PLATFORM_HASH); - + for (uint256 i = 0; i < acceptedTokens.length; i++) { address token = acceptedTokens[i]; uint256 protocolShare = s_protocolFeePerToken[token]; uint256 platformShare = s_platformFeePerToken[token]; - + if (protocolShare > 0 || platformShare > 0) { s_protocolFeePerToken[token] = 0; s_platformFeePerToken[token] = 0; - + if (protocolShare > 0) { IERC20(token).safeTransfer(protocolAdmin, protocolShare); } - + if (platformShare > 0) { IERC20(token).safeTransfer(platformAdmin, platformShare); } - + emit FeesDisbursed(token, protocolShare, platformShare); } } @@ -1493,7 +1561,6 @@ abstract contract BasePaymentTreasury is virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused - whenCampaignNotCancelled { if (!INFO.isTokenAccepted(token)) { revert PaymentTreasuryTokenNotAccepted(token); @@ -1506,26 +1573,19 @@ abstract contract BasePaymentTreasury is s_nonGoalLineItemClaimablePerToken[token] = 0; uint256 currentNonGoalConfirmed = s_nonGoalLineItemConfirmedPerToken[token]; - s_nonGoalLineItemConfirmedPerToken[token] = currentNonGoalConfirmed > claimableAmount - ? currentNonGoalConfirmed - claimableAmount - : 0; + s_nonGoalLineItemConfirmedPerToken[token] = + currentNonGoalConfirmed > claimableAmount ? currentNonGoalConfirmed - claimableAmount : 0; address platformAdmin = INFO.getPlatformAdminAddress(PLATFORM_HASH); - + IERC20(token).safeTransfer(platformAdmin, claimableAmount); - + emit NonGoalLineItemsClaimed(token, claimableAmount, platformAdmin); } /** * @notice Allows the platform admin to claim all remaining funds once the claim window has opened. */ - function claimExpiredFunds() - public - virtual - onlyPlatformAdmin(PLATFORM_HASH) - whenCampaignNotPaused - whenCampaignNotCancelled - { + function claimExpiredFunds() public virtual onlyPlatformAdmin(PLATFORM_HASH) whenCampaignNotPaused { uint256 claimDelay = INFO.getPlatformClaimDelay(PLATFORM_HASH); uint256 claimableAt = INFO.getDeadline(); claimableAt += claimDelay; @@ -1558,18 +1618,16 @@ abstract contract BasePaymentTreasury is if (availableConfirmed > 0) { uint256 currentConfirmed = s_confirmedPaymentPerToken[token]; - s_confirmedPaymentPerToken[token] = currentConfirmed > availableConfirmed - ? currentConfirmed - availableConfirmed - : 0; + s_confirmedPaymentPerToken[token] = + currentConfirmed > availableConfirmed ? currentConfirmed - availableConfirmed : 0; s_availableConfirmedPerToken[token] = 0; } if (claimableAmount > 0 || refundableAmount > 0) { uint256 reduction = claimableAmount + refundableAmount; uint256 currentNonGoalConfirmed = s_nonGoalLineItemConfirmedPerToken[token]; - s_nonGoalLineItemConfirmedPerToken[token] = currentNonGoalConfirmed > reduction - ? currentNonGoalConfirmed - reduction - : 0; + s_nonGoalLineItemConfirmedPerToken[token] = + currentNonGoalConfirmed > reduction ? currentNonGoalConfirmed - reduction : 0; s_nonGoalLineItemClaimablePerToken[token] = 0; s_refundableNonGoalLineItemPerToken[token] = 0; } @@ -1608,6 +1666,7 @@ abstract contract BasePaymentTreasury is public virtual override + onlyPlatformAdminOrCampaignOwner whenCampaignNotPaused whenCampaignNotCancelled { @@ -1619,16 +1678,16 @@ abstract contract BasePaymentTreasury is address[] memory acceptedTokens = INFO.getAcceptedTokens(); uint256 protocolFeePercent = INFO.getProtocolFeePercent(); uint256 platformFeePercent = INFO.getPlatformFeePercent(PLATFORM_HASH); - + bool hasWithdrawn = false; - + for (uint256 i = 0; i < acceptedTokens.length; i++) { address token = acceptedTokens[i]; uint256 balance = s_availableConfirmedPerToken[token]; - + if (balance > 0) { hasWithdrawn = true; - + // Calculate fees uint256 protocolShare = (balance * protocolFeePercent) / PERCENT_DIVIDER; uint256 platformShare = (balance * platformFeePercent) / PERCENT_DIVIDER; @@ -1638,11 +1697,11 @@ abstract contract BasePaymentTreasury is uint256 totalFee = protocolShare + platformShare; - if(balance < totalFee) { + if (balance < totalFee) { revert PaymentTreasuryInsufficientFundsForFee(balance, totalFee); } uint256 withdrawalAmount = balance - totalFee; - + // Reset balance s_availableConfirmedPerToken[token] = 0; @@ -1651,7 +1710,7 @@ abstract contract BasePaymentTreasury is emit WithdrawalWithFeeSuccessful(token, recipient, withdrawalAmount, totalFee); } } - + if (!hasWithdrawn) { revert PaymentTreasuryAlreadyWithdrawn(); } @@ -1660,27 +1719,21 @@ abstract contract BasePaymentTreasury is /** * @dev External function to pause the campaign. */ - function pauseTreasury( - bytes32 message - ) public virtual onlyPlatformAdmin(PLATFORM_HASH) { + function pauseTreasury(bytes32 message) public virtual onlyPlatformAdmin(PLATFORM_HASH) { _pause(message); } /** * @dev External function to unpause the campaign. */ - function unpauseTreasury( - bytes32 message - ) public virtual onlyPlatformAdmin(PLATFORM_HASH) { + function unpauseTreasury(bytes32 message) public virtual onlyPlatformAdmin(PLATFORM_HASH) { _unpause(message); } /** * @dev External function to cancel the campaign. */ - function cancelTreasury( - bytes32 message - ) public virtual onlyPlatformAdmin(PLATFORM_HASH) { + function cancelTreasury(bytes32 message) public virtual onlyPlatformAdmin(PLATFORM_HASH) { _cancel(message); } @@ -1739,21 +1792,38 @@ abstract contract BasePaymentTreasury is /** * @inheritdoc ICampaignPaymentTreasury + * @dev This function can look up payments created by anyone: + * - Off-chain payments (created via createPayment): Scoped with address(0), anyone can look these up + * - On-chain payments (created via processCryptoPayment): Uses stored creator address, anyone can look these up */ - function getPaymentData(bytes32 paymentId) public view override returns (ICampaignPaymentTreasury.PaymentData memory) { - PaymentInfo memory payment = s_payment[paymentId]; - address paymentToken = s_paymentIdToToken[paymentId]; - ICampaignPaymentTreasury.PaymentLineItem[] storage lineItemsStorage = s_paymentLineItems[paymentId]; - ICampaignPaymentTreasury.ExternalFees[] storage externalFeesStorage = s_paymentExternalFeeMetadata[paymentId]; + function getPaymentData(bytes32 paymentId) + public + view + override + returns (ICampaignPaymentTreasury.PaymentData memory) + { + // Try off-chain scope first (address(0)) - works for createPayment + // Then try on-chain scope using stored creator address - works for processCryptoPayment + bytes32 internalPaymentId = _findPaymentId(paymentId); + if (internalPaymentId == ZERO_BYTES) { + revert PaymentTreasuryPaymentNotExist(paymentId); + } + PaymentInfo memory payment = s_payment[internalPaymentId]; + address paymentToken = s_paymentIdToToken[internalPaymentId]; + ICampaignPaymentTreasury.PaymentLineItem[] storage lineItemsStorage = s_paymentLineItems[internalPaymentId]; + ICampaignPaymentTreasury.ExternalFees[] storage externalFeesStorage = + s_paymentExternalFeeMetadata[internalPaymentId]; // Copy line items from storage to memory (required: cannot directly assign storage array to memory array) - ICampaignPaymentTreasury.PaymentLineItem[] memory lineItems = new ICampaignPaymentTreasury.PaymentLineItem[](lineItemsStorage.length); + ICampaignPaymentTreasury.PaymentLineItem[] memory lineItems = + new ICampaignPaymentTreasury.PaymentLineItem[](lineItemsStorage.length); for (uint256 i = 0; i < lineItemsStorage.length; i++) { lineItems[i] = lineItemsStorage[i]; } // Copy external fees from storage to memory (same reason as line items) - ICampaignPaymentTreasury.ExternalFees[] memory externalFees = new ICampaignPaymentTreasury.ExternalFees[](externalFeesStorage.length); + ICampaignPaymentTreasury.ExternalFees[] memory externalFees = + new ICampaignPaymentTreasury.ExternalFees[](externalFeesStorage.length); for (uint256 i = 0; i < externalFeesStorage.length; i++) { externalFees[i] = externalFeesStorage[i]; } @@ -1778,4 +1848,4 @@ abstract contract BasePaymentTreasury is * @return Whether the success condition is met. */ function _checkSuccessCondition() internal view virtual returns (bool); -} \ No newline at end of file +} diff --git a/src/utils/BaseTreasury.sol b/src/utils/BaseTreasury.sol index 5b9029f2..9e5bcb4d 100644 --- a/src/utils/BaseTreasury.sol +++ b/src/utils/BaseTreasury.sol @@ -13,18 +13,13 @@ import {PausableCancellable} from "./PausableCancellable.sol"; * @title BaseTreasury * @notice A base contract for creating and managing treasuries in crowdfunding campaigns. * @dev This contract defines common functionality and storage for campaign treasuries. + * @dev Supports ERC-2771 meta-transactions via adapter contracts for platform admin operations. * @dev Contracts implementing this base contract should provide specific success conditions. */ -abstract contract BaseTreasury is - Initializable, - ICampaignTreasury, - CampaignAccessChecker, - PausableCancellable -{ +abstract contract BaseTreasury is Initializable, ICampaignTreasury, CampaignAccessChecker, PausableCancellable { using SafeERC20 for IERC20; - bytes32 internal constant ZERO_BYTES = - 0x0000000000000000000000000000000000000000000000000000000000000000; + bytes32 internal constant ZERO_BYTES = 0x0000000000000000000000000000000000000000000000000000000000000000; uint256 internal constant PERCENT_DIVIDER = 10000; uint256 internal constant STANDARD_DECIMALS = 18; @@ -32,10 +27,10 @@ abstract contract BaseTreasury is uint256 internal PLATFORM_FEE_PERCENT; bool internal s_feesDisbursed; - + // Multi-token support - mapping(address => uint256) internal s_tokenRaisedAmounts; // Amount raised per token (decreases on refunds) - mapping(address => uint256) internal s_tokenLifetimeRaisedAmounts; // Lifetime raised amount per token (never decreases) + mapping(address => uint256) internal s_tokenRaisedAmounts; // Amount raised per token (decreases on refunds) + mapping(address => uint256) internal s_tokenLifetimeRaisedAmounts; // Lifetime raised amount per token (never decreases) /** * @notice Emitted when fees are successfully disbursed for a specific token. @@ -78,13 +73,25 @@ abstract contract BaseTreasury is */ error TreasuryCampaignInfoIsPaused(); - function __BaseContract_init( - bytes32 platformHash, - address infoAddress - ) internal { + function __BaseContract_init(bytes32 platformHash, address infoAddress, address trustedForwarder_) internal { __CampaignAccessChecker_init(infoAddress); PLATFORM_HASH = platformHash; PLATFORM_FEE_PERCENT = INFO.getPlatformFeePercent(platformHash); + _trustedForwarder = trustedForwarder_; + } + + /** + * @dev Override _msgSender to support ERC-2771 meta-transactions. + * When called by the trusted forwarder (adapter), extracts the actual sender from calldata. + */ + function _msgSender() internal view virtual override returns (address sender) { + if (msg.sender == _trustedForwarder && msg.data.length >= 20) { + assembly { + sender := shr(96, calldataload(sub(calldatasize(), 20))) + } + } else { + sender = msg.sender; + } } /** @@ -120,12 +127,9 @@ abstract contract BaseTreasury is * @param amount The amount to normalize. * @return The normalized amount in 18 decimals. */ - function _normalizeAmount( - address token, - uint256 amount - ) internal view returns (uint256) { + function _normalizeAmount(address token, uint256 amount) internal view returns (uint256) { uint8 decimals = IERC20Metadata(token).decimals(); - + if (decimals == STANDARD_DECIMALS) { return amount; } else if (decimals < STANDARD_DECIMALS) { @@ -143,17 +147,15 @@ abstract contract BaseTreasury is * @param amount The amount in 18 decimals to denormalize. * @return The denormalized amount in token's native decimals. */ - function _denormalizeAmount( - address token, - uint256 amount - ) internal view returns (uint256) { + function _denormalizeAmount(address token, uint256 amount) internal view returns (uint256) { uint8 decimals = IERC20Metadata(token).decimals(); - + if (decimals == STANDARD_DECIMALS) { return amount; } else if (decimals < STANDARD_DECIMALS) { // Scale down for tokens with fewer decimals (e.g., USDC 6 decimals) - return amount / (10 ** (STANDARD_DECIMALS - decimals)); + uint256 divisor = 10 ** (STANDARD_DECIMALS - decimals); + return (amount + divisor - 1) / divisor; } else { // Scale up for tokens with more decimals (rare but possible) return amount * (10 ** (decimals - STANDARD_DECIMALS)); @@ -163,68 +165,53 @@ abstract contract BaseTreasury is /** * @inheritdoc ICampaignTreasury */ - function disburseFees() - public - virtual - override - whenCampaignNotPaused - whenCampaignNotCancelled - { + function disburseFees() public virtual override whenCampaignNotPaused whenCampaignNotCancelled { if (!_checkSuccessCondition()) { revert TreasurySuccessConditionNotFulfilled(); } - + address[] memory acceptedTokens = INFO.getAcceptedTokens(); - + // Disburse fees for each token for (uint256 i = 0; i < acceptedTokens.length; i++) { address token = acceptedTokens[i]; uint256 balance = s_tokenRaisedAmounts[token]; - + if (balance > 0) { uint256 protocolShare = (balance * INFO.getProtocolFeePercent()) / PERCENT_DIVIDER; uint256 platformShare = (balance * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; - + if (protocolShare > 0) { IERC20(token).safeTransfer(INFO.getProtocolAdminAddress(), protocolShare); } - + if (platformShare > 0) { - IERC20(token).safeTransfer( - INFO.getPlatformAdminAddress(PLATFORM_HASH), - platformShare - ); + IERC20(token).safeTransfer(INFO.getPlatformAdminAddress(PLATFORM_HASH), platformShare); } - + emit FeesDisbursed(token, protocolShare, platformShare); } } - + s_feesDisbursed = true; } /** * @inheritdoc ICampaignTreasury */ - function withdraw() - public - virtual - override - whenCampaignNotPaused - whenCampaignNotCancelled - { + function withdraw() public virtual override whenCampaignNotPaused whenCampaignNotCancelled { if (!s_feesDisbursed) { revert TreasuryFeeNotDisbursed(); } - + address[] memory acceptedTokens = INFO.getAcceptedTokens(); address recipient = INFO.owner(); - + // Withdraw remaining balance for each token for (uint256 i = 0; i < acceptedTokens.length; i++) { address token = acceptedTokens[i]; uint256 balance = IERC20(token).balanceOf(address(this)); - + if (balance > 0) { IERC20(token).safeTransfer(recipient, balance); emit WithdrawalSuccessful(token, recipient, balance); @@ -235,27 +222,21 @@ abstract contract BaseTreasury is /** * @dev External function to pause the campaign. */ - function pauseTreasury( - bytes32 message - ) public virtual onlyPlatformAdmin(PLATFORM_HASH) { + function pauseTreasury(bytes32 message) public virtual onlyPlatformAdmin(PLATFORM_HASH) { _pause(message); } /** * @dev External function to unpause the campaign. */ - function unpauseTreasury( - bytes32 message - ) public virtual onlyPlatformAdmin(PLATFORM_HASH) { + function unpauseTreasury(bytes32 message) public virtual onlyPlatformAdmin(PLATFORM_HASH) { _unpause(message); } /** * @dev External function to cancel the campaign. */ - function cancelTreasury( - bytes32 message - ) public virtual onlyPlatformAdmin(PLATFORM_HASH) { + function cancelTreasury(bytes32 message) public virtual onlyPlatformAdmin(PLATFORM_HASH) { _cancel(message); } diff --git a/src/utils/CampaignAccessChecker.sol b/src/utils/CampaignAccessChecker.sol index 7f8cc25f..dd0869ed 100644 --- a/src/utils/CampaignAccessChecker.sol +++ b/src/utils/CampaignAccessChecker.sol @@ -3,7 +3,6 @@ pragma solidity ^0.8.22; import {Context} from "@openzeppelin/contracts/utils/Context.sol"; import {ICampaignInfo} from "../interfaces/ICampaignInfo.sol"; -import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol"; /** * @title CampaignAccessChecker @@ -14,6 +13,9 @@ abstract contract CampaignAccessChecker is Context { // Immutable reference to the ICampaignInfo contract, which provides campaign-related information and admin addresses. ICampaignInfo internal INFO; + /// @dev Trusted forwarder address for ERC-2771 meta-transactions (set by derived contracts) + address internal _trustedForwarder; + /** * @dev Throws when the caller is not authorized. */ diff --git a/src/utils/FiatEnabled.sol b/src/utils/FiatEnabled.sol index fef6fb0c..378f7d1a 100644 --- a/src/utils/FiatEnabled.sol +++ b/src/utils/FiatEnabled.sol @@ -16,10 +16,7 @@ abstract contract FiatEnabled { * @param fiatTransactionId The unique identifier of the fiat transaction. * @param fiatTransactionAmount The updated amount of the fiat transaction. */ - event FiatTransactionUpdated( - bytes32 indexed fiatTransactionId, - uint256 fiatTransactionAmount - ); + event FiatTransactionUpdated(bytes32 indexed fiatTransactionId, uint256 fiatTransactionAmount); /** * @notice Emitted when the state of fiat fee disbursement is updated. @@ -27,11 +24,7 @@ abstract contract FiatEnabled { * @param protocolFeeAmount The protocol fee amount. * @param platformFeeAmount The platform fee amount. */ - event FiatFeeDisbusementStateUpdated( - bool isDisbursed, - uint256 protocolFeeAmount, - uint256 platformFeeAmount - ); + event FiatFeeDisbusementStateUpdated(bool isDisbursed, uint256 protocolFeeAmount, uint256 platformFeeAmount); /** * @dev Throws an error indicating that the fiat enabled functionality is already set. @@ -59,9 +52,7 @@ abstract contract FiatEnabled { * @param fiatTransactionId The unique identifier of the fiat transaction. * @return amount The amount of the specified fiat transaction. */ - function getFiatTransactionAmount( - bytes32 fiatTransactionId - ) external view returns (uint256 amount) { + function getFiatTransactionAmount(bytes32 fiatTransactionId) external view returns (uint256 amount) { amount = s_fiatAmountById[fiatTransactionId]; if (amount == 0) { revert FiatEnabledInvalidTransaction(); @@ -81,10 +72,7 @@ abstract contract FiatEnabled { * @param fiatTransactionId The unique identifier of the fiat transaction. * @param fiatTransactionAmount The amount of the fiat transaction. */ - function _updateFiatTransaction( - bytes32 fiatTransactionId, - uint256 fiatTransactionAmount - ) internal { + function _updateFiatTransaction(bytes32 fiatTransactionId, uint256 fiatTransactionAmount) internal { s_fiatAmountById[fiatTransactionId] = fiatTransactionAmount; s_fiatRaisedAmount += fiatTransactionAmount; emit FiatTransactionUpdated(fiatTransactionId, fiatTransactionAmount); @@ -96,11 +84,9 @@ abstract contract FiatEnabled { * @param protocolFeeAmount The protocol fee amount. * @param platformFeeAmount The platform fee amount. */ - function _updateFiatFeeDisbursementState( - bool isDisbursed, - uint256 protocolFeeAmount, - uint256 platformFeeAmount - ) internal { + function _updateFiatFeeDisbursementState(bool isDisbursed, uint256 protocolFeeAmount, uint256 platformFeeAmount) + internal + { if (s_fiatFeeIsDisbursed == true) { revert FiatEnabledAlreadySet(); } @@ -108,10 +94,6 @@ abstract contract FiatEnabled { revert FiatEnabledDisallowedState(); } s_fiatFeeIsDisbursed = true; - emit FiatFeeDisbusementStateUpdated( - isDisbursed, - protocolFeeAmount, - platformFeeAmount - ); + emit FiatFeeDisbusementStateUpdated(isDisbursed, protocolFeeAmount, platformFeeAmount); } } diff --git a/src/utils/ItemRegistry.sol b/src/utils/ItemRegistry.sol index e8ee582c..e1931739 100644 --- a/src/utils/ItemRegistry.sol +++ b/src/utils/ItemRegistry.sol @@ -28,10 +28,7 @@ contract ItemRegistry is IItem, Context { /** * @inheritdoc IItem */ - function getItem( - address owner, - bytes32 itemId - ) external view override returns (Item memory) { + function getItem(address owner, bytes32 itemId) external view override returns (Item memory) { return Items[owner][itemId]; } @@ -48,10 +45,7 @@ contract ItemRegistry is IItem, Context { * @param itemIds An array of unique item identifiers. * @param items An array of `Item` structs containing item attributes. */ - function addItemsBatch( - bytes32[] calldata itemIds, - Item[] calldata items - ) external { + function addItemsBatch(bytes32[] calldata itemIds, Item[] calldata items) external { if (itemIds.length != items.length) { revert ItemRegistryMismatchedArraysLength(); } diff --git a/src/utils/PausableCancellable.sol b/src/utils/PausableCancellable.sol index ee79d7e5..441a69f9 100644 --- a/src/utils/PausableCancellable.sol +++ b/src/utils/PausableCancellable.sol @@ -100,9 +100,7 @@ abstract contract PausableCancellable is Context { * @param reason A short reason for pausing * @dev Can only pause if not already paused or cancelled */ - function _pause( - bytes32 reason - ) internal virtual whenNotPaused whenNotCancelled { + function _pause(bytes32 reason) internal virtual whenNotPaused whenNotCancelled { _paused = true; emit Paused(_msgSender(), reason); } @@ -126,9 +124,7 @@ abstract contract PausableCancellable is Context { if (_cancelled) revert CannotCancel(); /// @dev keccak256 Hash of `Auto-unpaused during cancellation` is passed as a reason if (_paused) { - _unpause( - 0x231da0eace2a459b43889b78bbd1fc88a89e3192ee6cbcda7015c539d577e2cd - ); + _unpause(0x231da0eace2a459b43889b78bbd1fc88a89e3192ee6cbcda7015c539d577e2cd); } _cancelled = true; emit Cancelled(_msgSender(), reason); diff --git a/src/utils/PledgeNFT.sol b/src/utils/PledgeNFT.sol index edad3c38..2f7e939e 100644 --- a/src/utils/PledgeNFT.sol +++ b/src/utils/PledgeNFT.sol @@ -38,7 +38,7 @@ abstract contract PledgeNFT is ERC721Burnable, AccessControl { string internal s_nftSymbol; string internal s_imageURI; string internal s_contractURI; - + // Token ID counter (also serves as pledge ID counter) Counters.Counter internal s_tokenIdCounter; @@ -64,18 +64,18 @@ abstract contract PledgeNFT is ERC721Burnable, AccessControl { * @param treasury The treasury address * @param reward The reward identifier */ - event PledgeNFTMinted( - uint256 indexed tokenId, - address indexed backer, - address indexed treasury, - bytes32 reward - ); + event PledgeNFTMinted(uint256 indexed tokenId, address indexed backer, address indexed treasury, bytes32 reward); /** * @dev Emitted when unauthorized access is attempted */ error PledgeNFTUnAuthorized(); + /** + * @dev Emitted when a string contains invalid characters for JSON + */ + error PledgeNFTInvalidJsonString(); + /** * @notice Initialize NFT metadata * @dev Called by CampaignInfo during initialization @@ -90,12 +90,29 @@ abstract contract PledgeNFT is ERC721Burnable, AccessControl { string calldata _imageURI, string calldata _contractURI ) internal { + _validateJsonString(_nftName); s_nftName = _nftName; s_nftSymbol = _nftSymbol; s_imageURI = _imageURI; s_contractURI = _contractURI; } + /** + * @notice Validates that a string is safe for JSON embedding + * @dev Reverts if string contains quotes, backslashes, or control characters + * @param str The string to validate + */ + function _validateJsonString(string calldata str) internal pure { + bytes memory b = bytes(str); + for (uint256 i = 0; i < b.length; i++) { + bytes1 char = b[i]; + // Reject: double quote ("), backslash (\), or control characters (0x00-0x1F) + if (char == 0x22 || char == 0x5C || char < 0x20) { + revert PledgeNFTInvalidJsonString(); + } + } + } + /** * @notice Mints a pledge NFT (auto-increments counter) * @dev Called by treasuries - returns the new token ID to use as pledge ID @@ -118,7 +135,7 @@ abstract contract PledgeNFT is ERC721Burnable, AccessControl { // Increment counter and get new token ID s_tokenIdCounter.increment(); tokenId = s_tokenIdCounter.current(); - + // Set pledge data s_pledgeData[tokenId] = PledgeData({ backer: backer, @@ -129,12 +146,12 @@ abstract contract PledgeNFT is ERC721Burnable, AccessControl { shippingFee: shippingFee, tipAmount: tipAmount }); - + + emit PledgeNFTMinted(tokenId, backer, msg.sender, reward); + // Mint NFT _safeMint(backer, tokenId); - - emit PledgeNFTMinted(tokenId, backer, msg.sender, reward); - + return tokenId; } @@ -198,26 +215,44 @@ abstract contract PledgeNFT is ERC721Burnable, AccessControl { * @param tokenId The token ID * @return The base64 encoded JSON metadata */ - function tokenURI( - uint256 tokenId - ) public view virtual override returns (string memory) { + function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { _requireOwned(tokenId); PledgeData memory data = s_pledgeData[tokenId]; - + string memory json = string( abi.encodePacked( - '{"name":"', name(), " #", tokenId.toString(), - '","image":"', s_imageURI, + '{"name":"', + name(), + " #", + tokenId.toString(), + '","image":"', + s_imageURI, '","attributes":[', - '{"trait_type":"Backer","value":"', Strings.toHexString(uint160(data.backer), 20), '"},', - '{"trait_type":"Reward","value":"', Strings.toHexString(uint256(data.reward), 32), '"},', - '{"trait_type":"Treasury","value":"', Strings.toHexString(uint160(data.treasury), 20), '"},', - '{"trait_type":"Campaign","value":"', Strings.toHexString(uint160(address(this)), 20), '"},', - '{"trait_type":"PledgeToken","value":"', Strings.toHexString(uint160(data.tokenAddress), 20), '"},', - '{"trait_type":"PledgeAmount","value":"', data.amount.toString(), '"},', - '{"trait_type":"ShippingFee","value":"', data.shippingFee.toString(), '"},', - '{"trait_type":"TipAmount","value":"', data.tipAmount.toString(), '"}', + '{"trait_type":"Backer","value":"', + Strings.toHexString(uint160(data.backer), 20), + '"},', + '{"trait_type":"Reward","value":"', + Strings.toHexString(uint256(data.reward), 32), + '"},', + '{"trait_type":"Treasury","value":"', + Strings.toHexString(uint160(data.treasury), 20), + '"},', + '{"trait_type":"Campaign","value":"', + Strings.toHexString(uint160(address(this)), 20), + '"},', + '{"trait_type":"PledgeToken","value":"', + Strings.toHexString(uint160(data.tokenAddress), 20), + '"},', + '{"trait_type":"PledgeAmount","value":"', + data.amount.toString(), + '"},', + '{"trait_type":"ShippingFee","value":"', + data.shippingFee.toString(), + '"},', + '{"trait_type":"TipAmount","value":"', + data.tipAmount.toString(), + '"}', "]}" ) ); @@ -258,14 +293,7 @@ abstract contract PledgeNFT is ERC721Burnable, AccessControl { * @param interfaceId The interface ID * @return True if the interface is supported */ - function supportsInterface(bytes4 interfaceId) - public - view - virtual - override(ERC721, AccessControl) - returns (bool) - { + function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, AccessControl) returns (bool) { return super.supportsInterface(interfaceId); } } - diff --git a/src/utils/TimestampChecker.sol b/src/utils/TimestampChecker.sol index 3a697448..02e26c40 100644 --- a/src/utils/TimestampChecker.sol +++ b/src/utils/TimestampChecker.sol @@ -59,9 +59,7 @@ abstract contract TimestampChecker { * @dev Internal function to revert if the current timestamp is less than or equal a specified time. * @param inputTime The timestamp being checked against. */ - function _revertIfCurrentTimeIsNotLess( - uint256 inputTime - ) internal view virtual { + function _revertIfCurrentTimeIsNotLess(uint256 inputTime) internal view virtual { uint256 currentTime = block.timestamp; if (currentTime >= inputTime) { revert CurrentTimeIsGreater(inputTime, currentTime); @@ -72,9 +70,7 @@ abstract contract TimestampChecker { * @dev Internal function to revert if the current timestamp is not greater than or equal a specified time. * @param inputTime The timestamp being checked against. */ - function _revertIfCurrentTimeIsNotGreater( - uint256 inputTime - ) internal view virtual { + function _revertIfCurrentTimeIsNotGreater(uint256 inputTime) internal view virtual { uint256 currentTime = block.timestamp; if (currentTime <= inputTime) { revert CurrentTimeIsLess(inputTime, currentTime); @@ -86,10 +82,7 @@ abstract contract TimestampChecker { * @param initialTime The initial timestamp of the range. * @param finalTime The final timestamp of the range. */ - function _revertIfCurrentTimeIsNotWithinRange( - uint256 initialTime, - uint256 finalTime - ) internal view virtual { + function _revertIfCurrentTimeIsNotWithinRange(uint256 initialTime, uint256 finalTime) internal view virtual { uint256 currentTime = block.timestamp; if (currentTime < initialTime || currentTime > finalTime) { revert CurrentTimeIsNotWithinRange(initialTime, finalTime); diff --git a/test/foundry/Base.t.sol b/test/foundry/Base.t.sol index 108ec397..55b79115 100644 --- a/test/foundry/Base.t.sol +++ b/test/foundry/Base.t.sol @@ -21,13 +21,13 @@ abstract contract Base_Test is Test, Defaults { Users internal users; //Test Contracts - Multiple tokens for multi-token testing - TestToken internal usdtToken; // 6 decimals - Tether - TestToken internal usdcToken; // 6 decimals - USD Coin - TestToken internal cUSDToken; // 18 decimals - Celo Dollar - + TestToken internal usdtToken; // 6 decimals - Tether + TestToken internal usdcToken; // 6 decimals - USD Coin + TestToken internal cUSDToken; // 18 decimals - Celo Dollar + // Legacy support - points to cUSDToken for backward compatibility TestToken internal testToken; - + GlobalParams internal globalParams; CampaignInfoFactory internal campaignInfoFactory; TreasuryFactory internal treasuryFactory; @@ -54,20 +54,20 @@ abstract contract Base_Test is Test, Defaults { usdtToken = new TestToken("Tether USD", "USDT", 6); usdcToken = new TestToken("USD Coin", "USDC", 6); cUSDToken = new TestToken("Celo Dollar", "cUSD", 18); - + // Backward compatibility testToken = cUSDToken; - + // Setup currencies and tokens for multi-token support bytes32[] memory currencies = new bytes32[](1); currencies[0] = bytes32("USD"); - + address[][] memory tokensPerCurrency = new address[][](1); tokensPerCurrency[0] = new address[](3); tokensPerCurrency[0][0] = address(usdtToken); tokensPerCurrency[0][1] = address(usdcToken); tokensPerCurrency[0][2] = address(cUSDToken); - + // Deploy GlobalParams with UUPS proxy GlobalParams globalParamsImpl = new GlobalParams(); bytes memory globalParamsInitData = abi.encodeWithSelector( @@ -77,10 +77,7 @@ abstract contract Base_Test is Test, Defaults { currencies, tokensPerCurrency ); - ERC1967Proxy globalParamsProxy = new ERC1967Proxy( - address(globalParamsImpl), - globalParamsInitData - ); + ERC1967Proxy globalParamsProxy = new ERC1967Proxy(address(globalParamsImpl), globalParamsInitData); globalParams = GlobalParams(address(globalParamsProxy)); // Deploy CampaignInfo implementation @@ -89,14 +86,9 @@ abstract contract Base_Test is Test, Defaults { // Deploy TreasuryFactory with UUPS proxy TreasuryFactory treasuryFactoryImpl = new TreasuryFactory(); - bytes memory treasuryFactoryInitData = abi.encodeWithSelector( - TreasuryFactory.initialize.selector, - IGlobalParams(address(globalParams)) - ); - ERC1967Proxy treasuryFactoryProxy = new ERC1967Proxy( - address(treasuryFactoryImpl), - treasuryFactoryInitData - ); + bytes memory treasuryFactoryInitData = + abi.encodeWithSelector(TreasuryFactory.initialize.selector, IGlobalParams(address(globalParams))); + ERC1967Proxy treasuryFactoryProxy = new ERC1967Proxy(address(treasuryFactoryImpl), treasuryFactoryInitData); treasuryFactory = TreasuryFactory(address(treasuryFactoryProxy)); // Deploy CampaignInfoFactory with UUPS proxy @@ -108,17 +100,14 @@ abstract contract Base_Test is Test, Defaults { address(campaignInfo), address(treasuryFactory) ); - ERC1967Proxy campaignFactoryProxy = new ERC1967Proxy( - address(campaignFactoryImpl), - campaignFactoryInitData - ); + ERC1967Proxy campaignFactoryProxy = new ERC1967Proxy(address(campaignFactoryImpl), campaignFactoryInitData); campaignInfoFactory = CampaignInfoFactory(address(campaignFactoryProxy)); allOrNothingImplementation = new AllOrNothing(); keepWhatsRaisedImplementation = new KeepWhatsRaised(); - + vm.stopPrank(); - + // Set time constraints in dataRegistry (requires protocol admin) vm.startPrank(users.protocolAdminAddress); globalParams.addToRegistry( @@ -130,23 +119,23 @@ abstract contract Base_Test is Test, Defaults { bytes32(uint256(0)) // No minimum duration for most tests ); vm.stopPrank(); - + vm.startPrank(users.contractOwner); //Mint tokens to backers - all three token types usdtToken.mint(users.backer1Address, TOKEN_MINT_AMOUNT / 1e12); // Adjust for 6 decimals usdtToken.mint(users.backer2Address, TOKEN_MINT_AMOUNT / 1e12); - + usdcToken.mint(users.backer1Address, TOKEN_MINT_AMOUNT / 1e12); usdcToken.mint(users.backer2Address, TOKEN_MINT_AMOUNT / 1e12); - + cUSDToken.mint(users.backer1Address, TOKEN_MINT_AMOUNT); cUSDToken.mint(users.backer2Address, TOKEN_MINT_AMOUNT); - + // Also mint to platform admins for setFeeAndPledge tests usdtToken.mint(users.platform1AdminAddress, TOKEN_MINT_AMOUNT / 1e12); usdcToken.mint(users.platform1AdminAddress, TOKEN_MINT_AMOUNT / 1e12); cUSDToken.mint(users.platform1AdminAddress, TOKEN_MINT_AMOUNT); - + usdtToken.mint(users.platform2AdminAddress, TOKEN_MINT_AMOUNT / 1e12); usdcToken.mint(users.platform2AdminAddress, TOKEN_MINT_AMOUNT / 1e12); cUSDToken.mint(users.platform2AdminAddress, TOKEN_MINT_AMOUNT); @@ -158,18 +147,9 @@ abstract contract Base_Test is Test, Defaults { vm.label({account: address(usdcToken), newLabel: "USDC"}); vm.label({account: address(cUSDToken), newLabel: "cUSD"}); vm.label({account: address(testToken), newLabel: "TestToken(cUSD)"}); - vm.label({ - account: address(globalParams), - newLabel: "Global Parameter" - }); - vm.label({ - account: address(campaignInfoFactory), - newLabel: "Campaign Info Factory" - }); - vm.label({ - account: address(treasuryFactory), - newLabel: "Treasury Factory" - }); + vm.label({account: address(globalParams), newLabel: "Global Parameter"}); + vm.label({account: address(campaignInfoFactory), newLabel: "Campaign Info Factory"}); + vm.label({account: address(treasuryFactory), newLabel: "Treasury Factory"}); // Warp to October 1, 2023 at 00:00 GMT to provide a more realistic testing environment. vm.warp(OCTOBER_1_2023); @@ -181,7 +161,7 @@ abstract contract Base_Test is Test, Defaults { vm.deal({account: user, newBalance: 100 ether}); return user; } - + /// @dev Helper to get token amount adjusted for decimals function getTokenAmount(address token, uint256 baseAmount) internal view returns (uint256) { if (token == address(usdtToken) || token == address(usdcToken)) { @@ -189,9 +169,9 @@ abstract contract Base_Test is Test, Defaults { } return baseAmount; // 18 decimals (cUSD) } - + /// @dev Helper to create an array filled with address(0) function _createZeroAddressArray(uint256 length) internal pure returns (address[] memory) { return new address[](length); } -} \ No newline at end of file +} diff --git a/test/foundry/integration/AllOrNothing/AllOrNothing.t.sol b/test/foundry/integration/AllOrNothing/AllOrNothing.t.sol index e5fc1907..e1e7a909 100644 --- a/test/foundry/integration/AllOrNothing/AllOrNothing.t.sol +++ b/test/foundry/integration/AllOrNothing/AllOrNothing.t.sol @@ -11,11 +11,7 @@ import {IReward} from "src/interfaces/IReward.sol"; import {LogDecoder} from "../../utils/LogDecoder.sol"; /// @notice Common testing logic needed by all AllOrNothing integration tests. -abstract contract AllOrNothing_Integration_Shared_Test is - IReward, - LogDecoder, - Base_Test -{ +abstract contract AllOrNothing_Integration_Shared_Test is IReward, LogDecoder, Base_Test { address campaignAddress; address treasuryAddress; AllOrNothing internal allOrNothing; @@ -55,18 +51,15 @@ abstract contract AllOrNothing_Integration_Shared_Test is globalParams.enlistPlatform( platformHash, users.platform1AdminAddress, - PLATFORM_FEE_PERCENT + PLATFORM_FEE_PERCENT, + address(0) // Platform adapter - can be set later with setPlatformAdapter ); vm.stopPrank(); } function registerTreasuryImplementation(bytes32 platformHash) internal { vm.startPrank(users.platform1AdminAddress); - treasuryFactory.registerTreasuryImplementation( - platformHash, - 0, - address(allOrNothingImplementation) - ); + treasuryFactory.registerTreasuryImplementation(platformHash, 0, address(allOrNothingImplementation)); vm.stopPrank(); } @@ -106,10 +99,8 @@ abstract contract AllOrNothing_Integration_Shared_Test is Vm.Log[] memory entries = vm.getRecordedLogs(); vm.stopPrank(); - (bytes32[] memory topics, ) = decodeTopicsAndData( - entries, - "CampaignInfoFactoryCampaignCreated(bytes32,address)", - address(campaignInfoFactory) + (bytes32[] memory topics,) = decodeTopicsAndData( + entries, "CampaignInfoFactoryCampaignCreated(bytes32,address)", address(campaignInfoFactory) ); require(topics.length == 3, "Unexpected topic length for event"); @@ -132,9 +123,7 @@ abstract contract AllOrNothing_Integration_Shared_Test is // Decode the TreasuryDeployed event (bytes32[] memory topics, bytes memory data) = decodeTopicsAndData( - entries, - "TreasuryFactoryTreasuryDeployed(bytes32,uint256,address,address)", - address(treasuryFactory) + entries, "TreasuryFactoryTreasuryDeployed(bytes32,uint256,address,address)", address(treasuryFactory) ); require(topics.length >= 3, "Expected indexed params missing"); @@ -145,12 +134,9 @@ abstract contract AllOrNothing_Integration_Shared_Test is allOrNothing = AllOrNothing(treasuryAddress); } - function addRewards( - address caller, - address treasury, - bytes32[] memory rewardNames, - Reward[] memory rewards - ) internal { + function addRewards(address caller, address treasury, bytes32[] memory rewardNames, Reward[] memory rewards) + internal + { vm.startPrank(caller); AllOrNothing(treasury).addRewards(rewardNames, rewards); vm.stopPrank(); @@ -167,14 +153,7 @@ abstract contract AllOrNothing_Integration_Shared_Test is uint256 shippingFee, uint256 launchTime, bytes32 rewardName - ) - internal - returns ( - Vm.Log[] memory logs, - uint256 tokenId, - bytes32[] memory rewards - ) - { + ) internal returns (Vm.Log[] memory logs, uint256 tokenId, bytes32[] memory rewards) { vm.startPrank(caller); vm.recordLogs(); @@ -184,27 +163,17 @@ abstract contract AllOrNothing_Integration_Shared_Test is bytes32[] memory reward = new bytes32[](1); reward[0] = rewardName; - AllOrNothing(allOrNothingAddress).pledgeForAReward( - caller, - address(token), - shippingFee, - reward - ); + AllOrNothing(allOrNothingAddress).pledgeForAReward(caller, address(token), shippingFee, reward); logs = vm.getRecordedLogs(); (bytes32[] memory topics, bytes memory data) = decodeTopicsAndData( - logs, - "Receipt(address,address,bytes32,uint256,uint256,uint256,bytes32[])", - allOrNothingAddress + logs, "Receipt(address,address,bytes32,uint256,uint256,uint256,bytes32[])", allOrNothingAddress ); // Indexed params: backer (topics[1]), pledgeToken (topics[2]) // Data params: reward, pledgeAmount, shippingFee, tokenId, rewards - (, , , tokenId, rewards) = abi.decode( - data, - (bytes32, uint256, uint256, uint256, bytes32[]) - ); + (,,, tokenId, rewards) = abi.decode(data, (bytes32, uint256, uint256, uint256, bytes32[])); vm.stopPrank(); } @@ -225,69 +194,43 @@ abstract contract AllOrNothing_Integration_Shared_Test is testToken.approve(allOrNothingAddress, pledgeAmount); vm.warp(launchTime); - AllOrNothing(allOrNothingAddress).pledgeWithoutAReward( - caller, - address(token), - pledgeAmount - ); + AllOrNothing(allOrNothingAddress).pledgeWithoutAReward(caller, address(token), pledgeAmount); logs = vm.getRecordedLogs(); // Decode receipt event if available (bytes32[] memory topics, bytes memory data) = decodeTopicsAndData( - logs, - "Receipt(address,address,bytes32,uint256,uint256,uint256,bytes32[])", - allOrNothingAddress + logs, "Receipt(address,address,bytes32,uint256,uint256,uint256,bytes32[])", allOrNothingAddress ); // Indexed params: backer (topics[1]), pledgeToken (topics[2]) // Data params: reward, pledgeAmount, shippingFee, tokenId, rewards - (, , , tokenId, ) = abi.decode( - data, - (bytes32, uint256, uint256, uint256, bytes32[]) - ); + (,,, tokenId,) = abi.decode(data, (bytes32, uint256, uint256, uint256, bytes32[])); vm.stopPrank(); } /** * @notice Implements claimRefund helper function. */ - function claimRefund( - address caller, - address allOrNothingAddress, - uint256 tokenId, - uint256 warpTime - ) + function claimRefund(address caller, address allOrNothingAddress, uint256 tokenId, uint256 warpTime) internal - returns ( - Vm.Log[] memory logs, - uint256 refundedTokenId, - uint256 refundAmount, - address claimer - ) + returns (Vm.Log[] memory logs, uint256 refundedTokenId, uint256 refundAmount, address claimer) { vm.warp(warpTime); vm.startPrank(caller); - + // Approve treasury to burn NFT CampaignInfo(campaignAddress).approve(allOrNothingAddress, tokenId); - + vm.recordLogs(); AllOrNothing(allOrNothingAddress).claimRefund(tokenId); logs = vm.getRecordedLogs(); - bytes memory data = decodeEventFromLogs( - logs, - "RefundClaimed(uint256,uint256,address)", - allOrNothingAddress - ); + bytes memory data = decodeEventFromLogs(logs, "RefundClaimed(uint256,uint256,address)", allOrNothingAddress); - (refundedTokenId, refundAmount, claimer) = abi.decode( - data, - (uint256, uint256, address) - ); + (refundedTokenId, refundAmount, claimer) = abi.decode(data, (uint256, uint256, address)); vm.stopPrank(); } @@ -295,16 +238,9 @@ abstract contract AllOrNothing_Integration_Shared_Test is /** * @notice Implements disburseFees helper function. */ - function disburseFees( - address allOrNothingAddress, - uint256 warpTime - ) + function disburseFees(address allOrNothingAddress, uint256 warpTime) internal - returns ( - Vm.Log[] memory logs, - uint256 protocolShare, - uint256 platformShare - ) + returns (Vm.Log[] memory logs, uint256 protocolShare, uint256 platformShare) { vm.warp(warpTime); vm.recordLogs(); @@ -313,11 +249,8 @@ abstract contract AllOrNothing_Integration_Shared_Test is logs = vm.getRecordedLogs(); - (bytes32[] memory topics, bytes memory data) = decodeTopicsAndData( - logs, - "FeesDisbursed(address,uint256,uint256)", - allOrNothingAddress - ); + (bytes32[] memory topics, bytes memory data) = + decodeTopicsAndData(logs, "FeesDisbursed(address,uint256,uint256)", allOrNothingAddress); // topics[1] is the indexed token (protocolShare, platformShare) = abi.decode(data, (uint256, uint256)); @@ -326,10 +259,10 @@ abstract contract AllOrNothing_Integration_Shared_Test is /** * @notice Implements withdraw helper function. */ - function withdraw( - address allOrNothingAddress, - uint256 warpTime - ) internal returns (Vm.Log[] memory logs, address to, uint256 amount) { + function withdraw(address allOrNothingAddress, uint256 warpTime) + internal + returns (Vm.Log[] memory logs, address to, uint256 amount) + { vm.warp(warpTime); // Start recording logs and simulate the withdrawal process vm.recordLogs(); @@ -341,11 +274,8 @@ abstract contract AllOrNothing_Integration_Shared_Test is logs = vm.getRecordedLogs(); // Decode the data from the logs - (bytes32[] memory topics, bytes memory data) = decodeTopicsAndData( - logs, - "WithdrawalSuccessful(address,address,uint256)", - allOrNothingAddress - ); + (bytes32[] memory topics, bytes memory data) = + decodeTopicsAndData(logs, "WithdrawalSuccessful(address,address,uint256)", allOrNothingAddress); // topics[1] is the indexed token // Decode the amount and the address of the receiver diff --git a/test/foundry/integration/AllOrNothing/AllOrNothingFunction.t.sol b/test/foundry/integration/AllOrNothing/AllOrNothingFunction.t.sol index 43f0c5f7..6037e124 100644 --- a/test/foundry/integration/AllOrNothing/AllOrNothingFunction.t.sol +++ b/test/foundry/integration/AllOrNothing/AllOrNothingFunction.t.sol @@ -9,18 +9,11 @@ import {Defaults} from "../../utils/Defaults.sol"; import {Constants} from "../../utils/Constants.sol"; import {Users} from "../../utils/Types.sol"; import {IReward} from "src/interfaces/IReward.sol"; -import {TestToken} from "../../../mocks/TestToken.sol"; +import {TestToken} from "../../../mocks/TestToken.sol"; -contract AllOrNothingFunction_Integration_Shared_Test is - AllOrNothing_Integration_Shared_Test -{ +contract AllOrNothingFunction_Integration_Shared_Test is AllOrNothing_Integration_Shared_Test { function test_addRewards() external { - addRewards( - users.creator1Address, - address(allOrNothing), - REWARD_NAMES, - REWARDS - ); + addRewards(users.creator1Address, address(allOrNothing), REWARD_NAMES, REWARDS); // Verify all rewards were added correctly // First reward @@ -51,27 +44,18 @@ contract AllOrNothingFunction_Integration_Shared_Test is } function test_pledgeForAReward() external { - addRewards( - users.creator1Address, + addRewards(users.creator1Address, address(allOrNothing), REWARD_NAMES, REWARDS); + + (Vm.Log[] memory logs, uint256 tokenId, bytes32[] memory rewards) = pledgeForAReward( + users.backer1Address, + address(testToken), address(allOrNothing), - REWARD_NAMES, - REWARDS + PLEDGE_AMOUNT, + SHIPPING_FEE, + LAUNCH_TIME, + REWARD_NAME_1_HASH ); - ( - Vm.Log[] memory logs, - uint256 tokenId, - bytes32[] memory rewards - ) = pledgeForAReward( - users.backer1Address, - address(testToken), - address(allOrNothing), - PLEDGE_AMOUNT, - SHIPPING_FEE, - LAUNCH_TIME, - REWARD_NAME_1_HASH - ); - uint256 backerBalance = testToken.balanceOf(users.backer1Address); uint256 treasuryBalance = testToken.balanceOf(address(allOrNothing)); uint256 backerNftBalance = CampaignInfo(campaignAddress).balanceOf(users.backer1Address); @@ -83,14 +67,9 @@ contract AllOrNothingFunction_Integration_Shared_Test is } function test_claimRefund() external { - addRewards( - users.creator1Address, - address(allOrNothing), - REWARD_NAMES, - REWARDS - ); + addRewards(users.creator1Address, address(allOrNothing), REWARD_NAMES, REWARDS); - (, uint256 rewardTokenId, ) = pledgeForAReward( + (, uint256 rewardTokenId,) = pledgeForAReward( users.backer1Address, address(testToken), address(allOrNothing), @@ -101,19 +80,11 @@ contract AllOrNothingFunction_Integration_Shared_Test is ); (, uint256 tokenId) = pledgeWithoutAReward( - users.backer1Address, - address(testToken), - address(allOrNothing), - PLEDGE_AMOUNT, - LAUNCH_TIME + users.backer1Address, address(testToken), address(allOrNothing), PLEDGE_AMOUNT, LAUNCH_TIME ); - ( - Vm.Log[] memory refundLogs, - uint256 refundedTokenId, - uint256 refundAmount, - address claimer - ) = claimRefund(users.backer1Address, address(allOrNothing), tokenId, LAUNCH_TIME + 1 days); + (Vm.Log[] memory refundLogs, uint256 refundedTokenId, uint256 refundAmount, address claimer) = + claimRefund(users.backer1Address, address(allOrNothing), tokenId, LAUNCH_TIME + 1 days); assertEq(refundedTokenId, tokenId); assertEq(refundAmount, PLEDGE_AMOUNT); @@ -121,12 +92,7 @@ contract AllOrNothingFunction_Integration_Shared_Test is } function test_disburseFees() external { - addRewards( - users.creator1Address, - address(allOrNothing), - REWARD_NAMES, - REWARDS - ); + addRewards(users.creator1Address, address(allOrNothing), REWARD_NAMES, REWARDS); pledgeForAReward( users.backer1Address, @@ -137,46 +103,22 @@ contract AllOrNothingFunction_Integration_Shared_Test is LAUNCH_TIME, REWARD_NAME_1_HASH ); - pledgeWithoutAReward( - users.backer2Address, - address(testToken), - address(allOrNothing), - GOAL_AMOUNT, - LAUNCH_TIME - ); + pledgeWithoutAReward(users.backer2Address, address(testToken), address(allOrNothing), GOAL_AMOUNT, LAUNCH_TIME); uint256 totalPledged = GOAL_AMOUNT + PLEDGE_AMOUNT; - ( - Vm.Log[] memory logs, - uint256 protocolShare, - uint256 platformShare - ) = disburseFees(address(allOrNothing), DEADLINE + 1 days); + (Vm.Log[] memory logs, uint256 protocolShare, uint256 platformShare) = + disburseFees(address(allOrNothing), DEADLINE + 1 days); - uint256 expectedProtocolShare = (totalPledged * PROTOCOL_FEE_PERCENT) / - PERCENT_DIVIDER; - uint256 expectedPlatformShare = (totalPledged * PLATFORM_FEE_PERCENT) / - PERCENT_DIVIDER; + uint256 expectedProtocolShare = (totalPledged * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 expectedPlatformShare = (totalPledged * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; - assertEq( - protocolShare, - expectedProtocolShare, - "Incorrect protocol fee" - ); - assertEq( - platformShare, - expectedPlatformShare, - "Incorrect platform fee" - ); + assertEq(protocolShare, expectedProtocolShare, "Incorrect protocol fee"); + assertEq(platformShare, expectedPlatformShare, "Incorrect platform fee"); } function test_withdraw() external { - addRewards( - users.creator1Address, - address(allOrNothing), - REWARD_NAMES, - REWARDS - ); + addRewards(users.creator1Address, address(allOrNothing), REWARD_NAMES, REWARDS); pledgeForAReward( users.backer1Address, @@ -187,36 +129,18 @@ contract AllOrNothingFunction_Integration_Shared_Test is LAUNCH_TIME, REWARD_NAME_1_HASH ); - pledgeWithoutAReward( - users.backer2Address, - address(testToken), - address(allOrNothing), - GOAL_AMOUNT, - LAUNCH_TIME - ); + pledgeWithoutAReward(users.backer2Address, address(testToken), address(allOrNothing), GOAL_AMOUNT, LAUNCH_TIME); uint256 totalPledged = GOAL_AMOUNT + PLEDGE_AMOUNT; disburseFees(address(allOrNothing), DEADLINE + 1 days); - (Vm.Log[] memory logs, address to, uint256 amount) = withdraw( - address(allOrNothing), - DEADLINE - ); + (Vm.Log[] memory logs, address to, uint256 amount) = withdraw(address(allOrNothing), DEADLINE); - uint256 protocolShare = (totalPledged * PROTOCOL_FEE_PERCENT) / - PERCENT_DIVIDER; - uint256 platformShare = (totalPledged * PLATFORM_FEE_PERCENT) / - PERCENT_DIVIDER; - uint256 expectedAmount = totalPledged + - SHIPPING_FEE - - protocolShare - - platformShare; + uint256 protocolShare = (totalPledged * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 platformShare = (totalPledged * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; + uint256 expectedAmount = totalPledged + SHIPPING_FEE - protocolShare - platformShare; - assertEq( - to, - users.creator1Address, - "Incorrect address receiving the funds" - ); + assertEq(to, users.creator1Address, "Incorrect address receiving the funds"); assertEq(amount, expectedAmount, "Incorrect withdrawal amount"); } @@ -225,133 +149,93 @@ contract AllOrNothingFunction_Integration_Shared_Test is //////////////////////////////////////////////////////////////*/ function test_pledgeWithMultipleTokens() external { - addRewards( - users.creator1Address, - address(allOrNothing), - REWARD_NAMES, - REWARDS - ); + addRewards(users.creator1Address, address(allOrNothing), REWARD_NAMES, REWARDS); // Pledge with USDC (6 decimals) uint256 usdcPledgeAmount = getTokenAmount(address(usdcToken), PLEDGE_AMOUNT); - uint256 usdcShippingFee = getTokenAmount(address(usdcToken), SHIPPING_FEE); - + uint256 usdcShippingFee = getTokenAmount(address(usdcToken), SHIPPING_FEE); + vm.startPrank(users.backer1Address); usdcToken.approve(address(allOrNothing), usdcPledgeAmount + usdcShippingFee); vm.warp(LAUNCH_TIME); - + bytes32[] memory reward1 = new bytes32[](1); reward1[0] = REWARD_NAME_1_HASH; - allOrNothing.pledgeForAReward( - users.backer1Address, - address(usdcToken), - usdcShippingFee, - reward1 - ); + allOrNothing.pledgeForAReward(users.backer1Address, address(usdcToken), usdcShippingFee, reward1); vm.stopPrank(); - + // Pledge with cUSD (18 decimals) - no conversion needed vm.startPrank(users.backer2Address); cUSDToken.approve(address(allOrNothing), PLEDGE_AMOUNT); - allOrNothing.pledgeWithoutAReward( - users.backer2Address, - address(cUSDToken), - PLEDGE_AMOUNT - ); + allOrNothing.pledgeWithoutAReward(users.backer2Address, address(cUSDToken), PLEDGE_AMOUNT); vm.stopPrank(); - + // Verify balances assertEq(usdcToken.balanceOf(address(allOrNothing)), usdcPledgeAmount + usdcShippingFee); assertEq(cUSDToken.balanceOf(address(allOrNothing)), PLEDGE_AMOUNT); - + // Verify normalized raised amount uint256 totalRaised = allOrNothing.getRaisedAmount(); assertEq(totalRaised, PLEDGE_AMOUNT * 2, "Total raised should be sum of normalized amounts"); } function test_getRaisedAmountNormalizesCorrectly() external { - addRewards( - users.creator1Address, - address(allOrNothing), - REWARD_NAMES, - REWARDS - ); - + addRewards(users.creator1Address, address(allOrNothing), REWARD_NAMES, REWARDS); + // Pledge same base amount in different tokens uint256 baseAmount = 1000e18; - + // USDC pledge (6 decimals) uint256 usdcAmount = baseAmount / 1e12; vm.startPrank(users.backer1Address); usdcToken.approve(address(allOrNothing), usdcAmount); vm.warp(LAUNCH_TIME); - allOrNothing.pledgeWithoutAReward( - users.backer1Address, - address(usdcToken), - usdcAmount - ); + allOrNothing.pledgeWithoutAReward(users.backer1Address, address(usdcToken), usdcAmount); vm.stopPrank(); - + uint256 raisedAfterUSDC = allOrNothing.getRaisedAmount(); assertEq(raisedAfterUSDC, baseAmount, "USDC amount should be normalized to 18 decimals"); - + // cUSD pledge (18 decimals) vm.startPrank(users.backer2Address); cUSDToken.approve(address(allOrNothing), baseAmount); - allOrNothing.pledgeWithoutAReward( - users.backer2Address, - address(cUSDToken), - baseAmount - ); + allOrNothing.pledgeWithoutAReward(users.backer2Address, address(cUSDToken), baseAmount); vm.stopPrank(); - + uint256 raisedAfterCUSD = allOrNothing.getRaisedAmount(); assertEq(raisedAfterCUSD, baseAmount * 2, "Total should be sum of normalized amounts"); } function test_disburseFeesWithMultipleTokens() external { - addRewards( - users.creator1Address, - address(allOrNothing), - REWARD_NAMES, - REWARDS - ); - + addRewards(users.creator1Address, address(allOrNothing), REWARD_NAMES, REWARDS); + // Pledge with USDC uint256 usdcAmount = getTokenAmount(address(usdcToken), PLEDGE_AMOUNT); vm.startPrank(users.backer1Address); usdcToken.approve(address(allOrNothing), usdcAmount); vm.warp(LAUNCH_TIME); - allOrNothing.pledgeWithoutAReward( - users.backer1Address, - address(usdcToken), - usdcAmount - ); + allOrNothing.pledgeWithoutAReward(users.backer1Address, address(usdcToken), usdcAmount); vm.stopPrank(); - + // Pledge with cUSD to meet goal vm.startPrank(users.backer2Address); cUSDToken.approve(address(allOrNothing), GOAL_AMOUNT); - allOrNothing.pledgeWithoutAReward( - users.backer2Address, - address(cUSDToken), - GOAL_AMOUNT - ); + allOrNothing.pledgeWithoutAReward(users.backer2Address, address(cUSDToken), GOAL_AMOUNT); vm.stopPrank(); - + uint256 protocolBalanceUSDCBefore = usdcToken.balanceOf(users.protocolAdminAddress); uint256 platformBalanceUSDCBefore = usdcToken.balanceOf(users.platform1AdminAddress); uint256 protocolBalanceCUSDBefore = cUSDToken.balanceOf(users.protocolAdminAddress); uint256 platformBalanceCUSDBefore = cUSDToken.balanceOf(users.platform1AdminAddress); - + // Disburse fees vm.warp(DEADLINE + 1 days); allOrNothing.disburseFees(); - + // Verify USDC fees uint256 expectedUSDCProtocolFee = (usdcAmount * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; uint256 expectedUSDCPlatformFee = (usdcAmount * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; - + assertEq( usdcToken.balanceOf(users.protocolAdminAddress) - protocolBalanceUSDCBefore, expectedUSDCProtocolFee, @@ -362,11 +246,11 @@ contract AllOrNothingFunction_Integration_Shared_Test is expectedUSDCPlatformFee, "Incorrect USDC platform fee" ); - + // Verify cUSD fees uint256 expectedCUSDProtocolFee = (GOAL_AMOUNT * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; uint256 expectedCUSDPlatformFee = (GOAL_AMOUNT * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; - + assertEq( cUSDToken.balanceOf(users.protocolAdminAddress) - protocolBalanceCUSDBefore, expectedCUSDProtocolFee, @@ -380,61 +264,44 @@ contract AllOrNothingFunction_Integration_Shared_Test is } function test_withdrawWithMultipleTokens() external { - addRewards( - users.creator1Address, - address(allOrNothing), - REWARD_NAMES, - REWARDS - ); - + addRewards(users.creator1Address, address(allOrNothing), REWARD_NAMES, REWARDS); + // Pledge with multiple tokens uint256 usdcAmount = getTokenAmount(address(usdcToken), PLEDGE_AMOUNT); uint256 usdtAmount = getTokenAmount(address(usdtToken), PLEDGE_AMOUNT); - + vm.startPrank(users.backer1Address); usdcToken.approve(address(allOrNothing), usdcAmount); vm.warp(LAUNCH_TIME); - allOrNothing.pledgeWithoutAReward( - users.backer1Address, - address(usdcToken), - usdcAmount - ); + allOrNothing.pledgeWithoutAReward(users.backer1Address, address(usdcToken), usdcAmount); vm.stopPrank(); - + vm.startPrank(users.backer2Address); usdtToken.approve(address(allOrNothing), usdtAmount); - allOrNothing.pledgeWithoutAReward( - users.backer2Address, - address(usdtToken), - usdtAmount - ); + allOrNothing.pledgeWithoutAReward(users.backer2Address, address(usdtToken), usdtAmount); vm.stopPrank(); - + // Need cUSD pledge to meet goal vm.startPrank(users.backer1Address); cUSDToken.approve(address(allOrNothing), GOAL_AMOUNT); - allOrNothing.pledgeWithoutAReward( - users.backer1Address, - address(cUSDToken), - GOAL_AMOUNT - ); + allOrNothing.pledgeWithoutAReward(users.backer1Address, address(cUSDToken), GOAL_AMOUNT); vm.stopPrank(); - + // Disburse fees and withdraw vm.warp(DEADLINE + 1 days); allOrNothing.disburseFees(); - + uint256 creatorUSDCBefore = usdcToken.balanceOf(users.creator1Address); uint256 creatorUSDTBefore = usdtToken.balanceOf(users.creator1Address); uint256 creatorCUSDBefore = cUSDToken.balanceOf(users.creator1Address); - + allOrNothing.withdraw(); - + // Verify all tokens were withdrawn assertTrue(usdcToken.balanceOf(users.creator1Address) > creatorUSDCBefore, "Creator should receive USDC"); assertTrue(usdtToken.balanceOf(users.creator1Address) > creatorUSDTBefore, "Creator should receive USDT"); assertTrue(cUSDToken.balanceOf(users.creator1Address) > creatorCUSDBefore, "Creator should receive cUSD"); - + // Verify treasury is empty assertEq(usdcToken.balanceOf(address(allOrNothing)), 0, "USDC should be fully withdrawn"); assertEq(usdtToken.balanceOf(address(allOrNothing)), 0, "USDT should be fully withdrawn"); @@ -442,68 +309,47 @@ contract AllOrNothingFunction_Integration_Shared_Test is } function test_refundWithCorrectToken() external { - addRewards( - users.creator1Address, - address(allOrNothing), - REWARD_NAMES, - REWARDS - ); - + addRewards(users.creator1Address, address(allOrNothing), REWARD_NAMES, REWARDS); + // Backer1 pledges with USDC uint256 usdcAmount = getTokenAmount(address(usdcToken), PLEDGE_AMOUNT); vm.startPrank(users.backer1Address); usdcToken.approve(address(allOrNothing), usdcAmount); vm.warp(LAUNCH_TIME); - allOrNothing.pledgeWithoutAReward( - users.backer1Address, - address(usdcToken), - usdcAmount - ); + allOrNothing.pledgeWithoutAReward(users.backer1Address, address(usdcToken), usdcAmount); uint256 usdcTokenId = 1; // First pledge vm.stopPrank(); - + // Backer2 pledges with cUSD vm.startPrank(users.backer2Address); cUSDToken.approve(address(allOrNothing), PLEDGE_AMOUNT); - allOrNothing.pledgeWithoutAReward( - users.backer2Address, - address(cUSDToken), - PLEDGE_AMOUNT - ); + allOrNothing.pledgeWithoutAReward(users.backer2Address, address(cUSDToken), PLEDGE_AMOUNT); uint256 cUSDTokenId = 2; // Second pledge vm.stopPrank(); - + uint256 backer1USDCBefore = usdcToken.balanceOf(users.backer1Address); uint256 backer2CUSDBefore = cUSDToken.balanceOf(users.backer2Address); - + // Claim refunds vm.warp(LAUNCH_TIME + 1 days); - + // Approve treasury to burn NFTs vm.prank(users.backer1Address); CampaignInfo(campaignAddress).approve(address(allOrNothing), usdcTokenId); - + vm.prank(users.backer1Address); allOrNothing.claimRefund(usdcTokenId); - + vm.prank(users.backer2Address); CampaignInfo(campaignAddress).approve(address(allOrNothing), cUSDTokenId); - + vm.prank(users.backer2Address); allOrNothing.claimRefund(cUSDTokenId); - + // Verify refunds in correct tokens - assertEq( - usdcToken.balanceOf(users.backer1Address) - backer1USDCBefore, - usdcAmount, - "Should refund in USDC" - ); - assertEq( - cUSDToken.balanceOf(users.backer2Address) - backer2CUSDBefore, - PLEDGE_AMOUNT, - "Should refund in cUSD" - ); - + assertEq(usdcToken.balanceOf(users.backer1Address) - backer1USDCBefore, usdcAmount, "Should refund in USDC"); + assertEq(cUSDToken.balanceOf(users.backer2Address) - backer2CUSDBefore, PLEDGE_AMOUNT, "Should refund in cUSD"); + // Verify no cross-token refunds assertEq(cUSDToken.balanceOf(users.backer1Address), TOKEN_MINT_AMOUNT, "Should not receive cUSD"); assertEq(usdcToken.balanceOf(users.backer2Address), TOKEN_MINT_AMOUNT / 1e12, "Should not receive USDC"); @@ -513,29 +359,17 @@ contract AllOrNothingFunction_Integration_Shared_Test is // Create a token not in the accepted list TestToken unacceptedToken = new TestToken("Unaccepted", "UNA", 18); unacceptedToken.mint(users.backer1Address, PLEDGE_AMOUNT); - - addRewards( - users.creator1Address, - address(allOrNothing), - REWARD_NAMES, - REWARDS - ); - + + addRewards(users.creator1Address, address(allOrNothing), REWARD_NAMES, REWARDS); + vm.startPrank(users.backer1Address); unacceptedToken.approve(address(allOrNothing), PLEDGE_AMOUNT); vm.warp(LAUNCH_TIME); - + vm.expectRevert( - abi.encodeWithSelector( - AllOrNothing.AllOrNothingTokenNotAccepted.selector, - address(unacceptedToken) - ) - ); - allOrNothing.pledgeWithoutAReward( - users.backer1Address, - address(unacceptedToken), - PLEDGE_AMOUNT + abi.encodeWithSelector(AllOrNothing.AllOrNothingTokenNotAccepted.selector, address(unacceptedToken)) ); + allOrNothing.pledgeWithoutAReward(users.backer1Address, address(unacceptedToken), PLEDGE_AMOUNT); vm.stopPrank(); } } diff --git a/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaised.t.sol b/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaised.t.sol index 32cdf74c..02bdcd9b 100644 --- a/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaised.t.sol +++ b/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaised.t.sol @@ -32,7 +32,7 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder approveTreasuryImplementation(PLATFORM_2_HASH); console.log("approved treasury"); - + // Create Campaign createCampaign(PLATFORM_2_HASH); console.log("created campaign"); @@ -61,7 +61,7 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder */ function enlistPlatform(bytes32 platformHash) internal { vm.startPrank(users.protocolAdminAddress); - globalParams.enlistPlatform(platformHash, users.platform2AdminAddress, PLATFORM_FEE_PERCENT); + globalParams.enlistPlatform(platformHash, users.platform2AdminAddress, PLATFORM_FEE_PERCENT, address(0)); vm.stopPrank(); } @@ -116,8 +116,8 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder users.creator1Address, identifierHash, selectedPlatformHash, - platformDataKey, - platformDataValue, + platformDataKey, + platformDataValue, CAMPAIGN_DATA, "Campaign Pledge NFT", "PLEDGE", @@ -276,17 +276,18 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder testToken.approve(treasury, pledgeAmount + tip); } - KeepWhatsRaised(treasury).setFeeAndPledge(pledgeId, backer, address(testToken), pledgeAmount, tip, fee, reward, isPledgeForAReward); + KeepWhatsRaised(treasury).setFeeAndPledge( + pledgeId, backer, address(testToken), pledgeAmount, tip, fee, reward, isPledgeForAReward + ); logs = vm.getRecordedLogs(); - (bytes32[] memory topics, bytes memory data) = decodeTopicsAndData( - logs, "Receipt(address,address,bytes32,uint256,uint256,uint256,bytes32[])", treasury - ); + (bytes32[] memory topics, bytes memory data) = + decodeTopicsAndData(logs, "Receipt(address,address,bytes32,uint256,uint256,uint256,bytes32[])", treasury); // Indexed params: backer (topics[1]), pledgeToken (topics[2]) // Data params: reward, pledgeAmount, tip, tokenId, rewards - (,, , tokenId, rewards) = abi.decode(data, (bytes32, uint256, uint256, uint256, bytes32[])); + (,,, tokenId, rewards) = abi.decode(data, (bytes32, uint256, uint256, uint256, bytes32[])); vm.stopPrank(); } @@ -323,7 +324,7 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder // Indexed params: backer (topics[1]), pledgeToken (topics[2]) // Data params: reward, pledgeAmount, tip, tokenId, rewards - (,, , tokenId, rewards) = abi.decode(data, (bytes32, uint256, uint256, uint256, bytes32[])); + (,,, tokenId, rewards) = abi.decode(data, (bytes32, uint256, uint256, uint256, bytes32[])); vm.stopPrank(); } @@ -356,7 +357,7 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder // Indexed params: backer (topics[1]), pledgeToken (topics[2]) // Data params: reward, pledgeAmount, tip, tokenId, rewards - (,, , tokenId,) = abi.decode(data, (bytes32, uint256, uint256, uint256, bytes32[])); + (,,, tokenId,) = abi.decode(data, (bytes32, uint256, uint256, uint256, bytes32[])); vm.stopPrank(); } @@ -381,7 +382,7 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder to = address(uint160(uint256(topics[1]))); (withdrawalAmount, fee) = abi.decode(data, (uint256, uint256)); - + vm.stopPrank(); } @@ -393,10 +394,10 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder returns (Vm.Log[] memory logs, uint256 refundedTokenId, uint256 refundAmount, address claimer) { vm.startPrank(caller); - + // Approve treasury to burn NFT CampaignInfo(campaignAddress).approve(keepWhatsRaisedAddress, tokenId); - + vm.recordLogs(); KeepWhatsRaised(keepWhatsRaisedAddress).claimRefund(tokenId); @@ -477,7 +478,8 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder logs = vm.getRecordedLogs(); - (bytes32[] memory topics, bytes memory data) = decodeTopicsAndData(logs, "FeesDisbursed(address,uint256,uint256)", keepWhatsRaisedAddress); + (bytes32[] memory topics, bytes memory data) = + decodeTopicsAndData(logs, "FeesDisbursed(address,uint256,uint256)", keepWhatsRaisedAddress); // topics[1] is the indexed token (protocolShare, platformShare) = abi.decode(data, (uint256, uint256)); @@ -491,4 +493,4 @@ abstract contract KeepWhatsRaised_Integration_Shared_Test is IReward, LogDecoder KeepWhatsRaised(treasury).cancelTreasury(message); vm.stopPrank(); } -} \ No newline at end of file +} diff --git a/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaisedFunction.t.sol b/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaisedFunction.t.sol index 81cd5dd2..35cd7b7f 100644 --- a/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaisedFunction.t.sol +++ b/test/foundry/integration/KeepWhatsRaised/KeepWhatsRaisedFunction.t.sol @@ -24,7 +24,7 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte function test_addRewards() external { addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); - + // First reward Reward memory resultReward1 = keepWhatsRaised.getReward(REWARD_NAMES[0]); assertEq(REWARDS[0].rewardValue, resultReward1.rewardValue); @@ -53,17 +53,21 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte } function test_setPaymentGatewayFee() external { - setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); - + setPaymentGatewayFee( + users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE + ); + uint256 fee = keepWhatsRaised.getPaymentGatewayFee(TEST_PLEDGE_ID_1); assertEq(fee, PAYMENT_GATEWAY_FEE); } function test_pledgeForARewardWithGatewayFee() external { addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); - + // Set gateway fee first - setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); + setPaymentGatewayFee( + users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE + ); (Vm.Log[] memory logs, uint256 tokenId, bytes32[] memory rewards) = pledgeForAReward( users.backer1Address, @@ -92,12 +96,20 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte function test_pledgeWithoutARewardWithGatewayFee() external { addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); - + // Set gateway fee first - setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); + setPaymentGatewayFee( + users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE + ); (, uint256 tokenId) = pledgeWithoutAReward( - users.backer1Address, address(testToken), address(keepWhatsRaised), TEST_PLEDGE_ID_1, PLEDGE_AMOUNT, TIP_AMOUNT, LAUNCH_TIME + users.backer1Address, + address(testToken), + address(keepWhatsRaised), + TEST_PLEDGE_ID_1, + PLEDGE_AMOUNT, + TIP_AMOUNT, + LAUNCH_TIME ); uint256 treasuryBalance = testToken.balanceOf(address(keepWhatsRaised)); @@ -115,12 +127,12 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte function test_setFeeAndPledgeForReward() external { addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); - + vm.warp(LAUNCH_TIME); - + bytes32[] memory reward = new bytes32[](1); reward[0] = REWARD_NAME_1_HASH; - + (Vm.Log[] memory logs, uint256 tokenId, bytes32[] memory rewards) = setFeeAndPledge( users.platform2AdminAddress, address(keepWhatsRaised), @@ -132,10 +144,10 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte reward, true ); - + // Verify fee was set assertEq(keepWhatsRaised.getPaymentGatewayFee(TEST_PLEDGE_ID_1), PAYMENT_GATEWAY_FEE); - + // Verify pledge was made - tokens come from admin not backer address nftOwnerAddress = CampaignInfo(campaignAddress).ownerOf(tokenId); assertEq(users.backer1Address, nftOwnerAddress); @@ -143,9 +155,9 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte function test_setFeeAndPledgeWithoutReward() external { vm.warp(LAUNCH_TIME); - + bytes32[] memory emptyReward = new bytes32[](0); - + (Vm.Log[] memory logs, uint256 tokenId, bytes32[] memory rewards) = setFeeAndPledge( users.platform2AdminAddress, address(keepWhatsRaised), @@ -157,10 +169,10 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte emptyReward, false ); - + // Verify fee was set assertEq(keepWhatsRaised.getPaymentGatewayFee(TEST_PLEDGE_ID_1), PAYMENT_GATEWAY_FEE); - + // Verify pledge was made - tokens come from admin not backer address nftOwnerAddress = CampaignInfo(campaignAddress).ownerOf(tokenId); assertEq(users.backer1Address, nftOwnerAddress); @@ -169,12 +181,16 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte function test_withdrawWithColombianCreatorTax() external { // Configure with Colombian creator KeepWhatsRaised.FeeValues memory feeValues = createFeeValues(); - configureTreasury(users.platform2AdminAddress, address(keepWhatsRaised), CONFIG_COLOMBIAN, CAMPAIGN_DATA, FEE_KEYS, feeValues); - + configureTreasury( + users.platform2AdminAddress, address(keepWhatsRaised), CONFIG_COLOMBIAN, CAMPAIGN_DATA, FEE_KEYS, feeValues + ); + addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); // Make pledges with gateway fees - setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); + setPaymentGatewayFee( + users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE + ); pledgeForAReward( users.backer1Address, address(testToken), @@ -185,10 +201,18 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte LAUNCH_TIME, REWARD_NAME_1_HASH ); - - setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_2, PAYMENT_GATEWAY_FEE); + + setPaymentGatewayFee( + users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_2, PAYMENT_GATEWAY_FEE + ); pledgeWithoutAReward( - users.backer2Address, address(testToken), address(keepWhatsRaised), TEST_PLEDGE_ID_2, GOAL_AMOUNT, TIP_AMOUNT, LAUNCH_TIME + users.backer2Address, + address(testToken), + address(keepWhatsRaised), + TEST_PLEDGE_ID_2, + GOAL_AMOUNT, + TIP_AMOUNT, + LAUNCH_TIME ); approveWithdrawal(users.platform2AdminAddress, address(keepWhatsRaised)); @@ -212,7 +236,9 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); // Make pledge with gateway fee - setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); + setPaymentGatewayFee( + users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE + ); (, uint256 tokenId,) = pledgeForAReward( users.backer1Address, address(testToken), @@ -233,7 +259,7 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte uint256 backerBalanceAfter = testToken.balanceOf(users.backer1Address); assertEq(refundedTokenId, tokenId); - + // Account for all fees including protocol fee uint256 platformFee = (PLEDGE_AMOUNT * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; uint256 vakiCommission = (PLEDGE_AMOUNT * uint256(VAKI_COMMISSION_VALUE)) / PERCENT_DIVIDER; @@ -249,7 +275,9 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); // Make pledges with gateway fees - setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); + setPaymentGatewayFee( + users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE + ); pledgeForAReward( users.backer1Address, address(testToken), @@ -260,15 +288,23 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte LAUNCH_TIME, REWARD_NAME_1_HASH ); - - setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_2, PAYMENT_GATEWAY_FEE); + + setPaymentGatewayFee( + users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_2, PAYMENT_GATEWAY_FEE + ); pledgeWithoutAReward( - users.backer2Address, address(testToken), address(keepWhatsRaised), TEST_PLEDGE_ID_2, PLEDGE_AMOUNT, 0, LAUNCH_TIME + users.backer2Address, + address(testToken), + address(keepWhatsRaised), + TEST_PLEDGE_ID_2, + PLEDGE_AMOUNT, + 0, + LAUNCH_TIME ); // Approve and withdraw (as platform admin) approveWithdrawal(users.platform2AdminAddress, address(keepWhatsRaised)); - + vm.warp(DEADLINE - 1 days); vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(address(testToken), PLEDGE_AMOUNT); @@ -308,7 +344,7 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte uint256 originalDeadline = keepWhatsRaised.getDeadline(); uint256 newDeadline = originalDeadline + 14 days; - + address campaignOwner = CampaignInfo(campaignAddress).owner(); updateDeadline(campaignOwner, address(keepWhatsRaised), newDeadline); @@ -331,7 +367,7 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte uint256 originalGoal = keepWhatsRaised.getGoalAmount(); uint256 newGoal = originalGoal * 3; - + address campaignOwner = CampaignInfo(campaignAddress).owner(); updateGoalAmount(campaignOwner, address(keepWhatsRaised), newGoal); @@ -350,7 +386,9 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); // Make pledges - setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); + setPaymentGatewayFee( + users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE + ); pledgeForAReward( users.backer1Address, address(testToken), @@ -361,10 +399,18 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte LAUNCH_TIME, REWARD_NAME_1_HASH ); - - setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_2, PAYMENT_GATEWAY_FEE); + + setPaymentGatewayFee( + users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_2, PAYMENT_GATEWAY_FEE + ); pledgeWithoutAReward( - users.backer2Address, address(testToken), address(keepWhatsRaised), TEST_PLEDGE_ID_2, GOAL_AMOUNT, TIP_AMOUNT, LAUNCH_TIME + users.backer2Address, + address(testToken), + address(keepWhatsRaised), + TEST_PLEDGE_ID_2, + GOAL_AMOUNT, + TIP_AMOUNT, + LAUNCH_TIME ); approveWithdrawal(users.platform2AdminAddress, address(keepWhatsRaised)); @@ -387,16 +433,24 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte function test_withdrawPartial() external { addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); - setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); + setPaymentGatewayFee( + users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE + ); pledgeWithoutAReward( - users.backer1Address, address(testToken), address(keepWhatsRaised), TEST_PLEDGE_ID_1, PLEDGE_AMOUNT, 0, LAUNCH_TIME + users.backer1Address, + address(testToken), + address(keepWhatsRaised), + TEST_PLEDGE_ID_1, + PLEDGE_AMOUNT, + 0, + LAUNCH_TIME ); // Approve withdrawal approveWithdrawal(users.platform2AdminAddress, address(keepWhatsRaised)); uint256 availableBefore = keepWhatsRaised.getAvailableRaisedAmount(); - + // Calculate safe withdrawal amount that accounts for cumulative fee // For small withdrawals, cumulative fee (200e18) is applied // So we need available >= withdrawalAmount + cumulativeFee @@ -410,14 +464,18 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte // For partial withdrawals, the full amount requested is transferred assertEq(withdrawalAmount, partialAmount, "Incorrect partial withdrawal"); // Available amount is reduced by withdrawal amount plus fees - assertEq(availableBefore - availableAfter, partialAmount + fee, "Available should be reduced by withdrawal plus fee"); + assertEq( + availableBefore - availableAfter, partialAmount + fee, "Available should be reduced by withdrawal plus fee" + ); } function test_claimTip() external { addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); // Make pledges with tips - setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); + setPaymentGatewayFee( + users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE + ); pledgeForAReward( users.backer1Address, address(testToken), @@ -428,10 +486,18 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte LAUNCH_TIME, REWARD_NAME_1_HASH ); - - setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_2, PAYMENT_GATEWAY_FEE); + + setPaymentGatewayFee( + users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_2, PAYMENT_GATEWAY_FEE + ); pledgeWithoutAReward( - users.backer2Address, address(testToken), address(keepWhatsRaised), TEST_PLEDGE_ID_2, GOAL_AMOUNT, TIP_AMOUNT * 2, LAUNCH_TIME + users.backer2Address, + address(testToken), + address(keepWhatsRaised), + TEST_PLEDGE_ID_2, + GOAL_AMOUNT, + TIP_AMOUNT * 2, + LAUNCH_TIME ); uint256 totalTips = TIP_AMOUNT + (TIP_AMOUNT * 2); @@ -452,7 +518,9 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); // Make a pledge - setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); + setPaymentGatewayFee( + users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE + ); pledgeForAReward( users.backer1Address, address(testToken), @@ -498,7 +566,9 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); // Make a pledge - setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); + setPaymentGatewayFee( + users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE + ); pledgeForAReward( users.backer1Address, address(testToken), @@ -519,7 +589,9 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte vm.startPrank(users.backer2Address); testToken.approve(address(keepWhatsRaised), PLEDGE_AMOUNT); vm.expectRevert(); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID_2, users.backer2Address, address(testToken), PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward( + TEST_PLEDGE_ID_2, users.backer2Address, address(testToken), PLEDGE_AMOUNT, 0 + ); vm.stopPrank(); } @@ -527,7 +599,9 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); // Make a pledge - setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); + setPaymentGatewayFee( + users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE + ); pledgeForAReward( users.backer1Address, address(testToken), @@ -549,7 +623,9 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte vm.startPrank(users.backer2Address); testToken.approve(address(keepWhatsRaised), PLEDGE_AMOUNT); vm.expectRevert(); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID_2, users.backer2Address, address(testToken), PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward( + TEST_PLEDGE_ID_2, users.backer2Address, address(testToken), PLEDGE_AMOUNT, 0 + ); vm.stopPrank(); } @@ -557,7 +633,9 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte addRewards(users.creator1Address, address(keepWhatsRaised), REWARD_NAMES, REWARDS); // Make pledge with gateway fee - setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE); + setPaymentGatewayFee( + users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID_1, PAYMENT_GATEWAY_FEE + ); (, uint256 tokenId,) = pledgeForAReward( users.backer1Address, address(testToken), @@ -588,9 +666,9 @@ contract KeepWhatsRaisedFunction_Integration_Shared_Test is KeepWhatsRaised_Inte uint256 vakiCommission = (PLEDGE_AMOUNT * uint256(VAKI_COMMISSION_VALUE)) / PERCENT_DIVIDER; uint256 protocolFee = (PLEDGE_AMOUNT * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; uint256 expectedRefund = PLEDGE_AMOUNT - PAYMENT_GATEWAY_FEE - platformFee - vakiCommission - protocolFee; - + assertEq(refundAmount, expectedRefund, "Refund amount should be pledge minus fees"); assertEq(claimer, users.backer1Address); assertEq(backerBalanceAfter - backerBalanceBefore, refundAmount); } -} \ No newline at end of file +} diff --git a/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol b/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol index 431c6459..71004aac 100644 --- a/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol +++ b/test/foundry/integration/PaymentTreasury/PaymentTreasury.t.sol @@ -59,7 +59,7 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te */ function enlistPlatform(bytes32 platformHash) internal { vm.startPrank(users.protocolAdminAddress); - globalParams.enlistPlatform(platformHash, users.platform1AdminAddress, PLATFORM_FEE_PERCENT); + globalParams.enlistPlatform(platformHash, users.platform1AdminAddress, PLATFORM_FEE_PERCENT, address(0)); vm.stopPrank(); } @@ -154,7 +154,9 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te ICampaignPaymentTreasury.ExternalFees[] memory externalFees ) internal { vm.prank(caller); - paymentTreasury.createPayment(paymentId, buyerId, itemId, paymentToken, amount, expiration, lineItems, externalFees); + paymentTreasury.createPayment( + paymentId, buyerId, itemId, paymentToken, amount, expiration, lineItems, externalFees + ); } /** @@ -171,7 +173,9 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te ICampaignPaymentTreasury.ExternalFees[] memory externalFees ) internal { vm.prank(caller); - paymentTreasury.processCryptoPayment(paymentId, itemId, buyerAddress, paymentToken, amount, lineItems, externalFees); + paymentTreasury.processCryptoPayment( + paymentId, itemId, buyerAddress, paymentToken, amount, lineItems, externalFees + ); } /** @@ -201,67 +205,60 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te /** * @notice Claims a refund */ - function claimRefund(address caller, bytes32 paymentId, address refundAddress) - internal - returns (uint256 refundAmount) + function claimRefund(address caller, bytes32 paymentId, address refundAddress) + internal + returns (uint256 refundAmount) { vm.startPrank(caller); vm.recordLogs(); - + paymentTreasury.claimRefund(paymentId, refundAddress); - + Vm.Log[] memory logs = vm.getRecordedLogs(); - - (bytes32[] memory topics, bytes memory data) = decodeTopicsAndData( - logs, "RefundClaimed(bytes32,uint256,address)", treasuryAddress - ); - + + (bytes32[] memory topics, bytes memory data) = + decodeTopicsAndData(logs, "RefundClaimed(bytes32,uint256,address)", treasuryAddress); + refundAmount = abi.decode(data, (uint256)); - + vm.stopPrank(); } /** * @notice Claims a refund (buyer-initiated) */ - function claimRefund(address caller, bytes32 paymentId, uint256 tokenId) - internal - returns (uint256 refundAmount) - { + function claimRefund(address caller, bytes32 paymentId, uint256 tokenId) internal returns (uint256 refundAmount) { vm.startPrank(caller); - + // Approve treasury to burn NFT CampaignInfo(campaignAddress).approve(treasuryAddress, tokenId); - + vm.recordLogs(); - + paymentTreasury.claimRefund(paymentId); - + Vm.Log[] memory logs = vm.getRecordedLogs(); - - (bytes32[] memory topics, bytes memory data) = decodeTopicsAndData( - logs, "RefundClaimed(bytes32,uint256,address)", treasuryAddress - ); - + + (bytes32[] memory topics, bytes memory data) = + decodeTopicsAndData(logs, "RefundClaimed(bytes32,uint256,address)", treasuryAddress); + refundAmount = abi.decode(data, (uint256)); - + vm.stopPrank(); } /** * @notice Disburses fees */ - function disburseFees(address treasury) - internal - returns (uint256 protocolShare, uint256 platformShare) - { + function disburseFees(address treasury) internal returns (uint256 protocolShare, uint256 platformShare) { vm.recordLogs(); PaymentTreasury(treasury).disburseFees(); Vm.Log[] memory logs = vm.getRecordedLogs(); - (bytes32[] memory topics, bytes memory data) = decodeTopicsAndData(logs, "FeesDisbursed(address,uint256,uint256)", treasury); + (bytes32[] memory topics, bytes memory data) = + decodeTopicsAndData(logs, "FeesDisbursed(address,uint256,uint256)", treasury); // topics[1] is the indexed token // Data contains protocolShare and platformShare @@ -271,12 +268,12 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te /** * @notice Withdraws funds */ - function withdraw(address treasury) - internal - returns (address to, uint256 amount, uint256 fee) - { + function withdraw(address treasury) internal returns (address to, uint256 amount, uint256 fee) { vm.recordLogs(); + // Use campaign owner as the authorized caller for withdraw + address campaignOwner = CampaignInfo(campaignAddress).owner(); + vm.prank(campaignOwner); PaymentTreasury(treasury).withdraw(); Vm.Log[] memory logs = vm.getRecordedLogs(); @@ -327,17 +324,28 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te ) internal { // Fund buyer deal(address(testToken), buyerAddress, amount); - + // Buyer approves treasury vm.prank(buyerAddress); testToken.approve(treasuryAddress, amount); - + // Create payment with token specified uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); - ICampaignPaymentTreasury.ExternalFees[] memory emptyExternalFees = new ICampaignPaymentTreasury.ExternalFees[](0); - createPayment(users.platform1AdminAddress, paymentId, buyerId, itemId, address(testToken), amount, expiration, emptyLineItems, emptyExternalFees); - + ICampaignPaymentTreasury.ExternalFees[] memory emptyExternalFees = + new ICampaignPaymentTreasury.ExternalFees[](0); + createPayment( + users.platform1AdminAddress, + paymentId, + buyerId, + itemId, + address(testToken), + amount, + expiration, + emptyLineItems, + emptyExternalFees + ); + // Transfer tokens from buyer to treasury vm.prank(buyerAddress); testToken.transfer(treasuryAddress, amount); @@ -346,22 +354,28 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te /** * @notice Helper to create and process a crypto payment */ - function _createAndProcessCryptoPayment( - bytes32 paymentId, - bytes32 itemId, - uint256 amount, - address buyerAddress - ) internal { + function _createAndProcessCryptoPayment(bytes32 paymentId, bytes32 itemId, uint256 amount, address buyerAddress) + internal + { // Fund buyer deal(address(testToken), buyerAddress, amount); - + // Buyer approves treasury vm.prank(buyerAddress); testToken.approve(treasuryAddress, amount); - + // Process crypto payment ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); - processCryptoPayment(buyerAddress, paymentId, itemId, buyerAddress, address(testToken), amount, emptyLineItems, new ICampaignPaymentTreasury.ExternalFees[](0)); + processCryptoPayment( + buyerAddress, + paymentId, + itemId, + buyerAddress, + address(testToken), + amount, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); } /** @@ -373,8 +387,8 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te } /** - * @notice Helper to create and fund a payment from buyer with specific token - */ + * @notice Helper to create and fund a payment from buyer with specific token + */ function _createAndFundPaymentWithToken( bytes32 paymentId, bytes32 buyerId, @@ -385,25 +399,36 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te ) internal { // Fund buyer deal(token, buyerAddress, amount); - + // Buyer approves treasury vm.prank(buyerAddress); TestToken(token).approve(treasuryAddress, amount); - + // Create payment with token specified uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); - ICampaignPaymentTreasury.ExternalFees[] memory emptyExternalFees = new ICampaignPaymentTreasury.ExternalFees[](0); - createPayment(users.platform1AdminAddress, paymentId, buyerId, itemId, token, amount, expiration, emptyLineItems, emptyExternalFees); - + ICampaignPaymentTreasury.ExternalFees[] memory emptyExternalFees = + new ICampaignPaymentTreasury.ExternalFees[](0); + createPayment( + users.platform1AdminAddress, + paymentId, + buyerId, + itemId, + token, + amount, + expiration, + emptyLineItems, + emptyExternalFees + ); + // Transfer tokens from buyer to treasury vm.prank(buyerAddress); TestToken(token).transfer(treasuryAddress, amount); } /** - * @notice Helper to create and process a crypto payment with specific token - */ + * @notice Helper to create and process a crypto payment with specific token + */ function _createAndProcessCryptoPaymentWithToken( bytes32 paymentId, bytes32 itemId, @@ -413,13 +438,22 @@ abstract contract PaymentTreasury_Integration_Shared_Test is LogDecoder, Base_Te ) internal { // Fund buyer deal(token, buyerAddress, amount); - + // Buyer approves treasury vm.prank(buyerAddress); TestToken(token).approve(treasuryAddress, amount); - + // Process crypto payment ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); - processCryptoPayment(buyerAddress, paymentId, itemId, buyerAddress, token, amount, emptyLineItems, new ICampaignPaymentTreasury.ExternalFees[](0)); + processCryptoPayment( + buyerAddress, + paymentId, + itemId, + buyerAddress, + token, + amount, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); } -} \ No newline at end of file +} diff --git a/test/foundry/integration/PaymentTreasury/PaymentTreasuryBatchLimitTest.t.sol b/test/foundry/integration/PaymentTreasury/PaymentTreasuryBatchLimitTest.t.sol index bc253870..f1d349b8 100644 --- a/test/foundry/integration/PaymentTreasury/PaymentTreasuryBatchLimitTest.t.sol +++ b/test/foundry/integration/PaymentTreasury/PaymentTreasuryBatchLimitTest.t.sol @@ -35,8 +35,18 @@ contract PaymentTreasuryBatchLimit_Test is PaymentTreasury_Integration_Shared_Te bytes32 itemId = keccak256(abi.encodePacked("item", i)); ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); - ICampaignPaymentTreasury.ExternalFees[] memory emptyExternalFees = new ICampaignPaymentTreasury.ExternalFees[](0); - paymentTreasury.createPayment(paymentId, buyerId, itemId, address(testToken), paymentAmount, expiration, emptyLineItems, emptyExternalFees); + ICampaignPaymentTreasury.ExternalFees[] memory emptyExternalFees = + new ICampaignPaymentTreasury.ExternalFees[](0); + paymentTreasury.createPayment( + paymentId, + buyerId, + itemId, + address(testToken), + paymentAmount, + expiration, + emptyLineItems, + emptyExternalFees + ); paymentIds[i] = paymentId; } @@ -85,16 +95,14 @@ contract PaymentTreasuryBatchLimit_Test is PaymentTreasury_Integration_Shared_Te console.log("Status: RISKY"); } console.log("----------------------------"); - } catch { console.log(string(abi.encodePacked("Batch Size: ", vm.toString(batchSize)))); console.log("FAILED - Exceeds gas limit or reverted"); console.log("----------------------------"); - break; + break; } setUp(); } } } - diff --git a/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol b/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol index c4487958..7a72f3af 100644 --- a/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol +++ b/test/foundry/integration/PaymentTreasury/PaymentTreasuryFunction.t.sol @@ -14,29 +14,17 @@ import {TestToken} from "../../../mocks/TestToken.sol"; * @notice This contract contains integration tests for the happy-path functionality * of the PaymentTreasury contract. Each test focuses on a single core function. */ -contract PaymentTreasuryFunction_Integration_Test is - PaymentTreasury_Integration_Shared_Test -{ +contract PaymentTreasuryFunction_Integration_Test is PaymentTreasury_Integration_Shared_Test { /** * @notice Tests the successful confirmation of a single payment. */ function test_confirmPayment() public { - _createAndFundPayment( - PAYMENT_ID_1, - BUYER_ID_1, - ITEM_ID_1, - PAYMENT_AMOUNT_1, - users.backer1Address - ); + _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); assertEq(testToken.balanceOf(treasuryAddress), PAYMENT_AMOUNT_1); confirmPayment(users.platform1AdminAddress, PAYMENT_ID_1); // Removed token parameter - assertEq( - paymentTreasury.getRaisedAmount(), - PAYMENT_AMOUNT_1, - "Raised amount should match the payment amount" - ); + assertEq(paymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1, "Raised amount should match the payment amount"); assertEq( paymentTreasury.getAvailableRaisedAmount(), PAYMENT_AMOUNT_1, @@ -58,9 +46,7 @@ contract PaymentTreasuryFunction_Integration_Test is confirmPaymentBatch(users.platform1AdminAddress, paymentIds); // Removed token array assertEq( - paymentTreasury.getRaisedAmount(), - totalAmount, - "Raised amount should match the total of batched payments" + paymentTreasury.getRaisedAmount(), totalAmount, "Raised amount should match the total of batched payments" ); assertEq( paymentTreasury.getAvailableRaisedAmount(), @@ -73,21 +59,11 @@ contract PaymentTreasuryFunction_Integration_Test is * @notice Tests that a confirmed payment can be successfully refunded. */ function test_claimRefund() public { - _createAndFundPayment( - PAYMENT_ID_1, - BUYER_ID_1, - ITEM_ID_1, - PAYMENT_AMOUNT_1, - users.backer1Address - ); + _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); confirmPayment(users.platform1AdminAddress, PAYMENT_ID_1); uint256 backerBalanceBefore = testToken.balanceOf(users.backer1Address); - uint256 refundAmount = claimRefund( - users.platform1AdminAddress, - PAYMENT_ID_1, - users.backer1Address - ); + uint256 refundAmount = claimRefund(users.platform1AdminAddress, PAYMENT_ID_1, users.backer1Address); // Verify the refund amount is correct and all balances are updated as expected. assertEq(refundAmount, PAYMENT_AMOUNT_1, "Refunded amount is incorrect"); @@ -107,13 +83,22 @@ contract PaymentTreasuryFunction_Integration_Test is function test_processCryptoPayment() public { uint256 amount = 1500e18; deal(address(testToken), users.backer1Address, amount); - + vm.prank(users.backer1Address); testToken.approve(treasuryAddress, amount); - + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); - processCryptoPayment(users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), amount, emptyLineItems, new ICampaignPaymentTreasury.ExternalFees[](0)); - + processCryptoPayment( + users.backer1Address, + PAYMENT_ID_1, + ITEM_ID_1, + users.backer1Address, + address(testToken), + amount, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + assertEq(paymentTreasury.getRaisedAmount(), amount, "Raised amount should match crypto payment"); assertEq(paymentTreasury.getAvailableRaisedAmount(), amount, "Available amount should match crypto payment"); assertEq(testToken.balanceOf(treasuryAddress), amount, "Treasury should hold the tokens"); @@ -125,19 +110,15 @@ contract PaymentTreasuryFunction_Integration_Test is function test_claimRefundBuyerInitiated() public { uint256 amount = 1500e18; _createAndProcessCryptoPayment(PAYMENT_ID_1, ITEM_ID_1, amount, users.backer1Address); - + uint256 buyerBalanceBefore = testToken.balanceOf(users.backer1Address); uint256 refundAmount = claimRefund(users.backer1Address, PAYMENT_ID_1, 1); // tokenId 1 - + assertEq(refundAmount, amount, "Refund amount should match payment"); - assertEq( - testToken.balanceOf(users.backer1Address), - buyerBalanceBefore + amount, - "Buyer should receive refund" - ); + assertEq(testToken.balanceOf(users.backer1Address), buyerBalanceBefore + amount, "Buyer should receive refund"); assertEq(paymentTreasury.getRaisedAmount(), 0, "Raised amount should be zero after refund"); } - + /** * @notice Tests the final withdrawal of funds by the campaign owner after fees have been calculated. */ @@ -165,8 +146,8 @@ contract PaymentTreasuryFunction_Integration_Test is assertEq(withdrawnAmount, expectedWithdrawalAmount, "Incorrect amount withdrawn"); assertEq(fee, expectedTotalFee, "Incorrect fee amount"); assertEq( - ownerBalanceAfter - ownerBalanceBefore, - expectedWithdrawalAmount, + ownerBalanceAfter - ownerBalanceBefore, + expectedWithdrawalAmount, "Campaign owner did not receive correct withdrawn amount" ); assertEq(paymentTreasury.getAvailableRaisedAmount(), 0, "Available amount should be zero after withdrawal"); @@ -182,7 +163,7 @@ contract PaymentTreasuryFunction_Integration_Test is paymentIds[0] = PAYMENT_ID_1; paymentIds[1] = PAYMENT_ID_2; confirmPaymentBatch(users.platform1AdminAddress, paymentIds); - + // Withdraw first to calculate fees withdraw(treasuryAddress); @@ -208,7 +189,7 @@ contract PaymentTreasuryFunction_Integration_Test is platformAdminBalanceBefore + expectedPlatformShare, "Platform admin did not receive correct fee amount" ); - + assertEq(testToken.balanceOf(treasuryAddress), 0, "Treasury should have zero balance after disbursing fees"); } @@ -220,69 +201,45 @@ contract PaymentTreasuryFunction_Integration_Test is // Create payments with different tokens uint256 usdtAmount = getTokenAmount(address(usdtToken), PAYMENT_AMOUNT_1); uint256 usdcAmount = getTokenAmount(address(usdcToken), PAYMENT_AMOUNT_2); - + _createAndFundPaymentWithToken( - PAYMENT_ID_1, - BUYER_ID_1, - ITEM_ID_1, - usdtAmount, - users.backer1Address, - address(usdtToken) + PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, usdtAmount, users.backer1Address, address(usdtToken) ); - + _createAndFundPaymentWithToken( - PAYMENT_ID_2, - BUYER_ID_2, - ITEM_ID_2, - usdcAmount, - users.backer2Address, - address(usdcToken) + PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, usdcAmount, users.backer2Address, address(usdcToken) ); - + // Confirm without specifying token (already set during creation) confirmPayment(users.platform1AdminAddress, PAYMENT_ID_1); confirmPayment(users.platform1AdminAddress, PAYMENT_ID_2); - + // Verify normalized raised amount uint256 expectedNormalized = PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2; - assertEq( - paymentTreasury.getRaisedAmount(), - expectedNormalized, - "Raised amount should be normalized sum" - ); + assertEq(paymentTreasury.getRaisedAmount(), expectedNormalized, "Raised amount should be normalized sum"); } function test_getRaisedAmountNormalizesCorrectly() public { // Create payments with same base amount in different tokens uint256 baseAmount = 1000e18; uint256 usdtAmount = baseAmount / 1e12; // 6 decimals - uint256 cUSDAmount = baseAmount; // 18 decimals - + uint256 cUSDAmount = baseAmount; // 18 decimals + _createAndFundPaymentWithToken( - PAYMENT_ID_1, - BUYER_ID_1, - ITEM_ID_1, - usdtAmount, - users.backer1Address, - address(usdtToken) + PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, usdtAmount, users.backer1Address, address(usdtToken) ); - + confirmPayment(users.platform1AdminAddress, PAYMENT_ID_1); - + uint256 raisedAfterUSDT = paymentTreasury.getRaisedAmount(); assertEq(raisedAfterUSDT, baseAmount, "USDT should normalize to base amount"); - + _createAndFundPaymentWithToken( - PAYMENT_ID_2, - BUYER_ID_2, - ITEM_ID_2, - cUSDAmount, - users.backer2Address, - address(cUSDToken) + PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, cUSDAmount, users.backer2Address, address(cUSDToken) ); - + confirmPayment(users.platform1AdminAddress, PAYMENT_ID_2); - + uint256 raisedAfterCUSD = paymentTreasury.getRaisedAmount(); assertEq(raisedAfterCUSD, baseAmount * 2, "Total should be sum of normalized amounts"); } @@ -292,42 +249,27 @@ contract PaymentTreasuryFunction_Integration_Test is uint256 usdtAmount = getTokenAmount(address(usdtToken), 500e18); uint256 usdcAmount = getTokenAmount(address(usdcToken), 700e18); uint256 cUSDAmount = 900e18; - + _createAndFundPaymentWithToken( - PAYMENT_ID_1, - BUYER_ID_1, - ITEM_ID_1, - usdtAmount, - users.backer1Address, - address(usdtToken) + PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, usdtAmount, users.backer1Address, address(usdtToken) ); - + _createAndFundPaymentWithToken( - PAYMENT_ID_2, - BUYER_ID_2, - ITEM_ID_2, - usdcAmount, - users.backer2Address, - address(usdcToken) + PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, usdcAmount, users.backer2Address, address(usdcToken) ); - + _createAndFundPaymentWithToken( - PAYMENT_ID_3, - BUYER_ID_1, - ITEM_ID_1, - cUSDAmount, - users.backer1Address, - address(cUSDToken) + PAYMENT_ID_3, BUYER_ID_1, ITEM_ID_1, cUSDAmount, users.backer1Address, address(cUSDToken) ); - + bytes32[] memory paymentIds = new bytes32[](3); paymentIds[0] = PAYMENT_ID_1; paymentIds[1] = PAYMENT_ID_2; paymentIds[2] = PAYMENT_ID_3; - + // Batch confirm without token array (tokens already set during creation) confirmPaymentBatch(users.platform1AdminAddress, paymentIds); - + uint256 expectedTotal = 500e18 + 700e18 + 900e18; assertEq(paymentTreasury.getRaisedAmount(), expectedTotal, "Should sum all normalized amounts"); } @@ -335,25 +277,17 @@ contract PaymentTreasuryFunction_Integration_Test is function test_processCryptoPaymentWithMultipleTokens() public { uint256 usdtAmount = getTokenAmount(address(usdtToken), 800e18); uint256 cUSDAmount = 1200e18; - + // Process USDT payment _createAndProcessCryptoPaymentWithToken( - PAYMENT_ID_1, - ITEM_ID_1, - usdtAmount, - users.backer1Address, - address(usdtToken) + PAYMENT_ID_1, ITEM_ID_1, usdtAmount, users.backer1Address, address(usdtToken) ); - + // Process cUSD payment _createAndProcessCryptoPaymentWithToken( - PAYMENT_ID_2, - ITEM_ID_2, - cUSDAmount, - users.backer2Address, - address(cUSDToken) + PAYMENT_ID_2, ITEM_ID_2, cUSDAmount, users.backer2Address, address(cUSDToken) ); - + uint256 expectedTotal = 800e18 + 1200e18; assertEq(paymentTreasury.getRaisedAmount(), expectedTotal, "Should track both crypto payments"); assertEq(usdtToken.balanceOf(treasuryAddress), usdtAmount, "Should hold USDT"); @@ -363,83 +297,59 @@ contract PaymentTreasuryFunction_Integration_Test is function test_refundReturnsCorrectToken() public { uint256 usdtAmount = getTokenAmount(address(usdtToken), PAYMENT_AMOUNT_1); uint256 cUSDAmount = PAYMENT_AMOUNT_2; - + // Create and confirm USDT payment _createAndFundPaymentWithToken( - PAYMENT_ID_1, - BUYER_ID_1, - ITEM_ID_1, - usdtAmount, - users.backer1Address, - address(usdtToken) + PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, usdtAmount, users.backer1Address, address(usdtToken) ); confirmPayment(users.platform1AdminAddress, PAYMENT_ID_1); // No token parameter - + // Create and confirm cUSD payment _createAndFundPaymentWithToken( - PAYMENT_ID_2, - BUYER_ID_2, - ITEM_ID_2, - cUSDAmount, - users.backer2Address, - address(cUSDToken) + PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, cUSDAmount, users.backer2Address, address(cUSDToken) ); confirmPayment(users.platform1AdminAddress, PAYMENT_ID_2); // No token parameter - + uint256 backer1USDTBefore = usdtToken.balanceOf(users.backer1Address); uint256 backer2CUSDBefore = cUSDToken.balanceOf(users.backer2Address); - + // Claim refunds uint256 refund1 = claimRefund(users.platform1AdminAddress, PAYMENT_ID_1, users.backer1Address); uint256 refund2 = claimRefund(users.platform1AdminAddress, PAYMENT_ID_2, users.backer2Address); - + // Verify correct tokens refunded assertEq(refund1, usdtAmount, "Should refund USDT amount"); assertEq(refund2, cUSDAmount, "Should refund cUSD amount"); - assertEq( - usdtToken.balanceOf(users.backer1Address) - backer1USDTBefore, - usdtAmount, - "Should receive USDT" - ); - assertEq( - cUSDToken.balanceOf(users.backer2Address) - backer2CUSDBefore, - cUSDAmount, - "Should receive cUSD" - ); - + assertEq(usdtToken.balanceOf(users.backer1Address) - backer1USDTBefore, usdtAmount, "Should receive USDT"); + assertEq(cUSDToken.balanceOf(users.backer2Address) - backer2CUSDBefore, cUSDAmount, "Should receive cUSD"); + // Verify no cross-token contamination assertEq(cUSDToken.balanceOf(users.backer1Address), TOKEN_MINT_AMOUNT, "Backer1 shouldn't have cUSD changes"); - assertEq(usdtToken.balanceOf(users.backer2Address), TOKEN_MINT_AMOUNT / 1e12, "Backer2 shouldn't have USDT changes"); + assertEq( + usdtToken.balanceOf(users.backer2Address), TOKEN_MINT_AMOUNT / 1e12, "Backer2 shouldn't have USDT changes" + ); } function test_cryptoPaymentRefundWithMultipleTokens() public { uint256 usdcAmount = getTokenAmount(address(usdcToken), 1500e18); uint256 cUSDAmount = 2000e18; - + // Process crypto payments _createAndProcessCryptoPaymentWithToken( - PAYMENT_ID_1, - ITEM_ID_1, - usdcAmount, - users.backer1Address, - address(usdcToken) + PAYMENT_ID_1, ITEM_ID_1, usdcAmount, users.backer1Address, address(usdcToken) ); - + _createAndProcessCryptoPaymentWithToken( - PAYMENT_ID_2, - ITEM_ID_2, - cUSDAmount, - users.backer2Address, - address(cUSDToken) + PAYMENT_ID_2, ITEM_ID_2, cUSDAmount, users.backer2Address, address(cUSDToken) ); - + uint256 backer1USDCBefore = usdcToken.balanceOf(users.backer1Address); uint256 backer2CUSDBefore = cUSDToken.balanceOf(users.backer2Address); - + // Buyers claim their own refunds uint256 refund1 = claimRefund(users.backer1Address, PAYMENT_ID_1, 1); // tokenId 1 uint256 refund2 = claimRefund(users.backer2Address, PAYMENT_ID_2, 2); // tokenId 2 - + assertEq(refund1, usdcAmount, "Should refund USDC amount"); assertEq(refund2, cUSDAmount, "Should refund cUSD amount"); assertEq(usdcToken.balanceOf(users.backer1Address) - backer1USDCBefore, usdcAmount); @@ -450,51 +360,36 @@ contract PaymentTreasuryFunction_Integration_Test is uint256 usdtAmount = getTokenAmount(address(usdtToken), 1000e18); uint256 usdcAmount = getTokenAmount(address(usdcToken), 1500e18); uint256 cUSDAmount = 2000e18; - + // Create and confirm payments with different tokens _createAndFundPaymentWithToken( - PAYMENT_ID_1, - BUYER_ID_1, - ITEM_ID_1, - usdtAmount, - users.backer1Address, - address(usdtToken) + PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, usdtAmount, users.backer1Address, address(usdtToken) ); confirmPayment(users.platform1AdminAddress, PAYMENT_ID_1); - + _createAndFundPaymentWithToken( - PAYMENT_ID_2, - BUYER_ID_2, - ITEM_ID_2, - usdcAmount, - users.backer2Address, - address(usdcToken) + PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, usdcAmount, users.backer2Address, address(usdcToken) ); confirmPayment(users.platform1AdminAddress, PAYMENT_ID_2); - + _createAndFundPaymentWithToken( - PAYMENT_ID_3, - BUYER_ID_1, - ITEM_ID_1, - cUSDAmount, - users.backer1Address, - address(cUSDToken) + PAYMENT_ID_3, BUYER_ID_1, ITEM_ID_1, cUSDAmount, users.backer1Address, address(cUSDToken) ); confirmPayment(users.platform1AdminAddress, PAYMENT_ID_3); - + address campaignOwner = CampaignInfo(campaignAddress).owner(); uint256 ownerUSDTBefore = usdtToken.balanceOf(campaignOwner); uint256 ownerUSDCBefore = usdcToken.balanceOf(campaignOwner); uint256 ownerCUSDBefore = cUSDToken.balanceOf(campaignOwner); - + // Withdraw all tokens withdraw(treasuryAddress); - + // Verify owner received all tokens (minus fees) assertTrue(usdtToken.balanceOf(campaignOwner) > ownerUSDTBefore, "Should receive USDT"); assertTrue(usdcToken.balanceOf(campaignOwner) > ownerUSDCBefore, "Should receive USDC"); assertTrue(cUSDToken.balanceOf(campaignOwner) > ownerCUSDBefore, "Should receive cUSD"); - + // Verify available amount is zero assertEq(paymentTreasury.getAvailableRaisedAmount(), 0, "Should have zero available after withdrawal"); } @@ -502,45 +397,35 @@ contract PaymentTreasuryFunction_Integration_Test is function test_disburseFeesWithMultipleTokens() public { uint256 usdtAmount = getTokenAmount(address(usdtToken), PAYMENT_AMOUNT_1); uint256 cUSDAmount = PAYMENT_AMOUNT_2; - + // Create and confirm payments _createAndFundPaymentWithToken( - PAYMENT_ID_1, - BUYER_ID_1, - ITEM_ID_1, - usdtAmount, - users.backer1Address, - address(usdtToken) + PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, usdtAmount, users.backer1Address, address(usdtToken) ); confirmPayment(users.platform1AdminAddress, PAYMENT_ID_1); - + _createAndFundPaymentWithToken( - PAYMENT_ID_2, - BUYER_ID_2, - ITEM_ID_2, - cUSDAmount, - users.backer2Address, - address(cUSDToken) + PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, cUSDAmount, users.backer2Address, address(cUSDToken) ); confirmPayment(users.platform1AdminAddress, PAYMENT_ID_2); - + // Withdraw to calculate fees withdraw(treasuryAddress); - + uint256 protocolUSDTBefore = usdtToken.balanceOf(users.protocolAdminAddress); uint256 protocolCUSDBefore = cUSDToken.balanceOf(users.protocolAdminAddress); uint256 platformUSDTBefore = usdtToken.balanceOf(users.platform1AdminAddress); uint256 platformCUSDBefore = cUSDToken.balanceOf(users.platform1AdminAddress); - + // Disburse fees disburseFees(treasuryAddress); - + // Verify fees distributed for both tokens uint256 expectedUSDTProtocolFee = (usdtAmount * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; uint256 expectedUSDTPlatformFee = (usdtAmount * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; uint256 expectedCUSDProtocolFee = (cUSDAmount * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; uint256 expectedCUSDPlatformFee = (cUSDAmount * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; - + assertEq( usdtToken.balanceOf(users.protocolAdminAddress) - protocolUSDTBefore, expectedUSDTProtocolFee, @@ -561,7 +446,7 @@ contract PaymentTreasuryFunction_Integration_Test is expectedCUSDPlatformFee, "cUSD platform fee incorrect" ); - + // Treasury should be empty assertEq(usdtToken.balanceOf(treasuryAddress), 0, "USDT should be fully disbursed"); assertEq(cUSDToken.balanceOf(treasuryAddress), 0, "cUSD should be fully disbursed"); @@ -571,45 +456,31 @@ contract PaymentTreasuryFunction_Integration_Test is // Regular payment with USDT uint256 usdtAmount = getTokenAmount(address(usdtToken), 1000e18); _createAndFundPaymentWithToken( - PAYMENT_ID_1, - BUYER_ID_1, - ITEM_ID_1, - usdtAmount, - users.backer1Address, - address(usdtToken) + PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, usdtAmount, users.backer1Address, address(usdtToken) ); confirmPayment(users.platform1AdminAddress, PAYMENT_ID_1); - + // Crypto payment with USDC uint256 usdcAmount = getTokenAmount(address(usdcToken), 1500e18); _createAndProcessCryptoPaymentWithToken( - PAYMENT_ID_2, - ITEM_ID_2, - usdcAmount, - users.backer2Address, - address(usdcToken) + PAYMENT_ID_2, ITEM_ID_2, usdcAmount, users.backer2Address, address(usdcToken) ); - + // Regular payment with cUSD uint256 cUSDAmount = 2000e18; _createAndFundPaymentWithToken( - PAYMENT_ID_3, - BUYER_ID_1, - ITEM_ID_1, - cUSDAmount, - users.backer1Address, - address(cUSDToken) + PAYMENT_ID_3, BUYER_ID_1, ITEM_ID_1, cUSDAmount, users.backer1Address, address(cUSDToken) ); confirmPayment(users.platform1AdminAddress, PAYMENT_ID_3); - + // Verify all contribute to raised amount uint256 expectedTotal = 1000e18 + 1500e18 + 2000e18; assertEq(paymentTreasury.getRaisedAmount(), expectedTotal, "Should sum all payment types"); - + // Withdraw and disburse withdraw(treasuryAddress); disburseFees(treasuryAddress); - + assertEq(paymentTreasury.getAvailableRaisedAmount(), 0); } @@ -618,7 +489,7 @@ contract PaymentTreasuryFunction_Integration_Test is TestToken rejectedToken = new TestToken("Rejected", "REJ", 18); uint256 amount = 1000e18; uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; - + // Try to create payment with unaccepted token vm.expectRevert(); vm.prank(users.platform1AdminAddress); @@ -640,10 +511,10 @@ contract PaymentTreasuryFunction_Integration_Test is TestToken rejectedToken = new TestToken("Rejected", "REJ", 18); uint256 amount = 1000e18; rejectedToken.mint(users.backer1Address, amount); - + vm.prank(users.backer1Address); rejectedToken.approve(treasuryAddress, amount); - + // Try to process crypto payment with unaccepted token vm.expectRevert(); ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); @@ -654,8 +525,9 @@ contract PaymentTreasuryFunction_Integration_Test is users.backer1Address, address(rejectedToken), amount, - emptyLineItems - , new ICampaignPaymentTreasury.ExternalFees[](0)); + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); } function test_balanceTrackingAcrossMultipleTokens() public { @@ -663,60 +535,37 @@ contract PaymentTreasuryFunction_Integration_Test is uint256 usdtAmount1 = getTokenAmount(address(usdtToken), 500e18); uint256 usdtAmount2 = getTokenAmount(address(usdtToken), 300e18); uint256 cUSDAmount = 1000e18; - + _createAndFundPaymentWithToken( - PAYMENT_ID_1, - BUYER_ID_1, - ITEM_ID_1, - usdtAmount1, - users.backer1Address, - address(usdtToken) + PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, usdtAmount1, users.backer1Address, address(usdtToken) ); - + _createAndFundPaymentWithToken( - PAYMENT_ID_2, - BUYER_ID_2, - ITEM_ID_2, - usdtAmount2, - users.backer2Address, - address(usdtToken) + PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, usdtAmount2, users.backer2Address, address(usdtToken) ); - + _createAndFundPaymentWithToken( - PAYMENT_ID_3, - BUYER_ID_1, - ITEM_ID_1, - cUSDAmount, - users.backer1Address, - address(cUSDToken) + PAYMENT_ID_3, BUYER_ID_1, ITEM_ID_1, cUSDAmount, users.backer1Address, address(cUSDToken) ); - + // Confirm all payments confirmPayment(users.platform1AdminAddress, PAYMENT_ID_1); confirmPayment(users.platform1AdminAddress, PAYMENT_ID_2); confirmPayment(users.platform1AdminAddress, PAYMENT_ID_3); - + // Verify raised amounts uint256 expectedTotal = 500e18 + 300e18 + 1000e18; assertEq(paymentTreasury.getRaisedAmount(), expectedTotal, "Should track total correctly"); - + // Refund one USDT payment claimRefund(users.platform1AdminAddress, PAYMENT_ID_1, users.backer1Address); - + uint256 afterRefund = 300e18 + 1000e18; assertEq(paymentTreasury.getRaisedAmount(), afterRefund, "Should update after refund"); - + // Verify token balances - assertEq( - usdtToken.balanceOf(treasuryAddress), - usdtAmount2, - "Should only have remaining USDT" - ); - assertEq( - cUSDToken.balanceOf(treasuryAddress), - cUSDAmount, - "cUSD should be unchanged" - ); + assertEq(usdtToken.balanceOf(treasuryAddress), usdtAmount2, "Should only have remaining USDT"); + assertEq(cUSDToken.balanceOf(treasuryAddress), cUSDAmount, "cUSD should be unchanged"); } /** @@ -731,7 +580,7 @@ contract PaymentTreasuryFunction_Integration_Test is // Enlist second platform vm.startPrank(users.protocolAdminAddress); - globalParams.enlistPlatform(PLATFORM_2_HASH, users.platform2AdminAddress, PLATFORM_FEE_PERCENT); + globalParams.enlistPlatform(PLATFORM_2_HASH, users.platform2AdminAddress, PLATFORM_FEE_PERCENT, address(0)); vm.stopPrank(); // Register and approve treasury for platform 2 @@ -815,12 +664,12 @@ contract PaymentTreasuryFunction_Integration_Test is emptyLineItems, new ICampaignPaymentTreasury.ExternalFees[](0) ); - + // Fund backer and transfer to treasury deal(address(testToken), users.backer1Address, amount1); vm.prank(users.backer1Address); testToken.transfer(treasury1, amount1); - + vm.prank(users.platform1AdminAddress); paymentTreasury1.confirmPayment(keccak256("payment-p1"), address(0)); @@ -836,12 +685,12 @@ contract PaymentTreasuryFunction_Integration_Test is emptyLineItems, new ICampaignPaymentTreasury.ExternalFees[](0) ); - + // Fund backer and transfer to treasury deal(address(testToken), users.backer2Address, amount2); vm.prank(users.backer2Address); testToken.transfer(treasury2, amount2); - + vm.prank(users.platform2AdminAddress); paymentTreasury2.confirmPayment(keccak256("payment-p2"), address(0)); @@ -865,4 +714,4 @@ contract PaymentTreasuryFunction_Integration_Test is uint256 totalAfter = campaignInfo.getTotalRaisedAmount(); assertEq(totalAfter, amount2, "Total should only include non-cancelled treasury"); } -} \ No newline at end of file +} diff --git a/test/foundry/integration/PaymentTreasury/PaymentTreasuryLineItems.t.sol b/test/foundry/integration/PaymentTreasury/PaymentTreasuryLineItems.t.sol index d7b29f5d..dc7dfcb7 100644 --- a/test/foundry/integration/PaymentTreasury/PaymentTreasuryLineItems.t.sol +++ b/test/foundry/integration/PaymentTreasury/PaymentTreasuryLineItems.t.sol @@ -14,17 +14,17 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes function setUp() public override { super.setUp(); - + // Register line item types vm.prank(users.platform1AdminAddress); globalParams.setPlatformLineItemType( PLATFORM_1_HASH, SHIPPING_FEE_TYPE_ID, "shipping_fee", - true, // countsTowardGoal + true, // countsTowardGoal false, // applyProtocolFee - true, // canRefund - false // instantTransfer + true, // canRefund + false // instantTransfer ); vm.prank(users.platform1AdminAddress); @@ -35,7 +35,7 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes false, // countsTowardGoal false, // applyProtocolFee false, // canRefund - true // instantTransfer + true // instantTransfer ); vm.prank(users.platform1AdminAddress); @@ -44,9 +44,9 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes INTEREST_TYPE_ID, "interest", false, // countsTowardGoal - true, // applyProtocolFee + true, // applyProtocolFee false, // canRefund - false // instantTransfer + false // instantTransfer ); vm.prank(users.platform1AdminAddress); @@ -55,9 +55,9 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes REFUNDABLE_FEE_WITH_PROTOCOL_TYPE_ID, "refundable_fee_with_protocol", false, // countsTowardGoal - true, // applyProtocolFee - true, // canRefund - false // instantTransfer + true, // applyProtocolFee + true, // canRefund + false // instantTransfer ); } @@ -68,12 +68,9 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes function test_createPaymentWithShippingFee() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; uint256 shippingFeeAmount = 50e18; - + ICampaignPaymentTreasury.LineItem[] memory lineItems = new ICampaignPaymentTreasury.LineItem[](1); - lineItems[0] = ICampaignPaymentTreasury.LineItem({ - typeId: SHIPPING_FEE_TYPE_ID, - amount: shippingFeeAmount - }); + lineItems[0] = ICampaignPaymentTreasury.LineItem({typeId: SHIPPING_FEE_TYPE_ID, amount: shippingFeeAmount}); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( @@ -94,12 +91,9 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes function test_createPaymentWithTip() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; uint256 tipAmount = 25e18; - + ICampaignPaymentTreasury.LineItem[] memory lineItems = new ICampaignPaymentTreasury.LineItem[](1); - lineItems[0] = ICampaignPaymentTreasury.LineItem({ - typeId: TIP_TYPE_ID, - amount: tipAmount - }); + lineItems[0] = ICampaignPaymentTreasury.LineItem({typeId: TIP_TYPE_ID, amount: tipAmount}); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( @@ -119,12 +113,9 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes function test_createPaymentWithInterest() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; uint256 interestAmount = 100e18; - + ICampaignPaymentTreasury.LineItem[] memory lineItems = new ICampaignPaymentTreasury.LineItem[](1); - lineItems[0] = ICampaignPaymentTreasury.LineItem({ - typeId: INTEREST_TYPE_ID, - amount: interestAmount - }); + lineItems[0] = ICampaignPaymentTreasury.LineItem({typeId: INTEREST_TYPE_ID, amount: interestAmount}); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( @@ -146,20 +137,11 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes uint256 shippingFeeAmount = 50e18; uint256 tipAmount = 25e18; uint256 interestAmount = 100e18; - + ICampaignPaymentTreasury.LineItem[] memory lineItems = new ICampaignPaymentTreasury.LineItem[](3); - lineItems[0] = ICampaignPaymentTreasury.LineItem({ - typeId: SHIPPING_FEE_TYPE_ID, - amount: shippingFeeAmount - }); - lineItems[1] = ICampaignPaymentTreasury.LineItem({ - typeId: TIP_TYPE_ID, - amount: tipAmount - }); - lineItems[2] = ICampaignPaymentTreasury.LineItem({ - typeId: INTEREST_TYPE_ID, - amount: interestAmount - }); + lineItems[0] = ICampaignPaymentTreasury.LineItem({typeId: SHIPPING_FEE_TYPE_ID, amount: shippingFeeAmount}); + lineItems[1] = ICampaignPaymentTreasury.LineItem({typeId: TIP_TYPE_ID, amount: tipAmount}); + lineItems[2] = ICampaignPaymentTreasury.LineItem({typeId: INTEREST_TYPE_ID, amount: interestAmount}); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( @@ -178,12 +160,9 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes function test_createPaymentRevertWhenLineItemTypeDoesNotExist() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; bytes32 nonExistentTypeId = keccak256("non_existent"); - + ICampaignPaymentTreasury.LineItem[] memory lineItems = new ICampaignPaymentTreasury.LineItem[](1); - lineItems[0] = ICampaignPaymentTreasury.LineItem({ - typeId: nonExistentTypeId, - amount: 50e18 - }); + lineItems[0] = ICampaignPaymentTreasury.LineItem({typeId: nonExistentTypeId, amount: 50e18}); vm.expectRevert(); vm.prank(users.platform1AdminAddress); @@ -201,12 +180,9 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes function test_createPaymentRevertWhenLineItemHasZeroTypeId() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; - + ICampaignPaymentTreasury.LineItem[] memory lineItems = new ICampaignPaymentTreasury.LineItem[](1); - lineItems[0] = ICampaignPaymentTreasury.LineItem({ - typeId: bytes32(0), - amount: 50e18 - }); + lineItems[0] = ICampaignPaymentTreasury.LineItem({typeId: bytes32(0), amount: 50e18}); vm.expectRevert(); vm.prank(users.platform1AdminAddress); @@ -224,12 +200,9 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes function test_createPaymentRevertWhenLineItemHasZeroAmount() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; - + ICampaignPaymentTreasury.LineItem[] memory lineItems = new ICampaignPaymentTreasury.LineItem[](1); - lineItems[0] = ICampaignPaymentTreasury.LineItem({ - typeId: SHIPPING_FEE_TYPE_ID, - amount: 0 - }); + lineItems[0] = ICampaignPaymentTreasury.LineItem({typeId: SHIPPING_FEE_TYPE_ID, amount: 0}); vm.expectRevert(); vm.prank(users.platform1AdminAddress); @@ -252,16 +225,13 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes function test_processCryptoPaymentWithShippingFee() public { uint256 shippingFeeAmount = 50e18; uint256 totalAmount = PAYMENT_AMOUNT_1 + shippingFeeAmount; - + deal(address(testToken), users.backer1Address, totalAmount); vm.prank(users.backer1Address); testToken.approve(treasuryAddress, totalAmount); ICampaignPaymentTreasury.LineItem[] memory lineItems = new ICampaignPaymentTreasury.LineItem[](1); - lineItems[0] = ICampaignPaymentTreasury.LineItem({ - typeId: SHIPPING_FEE_TYPE_ID, - amount: shippingFeeAmount - }); + lineItems[0] = ICampaignPaymentTreasury.LineItem({typeId: SHIPPING_FEE_TYPE_ID, amount: shippingFeeAmount}); vm.prank(users.backer1Address); paymentTreasury.processCryptoPayment( @@ -270,8 +240,9 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes users.backer1Address, address(testToken), PAYMENT_AMOUNT_1, - lineItems - , new ICampaignPaymentTreasury.ExternalFees[](0)); + lineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); // Payment should be confirmed immediately for crypto payments assertEq(paymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1 + shippingFeeAmount); @@ -281,7 +252,7 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes function test_processCryptoPaymentWithTip() public { uint256 tipAmount = 25e18; uint256 totalAmount = PAYMENT_AMOUNT_1 + tipAmount; - + deal(address(testToken), users.backer1Address, totalAmount); vm.prank(users.backer1Address); testToken.approve(treasuryAddress, totalAmount); @@ -289,10 +260,7 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes uint256 platformAdminBalanceBefore = testToken.balanceOf(users.platform1AdminAddress); ICampaignPaymentTreasury.LineItem[] memory lineItems = new ICampaignPaymentTreasury.LineItem[](1); - lineItems[0] = ICampaignPaymentTreasury.LineItem({ - typeId: TIP_TYPE_ID, - amount: tipAmount - }); + lineItems[0] = ICampaignPaymentTreasury.LineItem({typeId: TIP_TYPE_ID, amount: tipAmount}); vm.prank(users.backer1Address); paymentTreasury.processCryptoPayment( @@ -301,8 +269,9 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes users.backer1Address, address(testToken), PAYMENT_AMOUNT_1, - lineItems - , new ICampaignPaymentTreasury.ExternalFees[](0)); + lineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); // Tip doesn't count toward goal, but payment amount does assertEq(paymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1); @@ -317,7 +286,7 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes uint256 tipAmount = 25e18; uint256 interestAmount = 100e18; uint256 totalAmount = PAYMENT_AMOUNT_1 + shippingFeeAmount + tipAmount + interestAmount; - + deal(address(testToken), users.backer1Address, totalAmount); vm.prank(users.backer1Address); testToken.approve(treasuryAddress, totalAmount); @@ -326,18 +295,9 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes uint256 tipNetAmount = tipAmount; // No protocol fee on tip ICampaignPaymentTreasury.LineItem[] memory lineItems = new ICampaignPaymentTreasury.LineItem[](3); - lineItems[0] = ICampaignPaymentTreasury.LineItem({ - typeId: SHIPPING_FEE_TYPE_ID, - amount: shippingFeeAmount - }); - lineItems[1] = ICampaignPaymentTreasury.LineItem({ - typeId: TIP_TYPE_ID, - amount: tipAmount - }); - lineItems[2] = ICampaignPaymentTreasury.LineItem({ - typeId: INTEREST_TYPE_ID, - amount: interestAmount - }); + lineItems[0] = ICampaignPaymentTreasury.LineItem({typeId: SHIPPING_FEE_TYPE_ID, amount: shippingFeeAmount}); + lineItems[1] = ICampaignPaymentTreasury.LineItem({typeId: TIP_TYPE_ID, amount: tipAmount}); + lineItems[2] = ICampaignPaymentTreasury.LineItem({typeId: INTEREST_TYPE_ID, amount: interestAmount}); vm.prank(users.backer1Address); paymentTreasury.processCryptoPayment( @@ -346,8 +306,9 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes users.backer1Address, address(testToken), PAYMENT_AMOUNT_1, - lineItems - , new ICampaignPaymentTreasury.ExternalFees[](0)); + lineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); // Only payment amount + shipping fee count toward goal assertEq(paymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1 + shippingFeeAmount); @@ -364,7 +325,7 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes function test_createPaymentWithValidExpiration() public { uint256 expiration = block.timestamp + 1 days; - + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( @@ -382,7 +343,7 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes function test_createPaymentRevertWhenExpirationInPast() public { uint256 expiration = block.timestamp - 1; - + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.expectRevert(); vm.prank(users.platform1AdminAddress); @@ -400,7 +361,7 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes function test_createPaymentRevertWhenExpirationIsCurrentTime() public { uint256 expiration = block.timestamp; - + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.expectRevert(); vm.prank(users.platform1AdminAddress); @@ -418,7 +379,7 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes function test_createPaymentWithLongExpiration() public { uint256 expiration = block.timestamp + 365 days; - + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( @@ -436,7 +397,7 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes function test_cancelPaymentRevertWhenExpired() public { uint256 expiration = block.timestamp + 1 hours; - + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( @@ -460,7 +421,7 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes function test_confirmPaymentBeforeExpiration() public { uint256 expiration = block.timestamp + 1 days; - + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( @@ -491,14 +452,8 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes uint256 tipAmount = 25e18; ICampaignPaymentTreasury.LineItem[] memory lineItems = new ICampaignPaymentTreasury.LineItem[](2); - lineItems[0] = ICampaignPaymentTreasury.LineItem({ - typeId: SHIPPING_FEE_TYPE_ID, - amount: shippingFeeAmount - }); - lineItems[1] = ICampaignPaymentTreasury.LineItem({ - typeId: TIP_TYPE_ID, - amount: tipAmount - }); + lineItems[0] = ICampaignPaymentTreasury.LineItem({typeId: SHIPPING_FEE_TYPE_ID, amount: shippingFeeAmount}); + lineItems[1] = ICampaignPaymentTreasury.LineItem({typeId: TIP_TYPE_ID, amount: tipAmount}); ICampaignPaymentTreasury.ExternalFees[] memory externalFees = new ICampaignPaymentTreasury.ExternalFees[](2); externalFees[0] = ICampaignPaymentTreasury.ExternalFees({ @@ -568,10 +523,8 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes testToken.approve(treasuryAddress, totalAmount); ICampaignPaymentTreasury.LineItem[] memory lineItems = new ICampaignPaymentTreasury.LineItem[](1); - lineItems[0] = ICampaignPaymentTreasury.LineItem({ - typeId: REFUNDABLE_FEE_WITH_PROTOCOL_TYPE_ID, - amount: lineItemAmount - }); + lineItems[0] = + ICampaignPaymentTreasury.LineItem({typeId: REFUNDABLE_FEE_WITH_PROTOCOL_TYPE_ID, amount: lineItemAmount}); bytes32 paymentId = keccak256("refundableFeePayment"); @@ -597,10 +550,7 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes CampaignInfo(campaignAddress).approve(address(paymentTreasury), 1); paymentTreasury.claimRefund(paymentId); - assertEq( - testToken.balanceOf(users.backer1Address), - buyerBalanceAfterPayment + expectedRefund - ); + assertEq(testToken.balanceOf(users.backer1Address), buyerBalanceAfterPayment + expectedRefund); assertEq(testToken.balanceOf(treasuryAddress), expectedFee); } @@ -612,56 +562,44 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes bytes32[] memory paymentIds = new bytes32[](2); paymentIds[0] = PAYMENT_ID_1; paymentIds[1] = PAYMENT_ID_2; - + bytes32[] memory buyerIds = new bytes32[](2); buyerIds[0] = BUYER_ID_1; buyerIds[1] = BUYER_ID_2; - + bytes32[] memory itemIds = new bytes32[](2); itemIds[0] = ITEM_ID_1; itemIds[1] = ITEM_ID_2; - + address[] memory paymentTokens = new address[](2); paymentTokens[0] = address(testToken); paymentTokens[1] = address(testToken); - + uint256[] memory amounts = new uint256[](2); amounts[0] = PAYMENT_AMOUNT_1; amounts[1] = PAYMENT_AMOUNT_2; - + uint256[] memory expirations = new uint256[](2); expirations[0] = block.timestamp + PAYMENT_EXPIRATION; expirations[1] = block.timestamp + PAYMENT_EXPIRATION; - + ICampaignPaymentTreasury.LineItem[][] memory lineItemsArray = new ICampaignPaymentTreasury.LineItem[][](2); - + // First payment with shipping fee lineItemsArray[0] = new ICampaignPaymentTreasury.LineItem[](1); - lineItemsArray[0][0] = ICampaignPaymentTreasury.LineItem({ - typeId: SHIPPING_FEE_TYPE_ID, - amount: 50e18 - }); - + lineItemsArray[0][0] = ICampaignPaymentTreasury.LineItem({typeId: SHIPPING_FEE_TYPE_ID, amount: 50e18}); + // Second payment with tip lineItemsArray[1] = new ICampaignPaymentTreasury.LineItem[](1); - lineItemsArray[1][0] = ICampaignPaymentTreasury.LineItem({ - typeId: TIP_TYPE_ID, - amount: 25e18 - }); + lineItemsArray[1][0] = ICampaignPaymentTreasury.LineItem({typeId: TIP_TYPE_ID, amount: 25e18}); vm.prank(users.platform1AdminAddress); - ICampaignPaymentTreasury.ExternalFees[][] memory externalFeesArray = new ICampaignPaymentTreasury.ExternalFees[][](2); - externalFeesArray[0] = new ICampaignPaymentTreasury.ExternalFees[](0); - externalFeesArray[1] = new ICampaignPaymentTreasury.ExternalFees[](0); + ICampaignPaymentTreasury.ExternalFees[][] memory externalFeesArray = + new ICampaignPaymentTreasury.ExternalFees[][](2); + externalFeesArray[0] = new ICampaignPaymentTreasury.ExternalFees[](0); + externalFeesArray[1] = new ICampaignPaymentTreasury.ExternalFees[](0); paymentTreasury.createPaymentBatch( - paymentIds, - buyerIds, - itemIds, - paymentTokens, - amounts, - expirations, - lineItemsArray, - externalFeesArray + paymentIds, buyerIds, itemIds, paymentTokens, amounts, expirations, lineItemsArray, externalFeesArray ); assertEq(paymentTreasury.getRaisedAmount(), 0); @@ -671,46 +609,39 @@ contract PaymentTreasuryLineItems_Test is PaymentTreasury_Integration_Shared_Tes bytes32[] memory paymentIds = new bytes32[](2); paymentIds[0] = PAYMENT_ID_1; paymentIds[1] = PAYMENT_ID_2; - + bytes32[] memory buyerIds = new bytes32[](2); buyerIds[0] = BUYER_ID_1; buyerIds[1] = BUYER_ID_2; - + bytes32[] memory itemIds = new bytes32[](2); itemIds[0] = ITEM_ID_1; itemIds[1] = ITEM_ID_2; - + address[] memory paymentTokens = new address[](2); paymentTokens[0] = address(testToken); paymentTokens[1] = address(testToken); - + uint256[] memory amounts = new uint256[](2); amounts[0] = PAYMENT_AMOUNT_1; amounts[1] = PAYMENT_AMOUNT_2; - + uint256[] memory expirations = new uint256[](2); expirations[0] = block.timestamp + PAYMENT_EXPIRATION; expirations[1] = block.timestamp + PAYMENT_EXPIRATION; - + // Wrong length - only 1 item instead of 2 ICampaignPaymentTreasury.LineItem[][] memory lineItemsArray = new ICampaignPaymentTreasury.LineItem[][](1); lineItemsArray[0] = new ICampaignPaymentTreasury.LineItem[](0); // Also wrong length for externalFeesArray to match the test intent - ICampaignPaymentTreasury.ExternalFees[][] memory externalFeesArray = new ICampaignPaymentTreasury.ExternalFees[][](1); + ICampaignPaymentTreasury.ExternalFees[][] memory externalFeesArray = + new ICampaignPaymentTreasury.ExternalFees[][](1); externalFeesArray[0] = new ICampaignPaymentTreasury.ExternalFees[](0); vm.expectRevert(); vm.prank(users.platform1AdminAddress); paymentTreasury.createPaymentBatch( - paymentIds, - buyerIds, - itemIds, - paymentTokens, - amounts, - expirations, - lineItemsArray, - externalFeesArray + paymentIds, buyerIds, itemIds, paymentTokens, amounts, expirations, lineItemsArray, externalFeesArray ); } } - diff --git a/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasury.t.sol b/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasury.t.sol index c2bde023..b25a5adf 100644 --- a/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasury.t.sol +++ b/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasury.t.sol @@ -77,7 +77,7 @@ abstract contract TimeConstrainedPaymentTreasury_Integration_Shared_Test is LogD */ function enlistPlatform(bytes32 platformHash) internal { vm.startPrank(users.protocolAdminAddress); - globalParams.enlistPlatform(platformHash, users.platform1AdminAddress, PLATFORM_FEE_PERCENT); + globalParams.enlistPlatform(platformHash, users.platform1AdminAddress, PLATFORM_FEE_PERCENT, address(0)); vm.stopPrank(); } diff --git a/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasuryFunction.t.sol b/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasuryFunction.t.sol index 237654fe..f832b036 100644 --- a/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasuryFunction.t.sol +++ b/test/foundry/integration/TimeConstrainedPaymentTreasury/TimeConstrainedPaymentTreasuryFunction.t.sol @@ -12,7 +12,9 @@ import {TimeConstrainedPaymentTreasury} from "src/treasuries/TimeConstrainedPaym import {CampaignInfo} from "src/CampaignInfo.sol"; import {TestToken} from "../../../mocks/TestToken.sol"; -contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeConstrainedPaymentTreasury_Integration_Shared_Test { +contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is + TimeConstrainedPaymentTreasury_Integration_Shared_Test +{ function setUp() public virtual override { super.setUp(); @@ -25,7 +27,7 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC function test_createPayment() external { advanceToWithinRange(); - + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); @@ -46,61 +48,54 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC function test_createPaymentBatch() external { advanceToWithinRange(); - + bytes32[] memory paymentIds = new bytes32[](2); paymentIds[0] = PAYMENT_ID_1; paymentIds[1] = PAYMENT_ID_2; - + bytes32[] memory buyerIds = new bytes32[](2); buyerIds[0] = BUYER_ID_1; buyerIds[1] = BUYER_ID_2; - + bytes32[] memory itemIds = new bytes32[](2); itemIds[0] = ITEM_ID_1; itemIds[1] = ITEM_ID_2; - + address[] memory paymentTokens = new address[](2); paymentTokens[0] = address(testToken); paymentTokens[1] = address(testToken); - + uint256[] memory amounts = new uint256[](2); amounts[0] = PAYMENT_AMOUNT_1; amounts[1] = PAYMENT_AMOUNT_2; - + uint256[] memory expirations = new uint256[](2); expirations[0] = block.timestamp + PAYMENT_EXPIRATION; expirations[1] = block.timestamp + PAYMENT_EXPIRATION; - + ICampaignPaymentTreasury.LineItem[][] memory emptyLineItemsArray = new ICampaignPaymentTreasury.LineItem[][](2); emptyLineItemsArray[0] = new ICampaignPaymentTreasury.LineItem[](0); emptyLineItemsArray[1] = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); - ICampaignPaymentTreasury.ExternalFees[][] memory externalFeesArray = new ICampaignPaymentTreasury.ExternalFees[][](2); - externalFeesArray[0] = new ICampaignPaymentTreasury.ExternalFees[](0); - externalFeesArray[1] = new ICampaignPaymentTreasury.ExternalFees[](0); + ICampaignPaymentTreasury.ExternalFees[][] memory externalFeesArray = + new ICampaignPaymentTreasury.ExternalFees[][](2); + externalFeesArray[0] = new ICampaignPaymentTreasury.ExternalFees[](0); + externalFeesArray[1] = new ICampaignPaymentTreasury.ExternalFees[](0); timeConstrainedPaymentTreasury.createPaymentBatch( - paymentIds, - buyerIds, - itemIds, - paymentTokens, - amounts, - expirations, - emptyLineItemsArray, - - externalFeesArray + paymentIds, buyerIds, itemIds, paymentTokens, amounts, expirations, emptyLineItemsArray, externalFeesArray ); - + // Payments created successfully assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); } function test_processCryptoPayment() external { advanceToWithinRange(); - + // Approve tokens for the treasury vm.prank(users.backer1Address); testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); - + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.processCryptoPayment( @@ -109,9 +104,10 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC users.backer1Address, address(testToken), PAYMENT_AMOUNT_1, - emptyLineItems - , new ICampaignPaymentTreasury.ExternalFees[](0)); - + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + // Payment processed successfully assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1); assertEq(timeConstrainedPaymentTreasury.getAvailableRaisedAmount(), PAYMENT_AMOUNT_1); @@ -119,7 +115,7 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC function test_cancelPayment() external { advanceToWithinRange(); - + // First create a payment uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); @@ -137,21 +133,21 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC // Then cancel it vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.cancelPayment(PAYMENT_ID_1); - + // Payment cancelled successfully assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); } function test_confirmPayment() external { advanceToWithinRange(); - + // Use a unique payment ID for this test bytes32 uniquePaymentId = keccak256("confirmPaymentTest"); - + // Use processCryptoPayment which creates and confirms payment in one step vm.prank(users.backer1Address); testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); - + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.processCryptoPayment( @@ -160,9 +156,10 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC users.backer1Address, address(testToken), PAYMENT_AMOUNT_1, - emptyLineItems - , new ICampaignPaymentTreasury.ExternalFees[](0)); - + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + // Payment created and confirmed successfully by processCryptoPayment assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1); assertEq(timeConstrainedPaymentTreasury.getAvailableRaisedAmount(), PAYMENT_AMOUNT_1); @@ -170,15 +167,15 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC function test_confirmPaymentBatch() external { advanceToWithinRange(); - + // Use unique payment IDs for this test bytes32 uniquePaymentId1 = keccak256("confirmPaymentBatchTest1"); bytes32 uniquePaymentId2 = keccak256("confirmPaymentBatchTest2"); - + // Use processCryptoPayment for both payments which creates and confirms them vm.prank(users.backer1Address); testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); - + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.processCryptoPayment( @@ -187,12 +184,13 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC users.backer1Address, address(testToken), PAYMENT_AMOUNT_1, - emptyLineItems - , new ICampaignPaymentTreasury.ExternalFees[](0)); - + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + vm.prank(users.backer2Address); testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_2); - + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems2 = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.processCryptoPayment( @@ -201,9 +199,10 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC users.backer2Address, address(testToken), PAYMENT_AMOUNT_2, - emptyLineItems2 - , new ICampaignPaymentTreasury.ExternalFees[](0)); - + emptyLineItems2, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + // Payments created and confirmed successfully by processCryptoPayment assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2); assertEq(timeConstrainedPaymentTreasury.getAvailableRaisedAmount(), PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2); @@ -212,14 +211,14 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC function test_claimRefund() external { // First create payment within the allowed time range advanceToWithinRange(); - + // Use a unique payment ID for this test bytes32 uniquePaymentId = keccak256("claimRefundTest"); - + // Use processCryptoPayment which creates and confirms payment in one step vm.prank(users.backer1Address); testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); - + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.processCryptoPayment( @@ -228,20 +227,21 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC users.backer1Address, address(testToken), PAYMENT_AMOUNT_1, - emptyLineItems - , new ICampaignPaymentTreasury.ExternalFees[](0)); - + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + // Advance to after launch to be able to claim refund advanceToAfterLaunch(); - + // Approve treasury to burn NFT vm.prank(users.backer1Address); CampaignInfo(campaignAddress).approve(address(timeConstrainedPaymentTreasury), 1); // tokenId 1 - + // Then claim refund (use the overload without refundAddress since processCryptoPayment uses buyerAddress) vm.prank(users.backer1Address); timeConstrainedPaymentTreasury.claimRefund(uniquePaymentId); - + // Refund claimed successfully assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); assertEq(timeConstrainedPaymentTreasury.getAvailableRaisedAmount(), 0); @@ -250,14 +250,14 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC function test_disburseFees() external { // First create payment within the allowed time range advanceToWithinRange(); - + // Use a unique payment ID for this test bytes32 uniquePaymentId = keccak256("disburseFeesTest"); - + // Use processCryptoPayment which creates and confirms payment in one step vm.prank(users.backer1Address); testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); - + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.processCryptoPayment( @@ -266,30 +266,31 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC users.backer1Address, address(testToken), PAYMENT_AMOUNT_1, - emptyLineItems - , new ICampaignPaymentTreasury.ExternalFees[](0)); - + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + // Advance to after launch to be able to disburse fees advanceToAfterLaunch(); - + // Then disburse fees vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.disburseFees(); - + // Fees disbursed successfully (no revert) } function test_withdraw() external { // First create payment within the allowed time range advanceToWithinRange(); - + // Use a unique payment ID for this test bytes32 uniquePaymentId = keccak256("withdrawTest"); - + // Use processCryptoPayment which creates and confirms payment in one step vm.prank(users.backer1Address); testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); - + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.processCryptoPayment( @@ -298,22 +299,23 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC users.backer1Address, address(testToken), PAYMENT_AMOUNT_1, - emptyLineItems - , new ICampaignPaymentTreasury.ExternalFees[](0)); - + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + // Advance to after launch to be able to withdraw advanceToAfterLaunch(); - + // Then withdraw vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.withdraw(); - + // Withdrawal successful (no revert) } function test_timeConstraints_createPaymentBeforeLaunch() external { advanceToBeforeLaunch(); - + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.expectRevert(); @@ -332,7 +334,7 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC function test_timeConstraints_createPaymentAfterDeadline() external { advanceToAfterDeadline(); - + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.expectRevert(); @@ -351,7 +353,7 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC function test_timeConstraints_claimRefundBeforeLaunch() external { advanceToBeforeLaunch(); - + vm.expectRevert(); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.claimRefund(PAYMENT_ID_1, users.backer1Address); @@ -359,7 +361,7 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC function test_timeConstraints_disburseFeesBeforeLaunch() external { advanceToBeforeLaunch(); - + vm.expectRevert(); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.disburseFees(); @@ -367,7 +369,7 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC function test_timeConstraints_withdrawBeforeLaunch() external { advanceToBeforeLaunch(); - + vm.expectRevert(); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.withdraw(); @@ -379,7 +381,7 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC // by checking that operations work within the buffer time window // Use a time that should be within the allowed range vm.warp(campaignDeadline - 1); // Use deadline - 1 to be within range - + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); @@ -400,7 +402,7 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC function test_operationsAtDeadlinePlusBuffer() external { // Test operations at the exact deadline + buffer time vm.warp(campaignDeadline - 1); // Use deadline - 1 to be within range - + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); @@ -421,7 +423,7 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC function test_operationsAfterDeadlinePlusBuffer() external { // Test operations after deadline + buffer time advanceToAfterDeadline(); - + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.expectRevert(); @@ -441,7 +443,7 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC function test_operationsAtExactLaunchTime() external { // Test operations at the exact launch time vm.warp(campaignLaunchTime); - + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); @@ -462,7 +464,7 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC function test_operationsAtExactDeadline() external { // Test operations at the exact deadline vm.warp(campaignDeadline); - + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); @@ -483,14 +485,14 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC function test_multipleTimeConstraintChecks() external { // Test that multiple operations respect time constraints advanceToWithinRange(); - + // Use a unique payment ID for this test bytes32 uniquePaymentId = keccak256("multipleTimeConstraintChecksTest"); - + // Use processCryptoPayment which creates and confirms payment in one step vm.prank(users.backer1Address); testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); - + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.processCryptoPayment( @@ -499,16 +501,17 @@ contract TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test is TimeC users.backer1Address, address(testToken), PAYMENT_AMOUNT_1, - emptyLineItems - , new ICampaignPaymentTreasury.ExternalFees[](0)); - + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + // Advance to after launch time advanceToAfterLaunch(); - + // Withdraw (should work after launch time) vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.withdraw(); - + // All operations should succeed assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1); } diff --git a/test/foundry/unit/CampaignInfo.t.sol b/test/foundry/unit/CampaignInfo.t.sol index c954a509..0f7d70b8 100644 --- a/test/foundry/unit/CampaignInfo.t.sol +++ b/test/foundry/unit/CampaignInfo.t.sol @@ -33,35 +33,28 @@ contract CampaignInfo_UnitTest is Test, Defaults { function setUp() public { testToken = new TestToken(tokenName, tokenSymbol, 18); - + // Setup currencies and tokens bytes32[] memory currencies = new bytes32[](1); currencies[0] = bytes32("USD"); - + address[][] memory tokensPerCurrency = new address[][](1); tokensPerCurrency[0] = new address[](1); tokensPerCurrency[0][0] = address(testToken); - + // Deploy GlobalParams with proxy GlobalParams globalParamsImpl = new GlobalParams(); bytes memory globalParamsInitData = abi.encodeWithSelector( - GlobalParams.initialize.selector, - admin, - PROTOCOL_FEE_PERCENT, - currencies, - tokensPerCurrency - ); - ERC1967Proxy globalParamsProxy = new ERC1967Proxy( - address(globalParamsImpl), - globalParamsInitData + GlobalParams.initialize.selector, admin, PROTOCOL_FEE_PERCENT, currencies, tokensPerCurrency ); + ERC1967Proxy globalParamsProxy = new ERC1967Proxy(address(globalParamsImpl), globalParamsInitData); globalParams = GlobalParams(address(globalParamsProxy)); // Setup platforms in GlobalParams vm.startPrank(admin); - globalParams.enlistPlatform(platformHash1, admin, 1000); // 10% fee - globalParams.enlistPlatform(platformHash2, admin, 2000); // 20% fee - + globalParams.enlistPlatform(platformHash1, admin, 1000, address(0)); // 10% fee + globalParams.enlistPlatform(platformHash2, admin, 2000, address(0)); // 20% fee + // Add platform data keys globalParams.addPlatformData(platformHash1, platformDataKey1); globalParams.addPlatformData(platformHash2, platformDataKey2); @@ -69,14 +62,9 @@ contract CampaignInfo_UnitTest is Test, Defaults { // Deploy TreasuryFactory TreasuryFactory treasuryFactoryImpl = new TreasuryFactory(); - bytes memory treasuryFactoryInitData = abi.encodeWithSelector( - TreasuryFactory.initialize.selector, - IGlobalParams(address(globalParams)) - ); - ERC1967Proxy treasuryFactoryProxy = new ERC1967Proxy( - address(treasuryFactoryImpl), - treasuryFactoryInitData - ); + bytes memory treasuryFactoryInitData = + abi.encodeWithSelector(TreasuryFactory.initialize.selector, IGlobalParams(address(globalParams))); + ERC1967Proxy treasuryFactoryProxy = new ERC1967Proxy(address(treasuryFactoryImpl), treasuryFactoryInitData); treasuryFactory = TreasuryFactory(address(treasuryFactoryProxy)); // Deploy AllOrNothing implementation for testing @@ -97,25 +85,23 @@ contract CampaignInfo_UnitTest is Test, Defaults { address(new CampaignInfo()), address(treasuryFactory) ); - ERC1967Proxy campaignInfoFactoryProxy = new ERC1967Proxy( - address(campaignInfoFactoryImpl), - campaignInfoFactoryInitData - ); + ERC1967Proxy campaignInfoFactoryProxy = + new ERC1967Proxy(address(campaignInfoFactoryImpl), campaignInfoFactoryInitData); campaignInfoFactory = CampaignInfoFactory(address(campaignInfoFactoryProxy)); // Create a campaign using the factory ICampaignData.CampaignData memory campaignData = ICampaignData.CampaignData({ launchTime: block.timestamp + 1 days, deadline: block.timestamp + 30 days, - goalAmount: 1000 * 10**18, + goalAmount: 1000 * 10 ** 18, currency: bytes32("USD") }); - + bytes32[] memory selectedPlatformHashes = new bytes32[](0); // No platforms selected initially bytes32[] memory platformDataKeys = new bytes32[](0); bytes32[] memory platformDataValues = new bytes32[](0); bytes32 identifierHash = keccak256("test-campaign"); - + vm.startPrank(admin); campaignInfoFactory.createCampaign( campaignOwner, @@ -130,7 +116,7 @@ contract CampaignInfo_UnitTest is Test, Defaults { "ipfs://QmContractTest123" ); vm.stopPrank(); - + campaignInfo = CampaignInfo(campaignInfoFactory.identifierToCampaignInfo(identifierHash)); } @@ -156,10 +142,9 @@ contract CampaignInfo_UnitTest is Test, Defaults { function test_GetGoalAmount() public { uint256 goalAmount = campaignInfo.getGoalAmount(); - assertEq(goalAmount, 1000 * 10**18); + assertEq(goalAmount, 1000 * 10 ** 18); } - function test_GetCampaignCurrency() public { bytes32 currency = campaignInfo.getCampaignCurrency(); assertEq(currency, bytes32("USD")); @@ -211,165 +196,120 @@ contract CampaignInfo_UnitTest is Test, Defaults { function test_UpdateSelectedPlatform_SelectPlatform_Success() public { vm.startPrank(campaignOwner); - + bytes32[] memory dataKeys = new bytes32[](2); dataKeys[0] = platformDataKey1; dataKeys[1] = platformDataKey2; - + bytes32[] memory dataValues = new bytes32[](2); dataValues[0] = platformDataValue1; dataValues[1] = platformDataValue2; - campaignInfo.updateSelectedPlatform( - platformHash1, - true, - dataKeys, - dataValues - ); + campaignInfo.updateSelectedPlatform(platformHash1, true, dataKeys, dataValues); // Verify platform is selected assertTrue(campaignInfo.checkIfPlatformSelected(platformHash1)); - + // Verify platform data is stored assertEq(campaignInfo.getPlatformData(platformDataKey1), platformDataValue1); assertEq(campaignInfo.getPlatformData(platformDataKey2), platformDataValue2); - + // Verify platform fee is set assertEq(campaignInfo.getPlatformFeePercent(platformHash1), 1000); - + vm.stopPrank(); } - function test_UpdateSelectedPlatform_InvalidPlatform_Reverts() public { vm.startPrank(campaignOwner); - + bytes32 invalidPlatformHash = keccak256("invalid"); bytes32[] memory dataKeys = new bytes32[](1); dataKeys[0] = platformDataKey1; - + bytes32[] memory dataValues = new bytes32[](1); dataValues[0] = platformDataValue1; vm.expectRevert( - abi.encodeWithSelector( - CampaignInfo.CampaignInfoInvalidPlatformUpdate.selector, - invalidPlatformHash, - true - ) - ); - campaignInfo.updateSelectedPlatform( - invalidPlatformHash, - true, - dataKeys, - dataValues + abi.encodeWithSelector(CampaignInfo.CampaignInfoInvalidPlatformUpdate.selector, invalidPlatformHash, true) ); + campaignInfo.updateSelectedPlatform(invalidPlatformHash, true, dataKeys, dataValues); vm.stopPrank(); } function test_UpdateSelectedPlatform_AlreadySelected_Reverts() public { vm.startPrank(campaignOwner); - + bytes32[] memory dataKeys = new bytes32[](1); dataKeys[0] = platformDataKey1; - + bytes32[] memory dataValues = new bytes32[](1); dataValues[0] = platformDataValue1; // Select platform first time - campaignInfo.updateSelectedPlatform( - platformHash1, - true, - dataKeys, - dataValues - ); + campaignInfo.updateSelectedPlatform(platformHash1, true, dataKeys, dataValues); // Try to select again - should revert vm.expectRevert(CampaignInfo.CampaignInfoInvalidInput.selector); - campaignInfo.updateSelectedPlatform( - platformHash1, - true, - dataKeys, - dataValues - ); + campaignInfo.updateSelectedPlatform(platformHash1, true, dataKeys, dataValues); vm.stopPrank(); } function test_UpdateSelectedPlatform_DataKeyValueLengthMismatch_Reverts() public { vm.startPrank(campaignOwner); - + bytes32[] memory dataKeys = new bytes32[](2); dataKeys[0] = platformDataKey1; dataKeys[1] = platformDataKey2; - + bytes32[] memory dataValues = new bytes32[](1); dataValues[0] = platformDataValue1; vm.expectRevert(CampaignInfo.CampaignInfoInvalidInput.selector); - campaignInfo.updateSelectedPlatform( - platformHash1, - true, - dataKeys, - dataValues - ); + campaignInfo.updateSelectedPlatform(platformHash1, true, dataKeys, dataValues); vm.stopPrank(); } function test_UpdateSelectedPlatform_InvalidDataKey_Reverts() public { vm.startPrank(campaignOwner); - + bytes32[] memory dataKeys = new bytes32[](1); dataKeys[0] = keccak256("invalid_key"); - + bytes32[] memory dataValues = new bytes32[](1); dataValues[0] = platformDataValue1; vm.expectRevert(CampaignInfo.CampaignInfoInvalidInput.selector); - campaignInfo.updateSelectedPlatform( - platformHash1, - true, - dataKeys, - dataValues - ); + campaignInfo.updateSelectedPlatform(platformHash1, true, dataKeys, dataValues); vm.stopPrank(); } function test_UpdateSelectedPlatform_ZeroDataValue_Reverts() public { vm.startPrank(campaignOwner); - + bytes32[] memory dataKeys = new bytes32[](1); dataKeys[0] = platformDataKey1; - + bytes32[] memory dataValues = new bytes32[](1); dataValues[0] = bytes32(0); vm.expectRevert(CampaignInfo.CampaignInfoInvalidInput.selector); - campaignInfo.updateSelectedPlatform( - platformHash1, - true, - dataKeys, - dataValues - ); + campaignInfo.updateSelectedPlatform(platformHash1, true, dataKeys, dataValues); vm.stopPrank(); } function test_UpdateSelectedPlatform_Unauthorized_Reverts() public { address unauthorizedUser = address(0xC33FF); - + bytes32[] memory dataKeys = new bytes32[](1); dataKeys[0] = platformDataKey1; - + bytes32[] memory dataValues = new bytes32[](1); dataValues[0] = platformDataValue1; vm.startPrank(unauthorizedUser); vm.expectRevert(); - campaignInfo.updateSelectedPlatform( - platformHash1, - true, - dataKeys, - dataValues - ); + campaignInfo.updateSelectedPlatform(platformHash1, true, dataKeys, dataValues); vm.stopPrank(); } @@ -377,73 +317,72 @@ contract CampaignInfo_UnitTest is Test, Defaults { function test_UpdateLaunchTime_Success() public { vm.startPrank(campaignOwner); - + uint256 newLaunchTime = block.timestamp + 1 days; - + vm.expectEmit(true, false, false, true); emit CampaignInfo.CampaignInfoLaunchTimeUpdated(newLaunchTime); - + campaignInfo.updateLaunchTime(newLaunchTime); - + assertEq(campaignInfo.getLaunchTime(), newLaunchTime); vm.stopPrank(); } function test_UpdateLaunchTime_InvalidTime_Reverts() public { vm.startPrank(campaignOwner); - + // Launch time in the past vm.expectRevert(CampaignInfo.CampaignInfoInvalidInput.selector); campaignInfo.updateLaunchTime(block.timestamp - 1); - + vm.stopPrank(); } function test_UpdateDeadline_Success() public { vm.startPrank(campaignOwner); - + uint256 newDeadline = campaignInfo.getLaunchTime() + 60 days; - + vm.expectEmit(true, false, false, true); emit CampaignInfo.CampaignInfoDeadlineUpdated(newDeadline); - + campaignInfo.updateDeadline(newDeadline); - + assertEq(campaignInfo.getDeadline(), newDeadline); vm.stopPrank(); } function test_UpdateGoalAmount_Success() public { vm.startPrank(campaignOwner); - - uint256 newGoalAmount = 2000 * 10**18; - + + uint256 newGoalAmount = 2000 * 10 ** 18; + vm.expectEmit(true, false, false, true); emit CampaignInfo.CampaignInfoGoalAmountUpdated(newGoalAmount); - + campaignInfo.updateGoalAmount(newGoalAmount); - + assertEq(campaignInfo.getGoalAmount(), newGoalAmount); vm.stopPrank(); } function test_UpdateGoalAmount_ZeroAmount_Reverts() public { vm.startPrank(campaignOwner); - + vm.expectRevert(CampaignInfo.CampaignInfoInvalidInput.selector); campaignInfo.updateGoalAmount(0); - + vm.stopPrank(); } - // ============ Transfer Ownership Tests ============ function test_TransferOwnership_Success() public { vm.startPrank(campaignOwner); - + campaignInfo.transferOwnership(newOwner); - + assertEq(campaignInfo.owner(), newOwner); vm.stopPrank(); } @@ -476,10 +415,10 @@ contract CampaignInfo_UnitTest is Test, Defaults { function test_PauseCampaign_Success() public { vm.startPrank(admin); - + bytes32 message = keccak256("test pause"); campaignInfo._pauseCampaign(message); - + assertTrue(campaignInfo.paused()); vm.stopPrank(); } @@ -494,34 +433,34 @@ contract CampaignInfo_UnitTest is Test, Defaults { vm.startPrank(admin); bytes32 message = keccak256("test unpause"); campaignInfo._unpauseCampaign(message); - + assertFalse(campaignInfo.paused()); vm.stopPrank(); } function test_CancelCampaign_ByAdmin_Success() public { vm.startPrank(admin); - + bytes32 message = keccak256("test cancel"); campaignInfo._cancelCampaign(message); - + assertTrue(campaignInfo.cancelled()); vm.stopPrank(); } function test_CancelCampaign_ByOwner_Success() public { vm.startPrank(campaignOwner); - + bytes32 message = keccak256("test cancel"); campaignInfo._cancelCampaign(message); - + assertTrue(campaignInfo.cancelled()); vm.stopPrank(); } function test_CancelCampaign_Unauthorized_Reverts() public { address unauthorizedUser = address(0xD44F); - + vm.startPrank(unauthorizedUser); vm.expectRevert(CampaignInfo.CampaignInfoUnauthorized.selector); campaignInfo._cancelCampaign(keccak256("test cancel")); @@ -530,22 +469,16 @@ contract CampaignInfo_UnitTest is Test, Defaults { // ============ Locked Functionality Tests ============ - function test_UpdateSelectedPlatform_SelectPlatform_WhenNotLocked_Success() public { // Test that platform selection works when not locked vm.startPrank(campaignOwner); - + bytes32[] memory dataKeys = new bytes32[](1); dataKeys[0] = platformDataKey1; bytes32[] memory dataValues = new bytes32[](1); dataValues[0] = platformDataValue1; - campaignInfo.updateSelectedPlatform( - platformHash1, - true, - dataKeys, - dataValues - ); + campaignInfo.updateSelectedPlatform(platformHash1, true, dataKeys, dataValues); // Verify platform is selected assertTrue(campaignInfo.checkIfPlatformSelected(platformHash1)); @@ -555,44 +488,34 @@ contract CampaignInfo_UnitTest is Test, Defaults { function test_UpdateSelectedPlatform_DeselectPlatform_WhenNotLocked_Success() public { // First select a platform vm.startPrank(campaignOwner); - + bytes32[] memory dataKeys = new bytes32[](1); dataKeys[0] = platformDataKey1; bytes32[] memory dataValues = new bytes32[](1); dataValues[0] = platformDataValue1; - campaignInfo.updateSelectedPlatform( - platformHash1, - true, - dataKeys, - dataValues - ); + campaignInfo.updateSelectedPlatform(platformHash1, true, dataKeys, dataValues); // Now deselect it - campaignInfo.updateSelectedPlatform( - platformHash1, - false, - new bytes32[](0), - new bytes32[](0) - ); + campaignInfo.updateSelectedPlatform(platformHash1, false, new bytes32[](0), new bytes32[](0)); // Verify platform is not selected assertFalse(campaignInfo.checkIfPlatformSelected(platformHash1)); - + // Verify platform fee is reset to 0 assertEq(campaignInfo.getPlatformFeePercent(platformHash1), 0); - + vm.stopPrank(); } function test_UpdateLaunchTime_WhenNotLocked_Success() public { // Test that launch time update works when not locked vm.startPrank(campaignOwner); - + uint256 newLaunchTime = block.timestamp + 1 days; - + campaignInfo.updateLaunchTime(newLaunchTime); - + assertEq(campaignInfo.getLaunchTime(), newLaunchTime); vm.stopPrank(); } @@ -600,11 +523,11 @@ contract CampaignInfo_UnitTest is Test, Defaults { function test_UpdateDeadline_WhenNotLocked_Success() public { // Test that deadline update works when not locked vm.startPrank(campaignOwner); - + uint256 newDeadline = campaignInfo.getLaunchTime() + 60 days; - + campaignInfo.updateDeadline(newDeadline); - + assertEq(campaignInfo.getDeadline(), newDeadline); vm.stopPrank(); } @@ -612,11 +535,11 @@ contract CampaignInfo_UnitTest is Test, Defaults { function test_UpdateGoalAmount_WhenNotLocked_Success() public { // Test that goal amount update works when not locked vm.startPrank(campaignOwner); - - uint256 newGoalAmount = 2000 * 10**18; - + + uint256 newGoalAmount = 2000 * 10 ** 18; + campaignInfo.updateGoalAmount(newGoalAmount); - + assertEq(campaignInfo.getGoalAmount(), newGoalAmount); vm.stopPrank(); } @@ -631,12 +554,7 @@ contract CampaignInfo_UnitTest is Test, Defaults { bytes32[] memory dataValues = new bytes32[](1); dataValues[0] = platformDataValue1; - campaignInfo.updateSelectedPlatform( - platformHash1, - true, - dataKeys, - dataValues - ); + campaignInfo.updateSelectedPlatform(platformHash1, true, dataKeys, dataValues); vm.stopPrank(); // Verify campaign is not locked initially @@ -662,7 +580,7 @@ contract CampaignInfo_UnitTest is Test, Defaults { vm.startPrank(campaignOwner); uint256 newLaunchTime = block.timestamp + 1 days; - + vm.expectRevert(CampaignInfo.CampaignInfoIsLocked.selector); campaignInfo.updateLaunchTime(newLaunchTime); vm.stopPrank(); @@ -674,7 +592,7 @@ contract CampaignInfo_UnitTest is Test, Defaults { vm.startPrank(campaignOwner); uint256 newDeadline = campaignInfo.getLaunchTime() + 60 days; - + vm.expectRevert(CampaignInfo.CampaignInfoIsLocked.selector); campaignInfo.updateDeadline(newDeadline); vm.stopPrank(); @@ -685,8 +603,8 @@ contract CampaignInfo_UnitTest is Test, Defaults { _lockCampaign(); vm.startPrank(campaignOwner); - uint256 newGoalAmount = 2000 * 10**18; - + uint256 newGoalAmount = 2000 * 10 ** 18; + vm.expectRevert(CampaignInfo.CampaignInfoIsLocked.selector); campaignInfo.updateGoalAmount(newGoalAmount); vm.stopPrank(); @@ -700,12 +618,7 @@ contract CampaignInfo_UnitTest is Test, Defaults { bytes32[] memory dataValues = new bytes32[](1); dataValues[0] = platformDataValue1; - campaignInfo.updateSelectedPlatform( - platformHash1, - true, - dataKeys, - dataValues - ); + campaignInfo.updateSelectedPlatform(platformHash1, true, dataKeys, dataValues); vm.stopPrank(); // Lock the campaign by deploying treasury @@ -720,17 +633,9 @@ contract CampaignInfo_UnitTest is Test, Defaults { // Now try to deselect the platform - should revert with already approved error vm.startPrank(campaignOwner); vm.expectRevert( - abi.encodeWithSelector( - CampaignInfo.CampaignInfoPlatformAlreadyApproved.selector, - platformHash1 - ) - ); - campaignInfo.updateSelectedPlatform( - platformHash1, - false, - new bytes32[](0), - new bytes32[](0) + abi.encodeWithSelector(CampaignInfo.CampaignInfoPlatformAlreadyApproved.selector, platformHash1) ); + campaignInfo.updateSelectedPlatform(platformHash1, false, new bytes32[](0), new bytes32[](0)); vm.stopPrank(); } @@ -745,12 +650,7 @@ contract CampaignInfo_UnitTest is Test, Defaults { bytes32[] memory dataValues = new bytes32[](1); dataValues[0] = platformDataValue2; - campaignInfo.updateSelectedPlatform( - platformHash2, - true, - dataKeys, - dataValues - ); + campaignInfo.updateSelectedPlatform(platformHash2, true, dataKeys, dataValues); // Verify platform is selected assertTrue(campaignInfo.checkIfPlatformSelected(platformHash2)); @@ -765,7 +665,7 @@ contract CampaignInfo_UnitTest is Test, Defaults { // Transfer ownership should still work when locked vm.startPrank(campaignOwner); campaignInfo.transferOwnership(newOwner); - + assertEq(campaignInfo.owner(), newOwner); vm.stopPrank(); } @@ -778,7 +678,7 @@ contract CampaignInfo_UnitTest is Test, Defaults { vm.startPrank(admin); bytes32 message = keccak256("test pause"); campaignInfo._pauseCampaign(message); - + assertTrue(campaignInfo.paused()); vm.stopPrank(); } @@ -796,7 +696,7 @@ contract CampaignInfo_UnitTest is Test, Defaults { vm.startPrank(admin); bytes32 message = keccak256("test unpause"); campaignInfo._unpauseCampaign(message); - + assertFalse(campaignInfo.paused()); vm.stopPrank(); } @@ -809,7 +709,7 @@ contract CampaignInfo_UnitTest is Test, Defaults { vm.startPrank(admin); bytes32 message = keccak256("test cancel"); campaignInfo._cancelCampaign(message); - + assertTrue(campaignInfo.cancelled()); vm.stopPrank(); } @@ -822,7 +722,7 @@ contract CampaignInfo_UnitTest is Test, Defaults { vm.startPrank(campaignOwner); bytes32 message = keccak256("test cancel"); campaignInfo._cancelCampaign(message); - + assertTrue(campaignInfo.cancelled()); vm.stopPrank(); } @@ -836,7 +736,7 @@ contract CampaignInfo_UnitTest is Test, Defaults { assertEq(campaignInfo.owner(), campaignOwner); assertTrue(campaignInfo.getLaunchTime() > 0); assertTrue(campaignInfo.getDeadline() > campaignInfo.getLaunchTime()); - assertEq(campaignInfo.getGoalAmount(), 1000 * 10**18); + assertEq(campaignInfo.getGoalAmount(), 1000 * 10 ** 18); assertEq(campaignInfo.getCampaignCurrency(), bytes32("USD")); assertFalse(campaignInfo.paused()); assertFalse(campaignInfo.cancelled()); @@ -849,7 +749,7 @@ contract CampaignInfo_UnitTest is Test, Defaults { // Platform-related view functions should still work assertFalse(campaignInfo.checkIfPlatformSelected(platformHash2)); assertFalse(campaignInfo.checkIfPlatformApproved(platformHash2)); - + bytes32[] memory approvedPlatforms = campaignInfo.getApprovedPlatformHashes(); assertEq(approvedPlatforms.length, 1); assertEq(approvedPlatforms[0], platformHash1); @@ -863,12 +763,7 @@ contract CampaignInfo_UnitTest is Test, Defaults { bytes32[] memory dataValues = new bytes32[](1); dataValues[0] = platformDataValue1; - campaignInfo.updateSelectedPlatform( - platformHash1, - true, - dataKeys, - dataValues - ); + campaignInfo.updateSelectedPlatform(platformHash1, true, dataKeys, dataValues); vm.stopPrank(); // Approve the platform (this locks the campaign) @@ -883,17 +778,9 @@ contract CampaignInfo_UnitTest is Test, Defaults { // Now try to deselect the already approved platform - should revert with already approved error vm.startPrank(campaignOwner); vm.expectRevert( - abi.encodeWithSelector( - CampaignInfo.CampaignInfoPlatformAlreadyApproved.selector, - platformHash1 - ) - ); - campaignInfo.updateSelectedPlatform( - platformHash1, - false, - new bytes32[](0), - new bytes32[](0) + abi.encodeWithSelector(CampaignInfo.CampaignInfoPlatformAlreadyApproved.selector, platformHash1) ); + campaignInfo.updateSelectedPlatform(platformHash1, false, new bytes32[](0), new bytes32[](0)); vm.stopPrank(); } @@ -905,12 +792,7 @@ contract CampaignInfo_UnitTest is Test, Defaults { bytes32[] memory dataValues = new bytes32[](1); dataValues[0] = platformDataValue1; - campaignInfo.updateSelectedPlatform( - platformHash1, - true, - dataKeys, - dataValues - ); + campaignInfo.updateSelectedPlatform(platformHash1, true, dataKeys, dataValues); vm.stopPrank(); // Approve the platform (this locks the campaign) @@ -921,12 +803,7 @@ contract CampaignInfo_UnitTest is Test, Defaults { // Now try to select the already approved platform again - should revert vm.startPrank(campaignOwner); vm.expectRevert(CampaignInfo.CampaignInfoInvalidInput.selector); - campaignInfo.updateSelectedPlatform( - platformHash1, - true, - dataKeys, - dataValues - ); + campaignInfo.updateSelectedPlatform(platformHash1, true, dataKeys, dataValues); vm.stopPrank(); } @@ -939,12 +816,7 @@ contract CampaignInfo_UnitTest is Test, Defaults { bytes32[] memory dataValues = new bytes32[](1); dataValues[0] = platformDataValue1; - campaignInfo.updateSelectedPlatform( - platformHash1, - true, - dataKeys, - dataValues - ); + campaignInfo.updateSelectedPlatform(platformHash1, true, dataKeys, dataValues); vm.stopPrank(); // Then deploy a treasury (this locks the campaign) @@ -956,4 +828,4 @@ contract CampaignInfo_UnitTest is Test, Defaults { ); vm.stopPrank(); } -} \ No newline at end of file +} diff --git a/test/foundry/unit/CampaignInfoFactory.t.sol b/test/foundry/unit/CampaignInfoFactory.t.sol index 1df4063e..234379e4 100644 --- a/test/foundry/unit/CampaignInfoFactory.t.sol +++ b/test/foundry/unit/CampaignInfoFactory.t.sol @@ -24,45 +24,33 @@ contract CampaignInfoFactory_UnitTest is Test, Defaults { function setUp() public { testToken = new TestToken(tokenName, tokenSymbol, 18); - + // Setup currencies and tokens for multi-token support bytes32[] memory currencies = new bytes32[](1); currencies[0] = bytes32("USD"); - + address[][] memory tokensPerCurrency = new address[][](1); tokensPerCurrency[0] = new address[](1); tokensPerCurrency[0][0] = address(testToken); - + // Deploy GlobalParams with proxy GlobalParams globalParamsImpl = new GlobalParams(); bytes memory globalParamsInitData = abi.encodeWithSelector( - GlobalParams.initialize.selector, - admin, - PROTOCOL_FEE_PERCENT, - currencies, - tokensPerCurrency - ); - ERC1967Proxy globalParamsProxy = new ERC1967Proxy( - address(globalParamsImpl), - globalParamsInitData + GlobalParams.initialize.selector, admin, PROTOCOL_FEE_PERCENT, currencies, tokensPerCurrency ); + ERC1967Proxy globalParamsProxy = new ERC1967Proxy(address(globalParamsImpl), globalParamsInitData); globalParams = GlobalParams(address(globalParamsProxy)); - + // Deploy CampaignInfo implementation campaignInfoImplementation = new CampaignInfo(); - + // Deploy TreasuryFactory with proxy TreasuryFactory treasuryFactoryImpl = new TreasuryFactory(); - bytes memory treasuryFactoryInitData = abi.encodeWithSelector( - TreasuryFactory.initialize.selector, - IGlobalParams(address(globalParams)) - ); - ERC1967Proxy treasuryFactoryProxy = new ERC1967Proxy( - address(treasuryFactoryImpl), - treasuryFactoryInitData - ); + bytes memory treasuryFactoryInitData = + abi.encodeWithSelector(TreasuryFactory.initialize.selector, IGlobalParams(address(globalParams))); + ERC1967Proxy treasuryFactoryProxy = new ERC1967Proxy(address(treasuryFactoryImpl), treasuryFactoryInitData); treasuryFactory = TreasuryFactory(address(treasuryFactoryProxy)); - + // Deploy CampaignInfoFactory with proxy CampaignInfoFactory factoryImpl = new CampaignInfoFactory(); bytes memory factoryInitData = abi.encodeWithSelector( @@ -72,28 +60,20 @@ contract CampaignInfoFactory_UnitTest is Test, Defaults { address(campaignInfoImplementation), address(treasuryFactory) ); - ERC1967Proxy factoryProxy = new ERC1967Proxy( - address(factoryImpl), - factoryInitData - ); + ERC1967Proxy factoryProxy = new ERC1967Proxy(address(factoryImpl), factoryInitData); factory = CampaignInfoFactory(address(factoryProxy)); - + vm.startPrank(admin); globalParams.enlistPlatform( PLATFORM_1_HASH, admin, - PLATFORM_FEE_PERCENT + PLATFORM_FEE_PERCENT, + address(0) // Platform adapter - can be set later with setPlatformAdapter ); - + // Set time constraints in dataRegistry - globalParams.addToRegistry( - DataRegistryKeys.CAMPAIGN_LAUNCH_BUFFER, - bytes32(uint256(1 hours)) - ); - globalParams.addToRegistry( - DataRegistryKeys.MINIMUM_CAMPAIGN_DURATION, - bytes32(uint256(1 days)) - ); + globalParams.addToRegistry(DataRegistryKeys.CAMPAIGN_LAUNCH_BUFFER, bytes32(uint256(1 hours))); + globalParams.addToRegistry(DataRegistryKeys.MINIMUM_CAMPAIGN_DURATION, bytes32(uint256(1 days))); vm.stopPrank(); } @@ -129,9 +109,7 @@ contract CampaignInfoFactory_UnitTest is Test, Defaults { assertGt(logs.length, 0, "Expected at least one log"); // Decode expected event - bytes32 eventSig = keccak256( - "CampaignInfoFactoryCampaignCreated(bytes32,address)" - ); + bytes32 eventSig = keccak256("CampaignInfoFactoryCampaignCreated(bytes32,address)"); bool found = false; address campaignAddr; @@ -148,34 +126,29 @@ contract CampaignInfoFactory_UnitTest is Test, Defaults { assertTrue(campaignAddr != address(0), "Invalid campaign address"); // Check that campaign was stored in mapping - address storedCampaign = factory.identifierToCampaignInfo( - CAMPAIGN_1_IDENTIFIER_HASH - ); + address storedCampaign = factory.identifierToCampaignInfo(CAMPAIGN_1_IDENTIFIER_HASH); assertEq(storedCampaign, campaignAddr, "Stored campaign doesn't match"); // Check that it's valid - assertTrue( - factory.isValidCampaignInfo(campaignAddr), - "Campaign not marked valid" - ); + assertTrue(factory.isValidCampaignInfo(campaignAddr), "Campaign not marked valid"); } function testUpgrade() public { // Deploy new implementation CampaignInfoFactory newImplementation = new CampaignInfoFactory(); - + // Upgrade as owner (address(this)) factory.upgradeToAndCall(address(newImplementation), ""); - + // Factory should still work after upgrade bytes32[] memory platforms = new bytes32[](1); platforms[0] = PLATFORM_1_HASH; - + bytes32[] memory keys = new bytes32[](0); bytes32[] memory values = new bytes32[](0); - + address creator = address(0xBEEF); - + vm.prank(admin); factory.createCampaign( creator, @@ -194,7 +167,7 @@ contract CampaignInfoFactory_UnitTest is Test, Defaults { function testUpgradeUnauthorizedReverts() public { // Deploy new implementation CampaignInfoFactory newImplementation = new CampaignInfoFactory(); - + // Try to upgrade as non-owner (should revert) vm.prank(admin); vm.expectRevert(); diff --git a/test/foundry/unit/GlobalParams.t.sol b/test/foundry/unit/GlobalParams.t.sol index 41d25561..4fece932 100644 --- a/test/foundry/unit/GlobalParams.t.sol +++ b/test/foundry/unit/GlobalParams.t.sol @@ -25,32 +25,27 @@ contract GlobalParams_UnitTest is Test, Defaults { token1 = new TestToken("Token1", "TK1", 18); token2 = new TestToken("Token2", "TK2", 18); token3 = new TestToken("Token3", "TK3", 18); - + // Setup initial currencies and tokens bytes32[] memory currencies = new bytes32[](2); currencies[0] = USD; currencies[1] = EUR; - + address[][] memory tokensPerCurrency = new address[][](2); tokensPerCurrency[0] = new address[](2); tokensPerCurrency[0][0] = address(token1); tokensPerCurrency[0][1] = address(token2); - + tokensPerCurrency[1] = new address[](1); tokensPerCurrency[1][0] = address(token3); - + // Deploy implementation implementation = new GlobalParams(); - + // Prepare initialization data - bytes memory initData = abi.encodeWithSelector( - GlobalParams.initialize.selector, - admin, - protocolFee, - currencies, - tokensPerCurrency - ); - + bytes memory initData = + abi.encodeWithSelector(GlobalParams.initialize.selector, admin, protocolFee, currencies, tokensPerCurrency); + // Deploy proxy ERC1967Proxy proxy = new ERC1967Proxy(address(implementation), initData); globalParams = GlobalParams(address(proxy)); @@ -59,18 +54,18 @@ contract GlobalParams_UnitTest is Test, Defaults { function testInitialValues() public { assertEq(globalParams.getProtocolAdminAddress(), admin); assertEq(globalParams.getProtocolFeePercent(), protocolFee); - + // Test USD tokens address[] memory usdTokens = globalParams.getTokensForCurrency(USD); assertEq(usdTokens.length, 2); assertEq(usdTokens[0], address(token1)); assertEq(usdTokens[1], address(token2)); - + // Test EUR tokens address[] memory eurTokens = globalParams.getTokensForCurrency(EUR); assertEq(eurTokens.length, 1); assertEq(eurTokens[0], address(token3)); - + // Token validation is done by checking if token is in the returned array // This is handled by the getTokensForCurrency function above } @@ -90,10 +85,10 @@ contract GlobalParams_UnitTest is Test, Defaults { function testAddTokenToCurrency() public { TestToken newToken = new TestToken("NewToken", "NEW", 18); - + vm.prank(admin); globalParams.addTokenToCurrency(USD, address(newToken)); - + // Verify token was added address[] memory usdTokens = globalParams.getTokensForCurrency(USD); assertEq(usdTokens.length, 3); @@ -102,10 +97,10 @@ contract GlobalParams_UnitTest is Test, Defaults { function testAddTokenToNewCurrency() public { TestToken newToken = new TestToken("BRLToken", "BRL", 18); - + vm.prank(admin); globalParams.addTokenToCurrency(BRL, address(newToken)); - + // Verify token was added to new currency address[] memory brlTokens = globalParams.getTokensForCurrency(BRL); assertEq(brlTokens.length, 1); @@ -114,7 +109,7 @@ contract GlobalParams_UnitTest is Test, Defaults { function testAddTokenRevertWhenNotOwner() public { TestToken newToken = new TestToken("NewToken", "NEW", 18); - + vm.expectRevert(); globalParams.addTokenToCurrency(USD, address(newToken)); } @@ -123,11 +118,11 @@ contract GlobalParams_UnitTest is Test, Defaults { // A token can be assigned to multiple currencies vm.prank(admin); globalParams.addTokenToCurrency(EUR, address(token1)); - + // Verify token is now in both USD and EUR address[] memory usdTokens = globalParams.getTokensForCurrency(USD); address[] memory eurTokens = globalParams.getTokensForCurrency(EUR); - + assertEq(usdTokens.length, 2); assertEq(eurTokens.length, 2); assertEq(eurTokens[1], address(token1)); @@ -136,7 +131,7 @@ contract GlobalParams_UnitTest is Test, Defaults { function testRemoveTokenFromCurrency() public { vm.prank(admin); globalParams.removeTokenFromCurrency(USD, address(token1)); - + // Verify token was removed address[] memory usdTokens = globalParams.getTokensForCurrency(USD); assertEq(usdTokens.length, 1); @@ -149,10 +144,10 @@ contract GlobalParams_UnitTest is Test, Defaults { } function testRemoveTokenThatDoesNotExist() public { - // Removing a non-existent token + // Removing a non-existent token TestToken nonExistentToken = new TestToken("NonExistent", "NE", 18); - - vm.expectRevert(); + + vm.expectRevert(); vm.prank(admin); globalParams.removeTokenFromCurrency(USD, address(nonExistentToken)); } @@ -162,7 +157,7 @@ contract GlobalParams_UnitTest is Test, Defaults { address platformAdmin = address(0xB0B); vm.prank(admin); - globalParams.enlistPlatform(platformHash, platformAdmin, 500); + globalParams.enlistPlatform(platformHash, platformAdmin, 500, address(0)); uint256 claimDelay = 5 days; vm.prank(platformAdmin); @@ -176,7 +171,7 @@ contract GlobalParams_UnitTest is Test, Defaults { address platformAdmin = address(0xC0DE); vm.prank(admin); - globalParams.enlistPlatform(platformHash, platformAdmin, 600); + globalParams.enlistPlatform(platformHash, platformAdmin, 600, address(0)); vm.expectRevert(abi.encodeWithSelector(GlobalParams.GlobalParamsUnauthorized.selector)); globalParams.updatePlatformClaimDelay(platformHash, 3 days); @@ -188,7 +183,7 @@ contract GlobalParams_UnitTest is Test, Defaults { bytes32 typeId = keccak256("refundable_fee_with_protocol"); vm.prank(admin); - globalParams.enlistPlatform(platformHash, platformAdmin, 500); + globalParams.enlistPlatform(platformHash, platformAdmin, 500, address(0)); vm.prank(platformAdmin); globalParams.setPlatformLineItemType( @@ -196,19 +191,13 @@ contract GlobalParams_UnitTest is Test, Defaults { typeId, "refundable_fee_with_protocol", false, // countsTowardGoal - true, // applyProtocolFee - true, // canRefund - false // instantTransfer + true, // applyProtocolFee + true, // canRefund + false // instantTransfer ); - ( - bool exists, - , - bool countsTowardGoal, - bool applyProtocolFee, - bool canRefund, - bool instantTransfer - ) = globalParams.getPlatformLineItemType(platformHash, typeId); + (bool exists,, bool countsTowardGoal, bool applyProtocolFee, bool canRefund, bool instantTransfer) = + globalParams.getPlatformLineItemType(platformHash, typeId); assertTrue(exists); assertFalse(countsTowardGoal); @@ -223,7 +212,7 @@ contract GlobalParams_UnitTest is Test, Defaults { bytes32 typeId = keccak256("goal_type"); vm.prank(admin); - globalParams.enlistPlatform(platformHash, platformAdmin, 400); + globalParams.enlistPlatform(platformHash, platformAdmin, 400, address(0)); vm.expectRevert(GlobalParams.GlobalParamsInvalidInput.selector); vm.prank(platformAdmin); @@ -231,10 +220,10 @@ contract GlobalParams_UnitTest is Test, Defaults { platformHash, typeId, "goal_type", - true, // countsTowardGoal - true, // applyProtocolFee (should revert) - true, // canRefund - false // instantTransfer + true, // countsTowardGoal + true, // applyProtocolFee (should revert) + true, // canRefund + false // instantTransfer ); } @@ -244,7 +233,7 @@ contract GlobalParams_UnitTest is Test, Defaults { bytes32 typeId = keccak256("goal_no_refund"); vm.prank(admin); - globalParams.enlistPlatform(platformHash, platformAdmin, 450); + globalParams.enlistPlatform(platformHash, platformAdmin, 450, address(0)); vm.expectRevert(GlobalParams.GlobalParamsInvalidInput.selector); vm.prank(platformAdmin); @@ -252,10 +241,10 @@ contract GlobalParams_UnitTest is Test, Defaults { platformHash, typeId, "goal_no_refund", - true, // countsTowardGoal - false, // applyProtocolFee - false, // canRefund (should revert) - false // instantTransfer + true, // countsTowardGoal + false, // applyProtocolFee + false, // canRefund (should revert) + false // instantTransfer ); } @@ -265,7 +254,7 @@ contract GlobalParams_UnitTest is Test, Defaults { bytes32 typeId = keccak256("instant_refundable"); vm.prank(admin); - globalParams.enlistPlatform(platformHash, platformAdmin, 300); + globalParams.enlistPlatform(platformHash, platformAdmin, 300, address(0)); vm.expectRevert(GlobalParams.GlobalParamsInvalidInput.selector); vm.prank(platformAdmin); @@ -275,18 +264,18 @@ contract GlobalParams_UnitTest is Test, Defaults { "instant_refundable", false, // countsTowardGoal (non-goal) false, // applyProtocolFee - true, // canRefund (should revert with instantTransfer) - true // instantTransfer + true, // canRefund (should revert with instantTransfer) + true // instantTransfer ); } function testGetTokensForCurrency() public { address[] memory usdTokens = globalParams.getTokensForCurrency(USD); assertEq(usdTokens.length, 2); - + address[] memory eurTokens = globalParams.getTokensForCurrency(EUR); assertEq(eurTokens.length, 1); - + // Non-existent currency returns empty array address[] memory nonExistentTokens = globalParams.getTokensForCurrency(BRL); assertEq(nonExistentTokens.length, 0); @@ -303,19 +292,14 @@ contract GlobalParams_UnitTest is Test, Defaults { function testInitializerWithEmptyArrays() public { bytes32[] memory currencies = new bytes32[](0); address[][] memory tokensPerCurrency = new address[][](0); - + GlobalParams emptyImpl = new GlobalParams(); - bytes memory initData = abi.encodeWithSelector( - GlobalParams.initialize.selector, - admin, - protocolFee, - currencies, - tokensPerCurrency - ); - + bytes memory initData = + abi.encodeWithSelector(GlobalParams.initialize.selector, admin, protocolFee, currencies, tokensPerCurrency); + ERC1967Proxy emptyProxy = new ERC1967Proxy(address(emptyImpl), initData); GlobalParams emptyGlobalParams = GlobalParams(address(emptyProxy)); - + address[] memory tokens = emptyGlobalParams.getTokensForCurrency(USD); assertEq(tokens.length, 0); } @@ -324,20 +308,15 @@ contract GlobalParams_UnitTest is Test, Defaults { bytes32[] memory currencies = new bytes32[](2); currencies[0] = USD; currencies[1] = EUR; - + address[][] memory tokensPerCurrency = new address[][](1); tokensPerCurrency[0] = new address[](1); tokensPerCurrency[0][0] = address(token1); - + GlobalParams mismatchImpl = new GlobalParams(); - bytes memory initData = abi.encodeWithSelector( - GlobalParams.initialize.selector, - admin, - protocolFee, - currencies, - tokensPerCurrency - ); - + bytes memory initData = + abi.encodeWithSelector(GlobalParams.initialize.selector, admin, protocolFee, currencies, tokensPerCurrency); + vm.expectRevert(); new ERC1967Proxy(address(mismatchImpl), initData); } @@ -346,12 +325,12 @@ contract GlobalParams_UnitTest is Test, Defaults { // USD should have 2 tokens address[] memory usdTokens = globalParams.getTokensForCurrency(USD); assertEq(usdTokens.length, 2); - + // Add a third token to USD TestToken token4 = new TestToken("Token4", "TK4", 18); vm.prank(admin); globalParams.addTokenToCurrency(USD, address(token4)); - + // Verify USD now has 3 tokens usdTokens = globalParams.getTokensForCurrency(USD); assertEq(usdTokens.length, 3); @@ -364,7 +343,7 @@ contract GlobalParams_UnitTest is Test, Defaults { // Remove token1 (first token) from USD vm.prank(admin); globalParams.removeTokenFromCurrency(USD, address(token1)); - + address[] memory usdTokens = globalParams.getTokensForCurrency(USD); assertEq(usdTokens.length, 1); assertEq(usdTokens[0], address(token2)); @@ -373,22 +352,22 @@ contract GlobalParams_UnitTest is Test, Defaults { function testAddRemoveMultipleTokens() public { TestToken token4 = new TestToken("Token4", "TK4", 18); TestToken token5 = new TestToken("Token5", "TK5", 18); - + // Add two new tokens vm.startPrank(admin); globalParams.addTokenToCurrency(USD, address(token4)); globalParams.addTokenToCurrency(USD, address(token5)); vm.stopPrank(); - + address[] memory usdTokens = globalParams.getTokensForCurrency(USD); assertEq(usdTokens.length, 4); - + // Remove original tokens vm.startPrank(admin); globalParams.removeTokenFromCurrency(USD, address(token1)); globalParams.removeTokenFromCurrency(USD, address(token2)); vm.stopPrank(); - + usdTokens = globalParams.getTokensForCurrency(USD); assertEq(usdTokens.length, 2); assertEq(usdTokens[0], address(token5)); // token5 moved to index 0 @@ -398,15 +377,15 @@ contract GlobalParams_UnitTest is Test, Defaults { function testUpgrade() public { // Deploy new implementation GlobalParams newImplementation = new GlobalParams(); - + // Upgrade as admin vm.prank(admin); globalParams.upgradeToAndCall(address(newImplementation), ""); - + // Verify state is preserved after upgrade assertEq(globalParams.getProtocolAdminAddress(), admin); assertEq(globalParams.getProtocolFeePercent(), protocolFee); - + address[] memory usdTokens = globalParams.getTokensForCurrency(USD); assertEq(usdTokens.length, 2); } @@ -414,7 +393,7 @@ contract GlobalParams_UnitTest is Test, Defaults { function testUpgradeUnauthorizedReverts() public { // Deploy new implementation GlobalParams newImplementation = new GlobalParams(); - + // Try to upgrade as non-admin (should revert) vm.expectRevert(); globalParams.upgradeToAndCall(address(newImplementation), ""); @@ -423,7 +402,7 @@ contract GlobalParams_UnitTest is Test, Defaults { function testCannotInitializeTwice() public { bytes32[] memory currencies = new bytes32[](0); address[][] memory tokensPerCurrency = new address[][](0); - + // Try to initialize again (should revert) vm.expectRevert(); globalParams.initialize(admin, protocolFee, currencies, tokensPerCurrency); diff --git a/test/foundry/unit/KeepWhatsRaised.t.sol b/test/foundry/unit/KeepWhatsRaised.t.sol index c8dc940c..d31a64d2 100644 --- a/test/foundry/unit/KeepWhatsRaised.t.sol +++ b/test/foundry/unit/KeepWhatsRaised.t.sol @@ -15,77 +15,72 @@ import {ICampaignData} from "src/interfaces/ICampaignData.sol"; import {TestToken} from "../../mocks/TestToken.sol"; contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Test { - // Test constants uint256 internal constant TEST_PLEDGE_AMOUNT = 1000e18; uint256 internal constant TEST_TIP_AMOUNT = 50e18; bytes32 internal constant TEST_REWARD_NAME = keccak256("testReward"); bytes32 internal constant TEST_PLEDGE_ID = keccak256("testPledgeId"); - + function setUp() public virtual override { super.setUp(); deal(address(testToken), users.backer1Address, 100_000e18); deal(address(testToken), users.backer2Address, 100_000e18); - + // Label addresses vm.label(users.protocolAdminAddress, "ProtocolAdmin"); vm.label(users.platform2AdminAddress, "PlatformAdmin"); vm.label(users.contractOwner, "CampaignOwner"); vm.label(users.backer1Address, "Backer1"); - vm.label(users.backer2Address, "Backer2"); + vm.label(users.backer2Address, "Backer2"); vm.label(address(keepWhatsRaised), "KeepWhatsRaised"); vm.label(address(globalParams), "GlobalParams"); } - + /*////////////////////////////////////////////////////////////// INITIALIZATION //////////////////////////////////////////////////////////////*/ - + function testInitialize() public { bytes32 newIdentifierHash = keccak256(abi.encodePacked("newCampaign")); bytes32[] memory selectedPlatformHash = new bytes32[](1); selectedPlatformHash[0] = PLATFORM_2_HASH; - + // Pass empty arrays since platform data is not used by the new treasury bytes32[] memory platformDataKey = new bytes32[](0); bytes32[] memory platformDataValue = new bytes32[](0); - + vm.prank(users.creator1Address); campaignInfoFactory.createCampaign( users.creator1Address, newIdentifierHash, selectedPlatformHash, - platformDataKey, // Empty array - platformDataValue, // Empty array + platformDataKey, // Empty array + platformDataValue, // Empty array CAMPAIGN_DATA, "Campaign Pledge NFT", "PLEDGE", "ipfs://QmExampleImageURI", "ipfs://QmExampleContractURI" ); - + address newCampaignAddress = campaignInfoFactory.identifierToCampaignInfo(newIdentifierHash); - + // Deploy vm.prank(users.platform2AdminAddress); - address newTreasury = treasuryFactory.deploy( - PLATFORM_2_HASH, - newCampaignAddress, - 1 - ); - + address newTreasury = treasuryFactory.deploy(PLATFORM_2_HASH, newCampaignAddress, 1); + KeepWhatsRaised newContract = KeepWhatsRaised(newTreasury); CampaignInfo newCampaignInfo = CampaignInfo(newCampaignAddress); - + // NFT name and symbol are now on CampaignInfo, not treasury assertEq(newCampaignInfo.name(), "Campaign Pledge NFT"); assertEq(newCampaignInfo.symbol(), "PLEDGE"); } - + /*////////////////////////////////////////////////////////////// TREASURY CONFIGURATION //////////////////////////////////////////////////////////////*/ - + function testConfigureTreasury() public { ICampaignData.CampaignData memory newCampaignData = ICampaignData.CampaignData({ launchTime: block.timestamp + 1 days, @@ -93,23 +88,23 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te goalAmount: 5000, currency: bytes32("USD") }); - + KeepWhatsRaised.FeeValues memory feeValues = _createFeeValues(); - + vm.prank(users.platform2AdminAddress); keepWhatsRaised.configureTreasury(CONFIG, newCampaignData, FEE_KEYS, feeValues); - + assertEq(keepWhatsRaised.getLaunchTime(), newCampaignData.launchTime); assertEq(keepWhatsRaised.getDeadline(), newCampaignData.deadline); assertEq(keepWhatsRaised.getGoalAmount(), newCampaignData.goalAmount); - + // Verify fee values are stored assertEq(keepWhatsRaised.getFeeValue(FLAT_FEE_KEY), uint256(FLAT_FEE_VALUE)); assertEq(keepWhatsRaised.getFeeValue(CUMULATIVE_FLAT_FEE_KEY), uint256(CUMULATIVE_FLAT_FEE_VALUE)); assertEq(keepWhatsRaised.getFeeValue(PLATFORM_FEE_KEY), uint256(PLATFORM_FEE_VALUE)); assertEq(keepWhatsRaised.getFeeValue(VAKI_COMMISSION_KEY), uint256(VAKI_COMMISSION_VALUE)); } - + function testConfigureTreasuryWithColombianCreator() public { ICampaignData.CampaignData memory newCampaignData = ICampaignData.CampaignData({ launchTime: block.timestamp + 1 days, @@ -117,43 +112,43 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te goalAmount: 5000, currency: bytes32("USD") }); - + KeepWhatsRaised.FeeValues memory feeValues = _createFeeValues(); - + vm.prank(users.platform2AdminAddress); keepWhatsRaised.configureTreasury(CONFIG_COLOMBIAN, newCampaignData, FEE_KEYS, feeValues); - + // Test that Colombian creator tax is not applied in pledges _setupReward(); setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, 0); - + vm.warp(keepWhatsRaised.getLaunchTime()); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); - + bytes32[] memory rewardSelection = new bytes32[](1); rewardSelection[0] = TEST_REWARD_NAME; - + keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), 0, rewardSelection); vm.stopPrank(); - + // Available amount should not include Colombian tax deduction at pledge time uint256 availableAmount = keepWhatsRaised.getAvailableRaisedAmount(); - uint256 expectedWithoutColombianTax = TEST_PLEDGE_AMOUNT - - (TEST_PLEDGE_AMOUNT * PLATFORM_FEE_PERCENT / PERCENT_DIVIDER) + uint256 expectedWithoutColombianTax = TEST_PLEDGE_AMOUNT + - (TEST_PLEDGE_AMOUNT * PLATFORM_FEE_PERCENT / PERCENT_DIVIDER) - (TEST_PLEDGE_AMOUNT * 6 * 100 / PERCENT_DIVIDER) - (TEST_PLEDGE_AMOUNT * PROTOCOL_FEE_PERCENT / PERCENT_DIVIDER); assertEq(availableAmount, expectedWithoutColombianTax, "Colombian tax should not be applied at pledge time"); } - + function testConfigureTreasuryRevertWhenNotPlatformAdmin() public { KeepWhatsRaised.FeeValues memory feeValues = _createFeeValues(); - + vm.expectRevert(); vm.prank(users.backer1Address); keepWhatsRaised.configureTreasury(CONFIG, CAMPAIGN_DATA, FEE_KEYS, feeValues); } - + function testConfigureTreasuryRevertWhenInvalidCampaignData() public { // Invalid launch time (in the past) ICampaignData.CampaignData memory invalidCampaignData = ICampaignData.CampaignData({ @@ -162,562 +157,580 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te goalAmount: 5000, currency: bytes32("USD") }); - + KeepWhatsRaised.FeeValues memory feeValues = _createFeeValues(); - + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedInvalidInput.selector); vm.prank(users.platform2AdminAddress); keepWhatsRaised.configureTreasury(CONFIG, invalidCampaignData, FEE_KEYS, feeValues); } - + function testConfigureTreasuryRevertWhenMismatchedFeeArrays() public { // Create mismatched fee arrays KeepWhatsRaised.FeeKeys memory mismatchedKeys = FEE_KEYS; KeepWhatsRaised.FeeValues memory mismatchedValues = _createFeeValues(); mismatchedValues.grossPercentageFeeValues = new uint256[](1); // Wrong length - + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedInvalidInput.selector); vm.prank(users.platform2AdminAddress); keepWhatsRaised.configureTreasury(CONFIG, CAMPAIGN_DATA, mismatchedKeys, mismatchedValues); } - + /*////////////////////////////////////////////////////////////// PAYMENT GATEWAY FEES //////////////////////////////////////////////////////////////*/ - + function testSetPaymentGatewayFee() public { vm.prank(users.platform2AdminAddress); keepWhatsRaised.setPaymentGatewayFee(TEST_PLEDGE_ID, PAYMENT_GATEWAY_FEE); - + assertEq(keepWhatsRaised.getPaymentGatewayFee(TEST_PLEDGE_ID), PAYMENT_GATEWAY_FEE); } - + function testSetPaymentGatewayFeeRevertWhenNotPlatformAdmin() public { vm.expectRevert(); vm.prank(users.backer1Address); keepWhatsRaised.setPaymentGatewayFee(TEST_PLEDGE_ID, PAYMENT_GATEWAY_FEE); } - + function testSetPaymentGatewayFeeRevertWhenPaused() public { _pauseTreasury(); - + vm.expectRevert(); vm.prank(users.platform2AdminAddress); keepWhatsRaised.setPaymentGatewayFee(TEST_PLEDGE_ID, PAYMENT_GATEWAY_FEE); } - + /*////////////////////////////////////////////////////////////// WITHDRAWAL APPROVAL //////////////////////////////////////////////////////////////*/ - + function testApproveWithdrawal() public { assertFalse(keepWhatsRaised.getWithdrawalApprovalStatus()); - + vm.prank(users.platform2AdminAddress); keepWhatsRaised.approveWithdrawal(); - + assertTrue(keepWhatsRaised.getWithdrawalApprovalStatus()); } - + function testApproveWithdrawalRevertWhenAlreadyApproved() public { vm.prank(users.platform2AdminAddress); keepWhatsRaised.approveWithdrawal(); - + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedAlreadyEnabled.selector); vm.prank(users.platform2AdminAddress); keepWhatsRaised.approveWithdrawal(); } - + function testApproveWithdrawalRevertWhenNotPlatformAdmin() public { vm.expectRevert(); vm.prank(users.backer1Address); keepWhatsRaised.approveWithdrawal(); } - + /*////////////////////////////////////////////////////////////// DEADLINE AND GOAL UPDATES //////////////////////////////////////////////////////////////*/ - + function testUpdateDeadlineByPlatformAdmin() public { uint256 newDeadline = DEADLINE + 10 days; - + vm.warp(LAUNCH_TIME + 1 days); // Within config lock period vm.prank(users.platform2AdminAddress); keepWhatsRaised.updateDeadline(newDeadline); - + assertEq(keepWhatsRaised.getDeadline(), newDeadline); } - + function testUpdateDeadlineByCampaignOwner() public { uint256 newDeadline = DEADLINE + 10 days; address campaignOwner = CampaignInfo(campaignAddress).owner(); - + vm.warp(LAUNCH_TIME + 1 days); vm.prank(campaignOwner); keepWhatsRaised.updateDeadline(newDeadline); - + assertEq(keepWhatsRaised.getDeadline(), newDeadline); } - + function testUpdateDeadlineRevertWhenNotAuthorized() public { vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedUnAuthorized.selector); vm.prank(users.backer1Address); keepWhatsRaised.updateDeadline(DEADLINE + 10 days); } - + function testUpdateDeadlineRevertWhenPastConfigLock() public { // Warp to past config lock period vm.warp(DEADLINE - CONFIG_LOCK_PERIOD + 1); - + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedConfigLocked.selector); vm.prank(users.platform2AdminAddress); keepWhatsRaised.updateDeadline(DEADLINE + 10 days); } - + function testUpdateDeadlineRevertWhenDeadlineBeforeLaunchTime() public { vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedInvalidInput.selector); vm.prank(users.platform2AdminAddress); keepWhatsRaised.updateDeadline(LAUNCH_TIME - 1); } - + function testUpdateDeadlineRevertWhenDeadlineBeforeCurrentTime() public { vm.warp(LAUNCH_TIME + 5 days); - + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedInvalidInput.selector); vm.prank(users.platform2AdminAddress); keepWhatsRaised.updateDeadline(LAUNCH_TIME + 4 days); } - + function testUpdateDeadlineRevertWhenPaused() public { _pauseTreasury(); - - // Try to update deadline + + // Try to update deadline vm.warp(LAUNCH_TIME + 1 days); vm.expectRevert(); vm.prank(users.platform2AdminAddress); keepWhatsRaised.updateDeadline(DEADLINE + 10 days); } - + function testUpdateGoalAmountByPlatformAdmin() public { uint256 newGoal = GOAL_AMOUNT * 2; - + vm.warp(LAUNCH_TIME + 1 days); vm.prank(users.platform2AdminAddress); keepWhatsRaised.updateGoalAmount(newGoal); - + assertEq(keepWhatsRaised.getGoalAmount(), newGoal); } - + function testUpdateGoalAmountByCampaignOwner() public { uint256 newGoal = GOAL_AMOUNT * 2; address campaignOwner = CampaignInfo(campaignAddress).owner(); - + vm.warp(LAUNCH_TIME + 1 days); vm.prank(campaignOwner); keepWhatsRaised.updateGoalAmount(newGoal); - + assertEq(keepWhatsRaised.getGoalAmount(), newGoal); } - + function testUpdateGoalAmountRevertWhenNotAuthorized() public { vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedUnAuthorized.selector); vm.prank(users.backer1Address); keepWhatsRaised.updateGoalAmount(GOAL_AMOUNT * 2); } - + function testUpdateGoalAmountRevertWhenZero() public { vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedInvalidInput.selector); vm.prank(users.platform2AdminAddress); keepWhatsRaised.updateGoalAmount(0); } - + /*////////////////////////////////////////////////////////////// REWARDS MANAGEMENT //////////////////////////////////////////////////////////////*/ - + function testAddRewards() public { bytes32[] memory rewardNames = new bytes32[](1); rewardNames[0] = TEST_REWARD_NAME; - + Reward[] memory rewards = new Reward[](1); rewards[0] = _createTestReward(TEST_PLEDGE_AMOUNT, true); - + vm.prank(users.creator1Address); keepWhatsRaised.addRewards(rewardNames, rewards); - + Reward memory retrievedReward = keepWhatsRaised.getReward(TEST_REWARD_NAME); assertEq(retrievedReward.rewardValue, TEST_PLEDGE_AMOUNT); assertTrue(retrievedReward.isRewardTier); } - + function testAddRewardsRevertWhenMismatchedArrays() public { bytes32[] memory rewardNames = new bytes32[](2); Reward[] memory rewards = new Reward[](1); - + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedInvalidInput.selector); vm.prank(users.creator1Address); keepWhatsRaised.addRewards(rewardNames, rewards); } - + function testAddRewardsRevertWhenDuplicateReward() public { bytes32[] memory rewardNames = new bytes32[](1); rewardNames[0] = TEST_REWARD_NAME; - + Reward[] memory rewards = new Reward[](1); rewards[0] = _createTestReward(TEST_PLEDGE_AMOUNT, true); - + // Add first time vm.prank(users.creator1Address); keepWhatsRaised.addRewards(rewardNames, rewards); - + // Try to add again vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedRewardExists.selector); vm.prank(users.creator1Address); keepWhatsRaised.addRewards(rewardNames, rewards); } - + function testRemoveReward() public { // First add a reward bytes32[] memory rewardNames = new bytes32[](1); rewardNames[0] = TEST_REWARD_NAME; - + Reward[] memory rewards = new Reward[](1); rewards[0] = _createTestReward(TEST_PLEDGE_AMOUNT, true); - + vm.prank(users.creator1Address); keepWhatsRaised.addRewards(rewardNames, rewards); - + // Remove reward vm.prank(users.creator1Address); keepWhatsRaised.removeReward(TEST_REWARD_NAME); - + // Verify removal vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedInvalidInput.selector); keepWhatsRaised.getReward(TEST_REWARD_NAME); } - + function testRemoveRewardRevertWhenRewardDoesNotExist() public { vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedInvalidInput.selector); vm.prank(users.creator1Address); keepWhatsRaised.removeReward(TEST_REWARD_NAME); } - + function testAddRewardsRevertWhenPaused() public { _pauseTreasury(); - + // Try to add rewards bytes32[] memory rewardNames = new bytes32[](1); rewardNames[0] = TEST_REWARD_NAME; - + Reward[] memory rewards = new Reward[](1); rewards[0] = _createTestReward(TEST_PLEDGE_AMOUNT, true); - + vm.expectRevert(); vm.prank(users.creator1Address); keepWhatsRaised.addRewards(rewardNames, rewards); } - + function testRemoveRewardRevertWhenPaused() public { // First add a reward bytes32[] memory rewardNames = new bytes32[](1); rewardNames[0] = TEST_REWARD_NAME; - + Reward[] memory rewards = new Reward[](1); rewards[0] = _createTestReward(TEST_PLEDGE_AMOUNT, true); - + vm.prank(users.creator1Address); keepWhatsRaised.addRewards(rewardNames, rewards); - + _pauseTreasury(); - + // Try to remove reward - should revert vm.expectRevert(); vm.prank(users.creator1Address); keepWhatsRaised.removeReward(TEST_REWARD_NAME); } - + /*////////////////////////////////////////////////////////////// PLEDGING //////////////////////////////////////////////////////////////*/ - + function testPledgeForAReward() public { // Add reward first _setupReward(); setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, PAYMENT_GATEWAY_FEE); - + uint256 balanceBefore = testToken.balanceOf(users.backer1Address); - + // Pledge vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT + TEST_TIP_AMOUNT); - + bytes32[] memory rewardSelection = new bytes32[](1); rewardSelection[0] = TEST_REWARD_NAME; - - keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_TIP_AMOUNT, rewardSelection); + + keepWhatsRaised.pledgeForAReward( + TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_TIP_AMOUNT, rewardSelection + ); vm.stopPrank(); - + // Verify assertEq(testToken.balanceOf(users.backer1Address), balanceBefore - TEST_PLEDGE_AMOUNT - TEST_TIP_AMOUNT); assertEq(keepWhatsRaised.getRaisedAmount(), TEST_PLEDGE_AMOUNT); assertTrue(keepWhatsRaised.getAvailableRaisedAmount() < TEST_PLEDGE_AMOUNT); // Less due to fees assertEq(CampaignInfo(campaignAddress).balanceOf(users.backer1Address), 1); } - + function testPledgeForARewardRevertWhenDuplicatePledgeId() public { _setupReward(); setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, PAYMENT_GATEWAY_FEE); - + vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT * 2); - + bytes32[] memory rewardSelection = new bytes32[](1); rewardSelection[0] = TEST_REWARD_NAME; - + // First pledge keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), 0, rewardSelection); - + // Try to pledge with same ID bytes32 internalPledgeId = keccak256(abi.encodePacked(TEST_PLEDGE_ID, users.backer1Address)); - vm.expectRevert(abi.encodeWithSelector(KeepWhatsRaised.KeepWhatsRaisedPledgeAlreadyProcessed.selector, internalPledgeId)); + vm.expectRevert( + abi.encodeWithSelector(KeepWhatsRaised.KeepWhatsRaisedPledgeAlreadyProcessed.selector, internalPledgeId) + ); keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), 0, rewardSelection); vm.stopPrank(); } - + function testPledgeForARewardRevertWhenNotRewardTier() public { // Add non-reward tier bytes32[] memory rewardNames = new bytes32[](1); rewardNames[0] = TEST_REWARD_NAME; - + Reward[] memory rewards = new Reward[](1); - rewards[0] = _createTestReward(TEST_PLEDGE_AMOUNT, false); - + rewards[0] = _createTestReward(TEST_PLEDGE_AMOUNT, false); + vm.prank(users.creator1Address); keepWhatsRaised.addRewards(rewardNames, rewards); - + // Try to pledge vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); - + bytes32[] memory rewardSelection = new bytes32[](1); rewardSelection[0] = TEST_REWARD_NAME; - + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedInvalidInput.selector); keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), 0, rewardSelection); vm.stopPrank(); } - + function testPledgeWithoutAReward() public { uint256 pledgeAmount = 500e18; uint256 balanceBefore = testToken.balanceOf(users.backer1Address); - + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, PAYMENT_GATEWAY_FEE); - + // Pledge vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), pledgeAmount + TEST_TIP_AMOUNT); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), pledgeAmount, TEST_TIP_AMOUNT); + keepWhatsRaised.pledgeWithoutAReward( + TEST_PLEDGE_ID, users.backer1Address, address(testToken), pledgeAmount, TEST_TIP_AMOUNT + ); vm.stopPrank(); - + // Verify assertEq(testToken.balanceOf(users.backer1Address), balanceBefore - pledgeAmount - TEST_TIP_AMOUNT); assertEq(keepWhatsRaised.getRaisedAmount(), pledgeAmount); assertTrue(keepWhatsRaised.getAvailableRaisedAmount() < pledgeAmount); // Less due to fees assertEq(CampaignInfo(campaignAddress).balanceOf(users.backer1Address), 1); } - + function testPledgeWithoutARewardRevertWhenDuplicatePledgeId() public { setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, 0); - + vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT * 2); - + // First pledge - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); - + keepWhatsRaised.pledgeWithoutAReward( + TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0 + ); + // Try to pledge with same ID - internal pledge ID includes caller bytes32 internalPledgeId = keccak256(abi.encodePacked(TEST_PLEDGE_ID, users.backer1Address)); - vm.expectRevert(abi.encodeWithSelector(KeepWhatsRaised.KeepWhatsRaisedPledgeAlreadyProcessed.selector, internalPledgeId)); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); + vm.expectRevert( + abi.encodeWithSelector(KeepWhatsRaised.KeepWhatsRaisedPledgeAlreadyProcessed.selector, internalPledgeId) + ); + keepWhatsRaised.pledgeWithoutAReward( + TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0 + ); vm.stopPrank(); } - + function testPledgeRevertWhenOutsideCampaignPeriod() public { // Before launch vm.warp(LAUNCH_TIME - 1); vm.expectRevert(); vm.prank(users.backer1Address); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); - + keepWhatsRaised.pledgeWithoutAReward( + TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0 + ); + // After deadline vm.warp(DEADLINE + 1); vm.expectRevert(); vm.prank(users.backer1Address); - keepWhatsRaised.pledgeWithoutAReward(keccak256("newPledge"), users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward( + keccak256("newPledge"), users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0 + ); } - + function testPledgeForARewardRevertWhenPaused() public { // Add reward first _setupReward(); - + _pauseTreasury(); - - // Try to pledge + + // Try to pledge vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT + TEST_TIP_AMOUNT); - + bytes32[] memory rewardSelection = new bytes32[](1); rewardSelection[0] = TEST_REWARD_NAME; - + vm.expectRevert(); - keepWhatsRaised.pledgeForAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_TIP_AMOUNT, rewardSelection); + keepWhatsRaised.pledgeForAReward( + TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_TIP_AMOUNT, rewardSelection + ); vm.stopPrank(); } - + function testSetFeeAndPledge() public { _setupReward(); - + vm.warp(LAUNCH_TIME); - + bytes32[] memory rewardSelection = new bytes32[](1); rewardSelection[0] = TEST_REWARD_NAME; - + // Fund admin with tokens since they will be the token source deal(address(testToken), users.platform2AdminAddress, TEST_PLEDGE_AMOUNT + TEST_TIP_AMOUNT); - + vm.startPrank(users.platform2AdminAddress); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT + TEST_TIP_AMOUNT); - + keepWhatsRaised.setFeeAndPledge( - TEST_PLEDGE_ID, - users.backer1Address, + TEST_PLEDGE_ID, + users.backer1Address, address(testToken), 0, // ignored for reward pledges - TEST_TIP_AMOUNT, - PAYMENT_GATEWAY_FEE, - rewardSelection, + TEST_TIP_AMOUNT, + PAYMENT_GATEWAY_FEE, + rewardSelection, true ); vm.stopPrank(); - + // Verify fee was set assertEq(keepWhatsRaised.getPaymentGatewayFee(TEST_PLEDGE_ID), PAYMENT_GATEWAY_FEE); - + // Verify pledge was made assertEq(keepWhatsRaised.getRaisedAmount(), TEST_PLEDGE_AMOUNT); assertEq(CampaignInfo(campaignAddress).balanceOf(users.backer1Address), 1); } - + /*////////////////////////////////////////////////////////////// WITHDRAWALS //////////////////////////////////////////////////////////////*/ - + function testWithdrawFullAmountAfterDeadline() public { // Setup pledges _setupPledges(); - + // Approve withdrawal vm.prank(users.platform2AdminAddress); keepWhatsRaised.approveWithdrawal(); - + address owner = CampaignInfo(campaignAddress).owner(); uint256 ownerBalanceBefore = testToken.balanceOf(owner); - + // Withdraw after deadline (as platform admin) vm.warp(DEADLINE + 1); vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(address(testToken), 0); - + uint256 ownerBalanceAfter = testToken.balanceOf(owner); - + // Verify (accounting for fees) assertTrue(ownerBalanceAfter > ownerBalanceBefore); assertEq(keepWhatsRaised.getAvailableRaisedAmount(), 0); } - + function testWithdrawPartialAmountBeforeDeadline() public { // Setup pledges _setupPledges(); - + // Approve withdrawal vm.prank(users.platform2AdminAddress); keepWhatsRaised.approveWithdrawal(); - + uint256 partialAmount = 500e18; uint256 availableBefore = keepWhatsRaised.getAvailableRaisedAmount(); - + // Withdraw partial amount before deadline (as platform admin) vm.warp(LAUNCH_TIME + 1 days); vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(address(testToken), partialAmount); - + uint256 availableAfter = keepWhatsRaised.getAvailableRaisedAmount(); - + // Verify - available is reduced by withdrawal plus fees assertTrue(availableAfter < availableBefore - partialAmount); } - + function testWithdrawRevertWhenNotApproved() public { _setupPledges(); - + vm.warp(DEADLINE + 1); vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedDisabled.selector); vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(address(testToken), 0); } - + function testWithdrawRevertWhenAmountExceedsAvailable() public { _setupPledges(); - + vm.prank(users.platform2AdminAddress); keepWhatsRaised.approveWithdrawal(); - + uint256 available = keepWhatsRaised.getAvailableRaisedAmount(); - + vm.warp(LAUNCH_TIME + 1 days); vm.expectRevert(); vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(address(testToken), available + 1e18); } - + function testWithdrawRevertWhenAlreadyWithdrawn() public { _setupPledges(); - + vm.prank(users.platform2AdminAddress); keepWhatsRaised.approveWithdrawal(); - + // First withdrawal vm.warp(DEADLINE + 1); vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(address(testToken), 0); - + // Second withdrawal attempt vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedAlreadyWithdrawn.selector); vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(address(testToken), 0); } - + function testWithdrawRevertWhenPaused() public { // Setup pledges and approve withdrawal first _setupPledges(); vm.prank(users.platform2AdminAddress); keepWhatsRaised.approveWithdrawal(); - + _pauseTreasury(); - - // Try to withdraw + + // Try to withdraw vm.warp(DEADLINE + 1); vm.expectRevert(); vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(address(testToken), 0); } - + function testWithdrawWithMinimumFeeExemption() public { // Calculate pledge amount needed to have available amount above exemption after fees // We need the available amount after all pledge fees to be > MINIMUM_WITHDRAWAL_FOR_FEE_EXEMPTION @@ -726,334 +739,349 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te // We need: pledge * 0.64 > 50,000e18 // Therefore: pledge > 78,125e18 uint256 largePledge = 80_000e18; - + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, 0); - + vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), largePledge); keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), largePledge, 0); vm.stopPrank(); - + uint256 availableAfterPledge = keepWhatsRaised.getAvailableRaisedAmount(); // Verify available amount is above exemption threshold - assertTrue(availableAfterPledge > MINIMUM_WITHDRAWAL_FOR_FEE_EXEMPTION, "Available amount should be above exemption threshold"); - + assertTrue( + availableAfterPledge > MINIMUM_WITHDRAWAL_FOR_FEE_EXEMPTION, + "Available amount should be above exemption threshold" + ); + // Approve and withdraw vm.prank(users.platform2AdminAddress); keepWhatsRaised.approveWithdrawal(); - + address owner = CampaignInfo(campaignAddress).owner(); uint256 ownerBalanceBefore = testToken.balanceOf(owner); - + vm.warp(DEADLINE + 1); vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(address(testToken), 0); - + uint256 ownerBalanceAfter = testToken.balanceOf(owner); uint256 received = ownerBalanceAfter - ownerBalanceBefore; - + // For final withdrawal above exemption threshold, no flat fee is applied // The owner should receive the full available amount assertEq(received, availableAfterPledge, "Should receive full available amount without flat fee"); } - + function testWithdrawWithColombianCreatorTax() public { // Configure with Colombian creator KeepWhatsRaised.FeeValues memory feeValues = _createFeeValues(); vm.prank(users.platform2AdminAddress); keepWhatsRaised.configureTreasury(CONFIG_COLOMBIAN, CAMPAIGN_DATA, FEE_KEYS, feeValues); - + // Make a pledge setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, PAYMENT_GATEWAY_FEE); - + vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward( + TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0 + ); vm.stopPrank(); - + // Approve withdrawal vm.prank(users.platform2AdminAddress); keepWhatsRaised.approveWithdrawal(); - + address owner = CampaignInfo(campaignAddress).owner(); uint256 ownerBalanceBefore = testToken.balanceOf(owner); uint256 availableBeforeWithdraw = keepWhatsRaised.getAvailableRaisedAmount(); - + // Withdraw after deadline vm.warp(DEADLINE + 1); vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(address(testToken), 0); - + uint256 ownerBalanceAfter = testToken.balanceOf(owner); uint256 received = ownerBalanceAfter - ownerBalanceBefore; - + // Calculate expected amount after Colombian tax uint256 flatFee = uint256(FLAT_FEE_VALUE); uint256 amountAfterFlatFee = availableBeforeWithdraw - flatFee; - + // Colombian tax: (availableBeforeWithdraw * 0.004) / 1.004 uint256 colombianTax = (availableBeforeWithdraw * 40) / 10040; uint256 expectedAmount = amountAfterFlatFee - colombianTax; - + assertApproxEqAbs(received, expectedAmount, 10, "Should receive amount minus flat fee and Colombian tax"); } - + /*////////////////////////////////////////////////////////////// REFUNDS //////////////////////////////////////////////////////////////*/ - + function testClaimRefundAfterDeadline() public { // Make pledge setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, PAYMENT_GATEWAY_FEE); - + vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward( + TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0 + ); uint256 tokenId = 1; // First token ID after pledge vm.stopPrank(); - + uint256 balanceBefore = testToken.balanceOf(users.backer1Address); - + // Claim refund within refund window vm.warp(DEADLINE + 1 days); - + // Approve treasury to burn NFT vm.prank(users.backer1Address); CampaignInfo(campaignAddress).approve(address(keepWhatsRaised), tokenId); - + vm.prank(users.backer1Address); keepWhatsRaised.claimRefund(tokenId); - + // Calculate expected refund (pledge minus all fees including protocol) uint256 platformFee = (TEST_PLEDGE_AMOUNT * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; uint256 vakiCommission = (TEST_PLEDGE_AMOUNT * uint256(VAKI_COMMISSION_VALUE)) / PERCENT_DIVIDER; uint256 protocolFee = (TEST_PLEDGE_AMOUNT * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; uint256 expectedRefund = TEST_PLEDGE_AMOUNT - PAYMENT_GATEWAY_FEE - platformFee - vakiCommission - protocolFee; - + // Verify refund amount is pledge minus fees assertEq(testToken.balanceOf(users.backer1Address), balanceBefore + expectedRefund); vm.expectRevert(); campaignInfo.ownerOf(tokenId); // Token should be burned } - + function testClaimRefundRevertWhenOutsideRefundWindow() public { // Make pledge setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, 0); - + vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward( + TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0 + ); uint256 tokenId = 1; // First token ID after pledge vm.stopPrank(); - + // Try to claim after refund window vm.warp(DEADLINE + REFUND_DELAY + 1); vm.expectRevert(); vm.prank(users.backer1Address); keepWhatsRaised.claimRefund(tokenId); } - + function testClaimRefundAfterCancellation() public { // Make pledge setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, PAYMENT_GATEWAY_FEE); - + vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward( + TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0 + ); uint256 tokenId = 1; // First token ID after pledge vm.stopPrank(); - + // Cancel campaign vm.prank(users.platform2AdminAddress); keepWhatsRaised.cancelTreasury(keccak256("cancelled")); - + uint256 balanceBefore = testToken.balanceOf(users.backer1Address); - + // Claim refund vm.warp(block.timestamp + 1); - + // Approve treasury to burn NFT vm.prank(users.backer1Address); CampaignInfo(campaignAddress).approve(address(keepWhatsRaised), tokenId); - + vm.prank(users.backer1Address); keepWhatsRaised.claimRefund(tokenId); - + // Calculate expected refund (pledge minus all fees) uint256 platformFee = (TEST_PLEDGE_AMOUNT * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; uint256 vakiCommission = (TEST_PLEDGE_AMOUNT * uint256(VAKI_COMMISSION_VALUE)) / PERCENT_DIVIDER; uint256 protocolFee = (TEST_PLEDGE_AMOUNT * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; uint256 expectedRefund = TEST_PLEDGE_AMOUNT - PAYMENT_GATEWAY_FEE - platformFee - vakiCommission - protocolFee; - + // Verify refund amount is pledge minus fees assertEq(testToken.balanceOf(users.backer1Address), balanceBefore + expectedRefund); } - + function testClaimRefundRevertWhenPaused() public { // Make pledge first setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, 0); - + vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward( + TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0 + ); uint256 tokenId = 0; vm.stopPrank(); - + _pauseTreasury(); - - // Try to claim refund + + // Try to claim refund vm.warp(DEADLINE + 1 days); vm.expectRevert(); vm.prank(users.backer1Address); keepWhatsRaised.claimRefund(tokenId); } - + function testClaimRefundRevertWhenInsufficientFunds() public { // Make pledge setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, 0); - + vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward( + TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0 + ); uint256 tokenId = 0; vm.stopPrank(); - + // Withdraw all funds vm.prank(users.platform2AdminAddress); keepWhatsRaised.approveWithdrawal(); vm.warp(DEADLINE + 1); vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(address(testToken), 0); - - // Try to claim refund + + // Try to claim refund vm.warp(DEADLINE + 1 days); vm.expectRevert(); vm.prank(users.backer1Address); keepWhatsRaised.claimRefund(tokenId); } - + /*////////////////////////////////////////////////////////////// TIPS AND FUNDS CLAIMING //////////////////////////////////////////////////////////////*/ - + function testClaimTipAfterDeadline() public { // Setup pledges with tips _setupPledges(); - + uint256 platformBalanceBefore = testToken.balanceOf(users.platform2AdminAddress); uint256 totalTips = TEST_TIP_AMOUNT * 2; - + // Claim tips after deadline vm.warp(DEADLINE + 1); vm.prank(users.platform2AdminAddress); keepWhatsRaised.claimTip(); - + // Verify assertEq(testToken.balanceOf(users.platform2AdminAddress), platformBalanceBefore + totalTips); } - + function testClaimTipRevertWhenBeforeDeadline() public { _setupPledges(); - + vm.warp(DEADLINE - 1); vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedNotClaimableAdmin.selector); vm.prank(users.platform2AdminAddress); keepWhatsRaised.claimTip(); } - + function testClaimTipRevertWhenAlreadyClaimed() public { _setupPledges(); - + vm.warp(DEADLINE + 1); vm.prank(users.platform2AdminAddress); keepWhatsRaised.claimTip(); - + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedAlreadyClaimed.selector); vm.prank(users.platform2AdminAddress); keepWhatsRaised.claimTip(); } - + function testClaimTipRevertWhenPaused() public { // Setup pledges with tips _setupPledges(); _pauseTreasury(); - + vm.warp(DEADLINE + 1); vm.expectRevert(); vm.prank(users.platform2AdminAddress); keepWhatsRaised.claimTip(); } - + function testClaimFundAfterWithdrawalDelay() public { // Setup pledges _setupPledges(); - + uint256 platformBalanceBefore = testToken.balanceOf(users.platform2AdminAddress); uint256 availableFunds = keepWhatsRaised.getAvailableRaisedAmount(); - + // Claim funds after withdrawal delay vm.warp(DEADLINE + WITHDRAWAL_DELAY + 1); vm.prank(users.platform2AdminAddress); keepWhatsRaised.claimFund(); - + // Verify assertEq(testToken.balanceOf(users.platform2AdminAddress), platformBalanceBefore + availableFunds); assertEq(keepWhatsRaised.getAvailableRaisedAmount(), 0); } - + function testClaimFundAfterCancellation() public { // Setup pledges _setupPledges(); - + uint256 platformBalanceBefore = testToken.balanceOf(users.platform2AdminAddress); uint256 availableFunds = keepWhatsRaised.getAvailableRaisedAmount(); - + // Cancel treasury vm.prank(users.platform2AdminAddress); keepWhatsRaised.cancelTreasury(keccak256("cancelled")); - + // Claim funds after refund delay from cancellation vm.warp(block.timestamp + REFUND_DELAY + 1); vm.prank(users.platform2AdminAddress); keepWhatsRaised.claimFund(); - + // Verify assertEq(testToken.balanceOf(users.platform2AdminAddress), platformBalanceBefore + availableFunds); assertEq(keepWhatsRaised.getAvailableRaisedAmount(), 0); } - + function testClaimFundRevertWhenBeforeWithdrawalDelay() public { _setupPledges(); - + vm.warp(DEADLINE + WITHDRAWAL_DELAY - 1); vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedNotClaimableAdmin.selector); vm.prank(users.platform2AdminAddress); keepWhatsRaised.claimFund(); } - + function testClaimFundRevertWhenAlreadyClaimed() public { _setupPledges(); - + vm.warp(DEADLINE + WITHDRAWAL_DELAY + 1); vm.prank(users.platform2AdminAddress); keepWhatsRaised.claimFund(); - + vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedAlreadyClaimed.selector); vm.prank(users.platform2AdminAddress); keepWhatsRaised.claimFund(); } - + function testClaimFundRevertWhenPaused() public { // Setup pledges - _setupPledges(); + _setupPledges(); _pauseTreasury(); vm.warp(DEADLINE + WITHDRAWAL_DELAY + 1); @@ -1061,34 +1089,34 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.prank(users.platform2AdminAddress); keepWhatsRaised.claimFund(); } - + /*////////////////////////////////////////////////////////////// FEE DISBURSEMENT //////////////////////////////////////////////////////////////*/ - + function testDisburseFees() public { // Setup pledges - protocol fees are collected during pledge _setupPledges(); - + // Approve and withdraw to generate withdrawal fees vm.prank(users.platform2AdminAddress); keepWhatsRaised.approveWithdrawal(); - + vm.warp(DEADLINE + 1); vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(address(testToken), 0); - + uint256 protocolBalanceBefore = testToken.balanceOf(users.protocolAdminAddress); uint256 platformBalanceBefore = testToken.balanceOf(users.platform2AdminAddress); - + // Disburse fees immediately keepWhatsRaised.disburseFees(); - + // Verify fees were distributed assertTrue(testToken.balanceOf(users.protocolAdminAddress) > protocolBalanceBefore); assertTrue(testToken.balanceOf(users.platform2AdminAddress) > platformBalanceBefore); } - + function testDisburseFeesRevertWhenPaused() public { // Setup pledges and withdraw to generate fees _setupPledges(); @@ -1097,81 +1125,90 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.warp(DEADLINE + 1); vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(address(testToken), 0); - + _pauseTreasury(); - + // Try to disburse fees - should revert vm.expectRevert(); keepWhatsRaised.disburseFees(); } - + /*////////////////////////////////////////////////////////////// CANCEL TREASURY //////////////////////////////////////////////////////////////*/ - + function testCancelTreasuryByPlatformAdmin() public { bytes32 message = keccak256("Platform cancellation"); vm.prank(users.platform2AdminAddress); keepWhatsRaised.cancelTreasury(message); - + // Verify campaign is cancelled vm.warp(LAUNCH_TIME); vm.expectRevert(); vm.prank(users.backer1Address); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward( + TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0 + ); } - + function testCancelTreasuryByCampaignOwner() public { bytes32 message = keccak256("Owner cancellation"); address campaignOwner = CampaignInfo(campaignAddress).owner(); - + vm.prank(campaignOwner); keepWhatsRaised.cancelTreasury(message); - + // Verify campaign is cancelled vm.warp(LAUNCH_TIME); vm.expectRevert(); vm.prank(users.backer1Address); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward( + TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0 + ); } - + function testCancelTreasuryRevertWhenUnauthorized() public { vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedUnAuthorized.selector); vm.prank(users.backer1Address); keepWhatsRaised.cancelTreasury(keccak256("unauthorized")); } - + /*////////////////////////////////////////////////////////////// EDGE CASES //////////////////////////////////////////////////////////////*/ - + function testMultiplePartialWithdrawals() public { _setupPledges(); - + vm.prank(users.platform2AdminAddress); keepWhatsRaised.approveWithdrawal(); - + uint256 available = keepWhatsRaised.getAvailableRaisedAmount(); - + // First withdrawal: small amount that will incur cumulative fee // Need to ensure available >= withdrawal + cumulativeFee uint256 firstWithdrawal = 200e18; // Reduced to ensure enough for fee - + // First withdrawal vm.warp(LAUNCH_TIME + 1 days); uint256 availableBefore1 = keepWhatsRaised.getAvailableRaisedAmount(); vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(address(testToken), firstWithdrawal); uint256 availableAfter1 = keepWhatsRaised.getAvailableRaisedAmount(); - + // Verify first withdrawal reduced available amount by withdrawal + fees uint256 expectedReduction1 = firstWithdrawal + uint256(CUMULATIVE_FLAT_FEE_VALUE); - assertApproxEqAbs(availableBefore1 - availableAfter1, expectedReduction1, 10, "First withdrawal should reduce by amount plus cumulative fee"); - + assertApproxEqAbs( + availableBefore1 - availableAfter1, + expectedReduction1, + 10, + "First withdrawal should reduce by amount plus cumulative fee" + ); + // Second withdrawal // Calculate safe amount based on remaining balance uint256 secondWithdrawal = 150e18; // Reduced to ensure enough for fee - + // Only do second withdrawal if we have enough funds if (availableAfter1 >= secondWithdrawal + uint256(CUMULATIVE_FLAT_FEE_VALUE)) { vm.warp(LAUNCH_TIME + 2 days); @@ -1179,184 +1216,201 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(address(testToken), secondWithdrawal); uint256 availableAfter2 = keepWhatsRaised.getAvailableRaisedAmount(); - + // Verify second withdrawal reduced available amount by withdrawal + fees uint256 expectedReduction2 = secondWithdrawal + uint256(CUMULATIVE_FLAT_FEE_VALUE); - assertApproxEqAbs(availableBefore2 - availableAfter2, expectedReduction2, 10, "Second withdrawal should reduce by amount plus cumulative fee"); + assertApproxEqAbs( + availableBefore2 - availableAfter2, + expectedReduction2, + 10, + "Second withdrawal should reduce by amount plus cumulative fee" + ); } - + // Verify remaining amount assertTrue(keepWhatsRaised.getAvailableRaisedAmount() > 0, "Should still have funds available"); } - + function testWithdrawalRevertWhenFeesExceedAmount() public { // Make a small pledge uint256 smallPledge = 300e18; // Small enough that fees might exceed available setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, 0); - + vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), smallPledge); keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), smallPledge, 0); vm.stopPrank(); - + vm.prank(users.platform2AdminAddress); keepWhatsRaised.approveWithdrawal(); - + // Try to withdraw partial amount that would cause available < withdrawal + fees vm.warp(LAUNCH_TIME + 1 days); uint256 available = keepWhatsRaised.getAvailableRaisedAmount(); - + // Try to withdraw an amount that with fees would exceed available uint256 withdrawAmount = available - 50e18; // Leave less than cumulative fee vm.expectRevert(); keepWhatsRaised.withdraw(address(testToken), withdrawAmount); } - + function testZeroTipPledge() public { setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, 0); - + vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward( + TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0 + ); vm.stopPrank(); - + assertEq(keepWhatsRaised.getRaisedAmount(), TEST_PLEDGE_AMOUNT); } - + function testFeeCalculationWithoutColombianTax() public { // Make a pledge (non-Colombian) setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), TEST_PLEDGE_ID, PAYMENT_GATEWAY_FEE); - + vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); - keepWhatsRaised.pledgeWithoutAReward(TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward( + TEST_PLEDGE_ID, users.backer1Address, address(testToken), TEST_PLEDGE_AMOUNT, 0 + ); vm.stopPrank(); - + uint256 available = keepWhatsRaised.getAvailableRaisedAmount(); uint256 platformFee = (TEST_PLEDGE_AMOUNT * uint256(PLATFORM_FEE_VALUE)) / PERCENT_DIVIDER; uint256 vakiCommission = (TEST_PLEDGE_AMOUNT * uint256(VAKI_COMMISSION_VALUE)) / PERCENT_DIVIDER; uint256 protocolFee = (TEST_PLEDGE_AMOUNT * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; uint256 totalFees = platformFee + vakiCommission + PAYMENT_GATEWAY_FEE + protocolFee; - + uint256 expectedAvailable = TEST_PLEDGE_AMOUNT - totalFees; - + assertEq(available, expectedAvailable); } - + function testGetRewardRevertWhenNotExists() public { vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedInvalidInput.selector); keepWhatsRaised.getReward(keccak256("nonexistent")); } - + function testWithdrawRevertWhenZeroAfterDeadline() public { // No pledges made vm.prank(users.platform2AdminAddress); keepWhatsRaised.approveWithdrawal(); - + vm.warp(DEADLINE + 1); vm.expectRevert(KeepWhatsRaised.KeepWhatsRaisedAlreadyWithdrawn.selector); vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(address(testToken), 0); } - + /*////////////////////////////////////////////////////////////// COMPREHENSIVE FEE TESTS //////////////////////////////////////////////////////////////*/ - + function testComplexFeeScenario() public { // Testing multiple pledges with different fee structures - + // Configure Colombian creator for complex fee testing KeepWhatsRaised.FeeValues memory feeValues = _createFeeValues(); vm.prank(users.platform2AdminAddress); keepWhatsRaised.configureTreasury(CONFIG_COLOMBIAN, CAMPAIGN_DATA, FEE_KEYS, feeValues); - + // Add rewards _setupReward(); - + // Pledge 1: With reward and tip - setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("pledge1"), PAYMENT_GATEWAY_FEE); + setPaymentGatewayFee( + users.platform2AdminAddress, address(keepWhatsRaised), keccak256("pledge1"), PAYMENT_GATEWAY_FEE + ); vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT + TEST_TIP_AMOUNT); bytes32[] memory rewardSelection = new bytes32[](1); rewardSelection[0] = TEST_REWARD_NAME; - keepWhatsRaised.pledgeForAReward(keccak256("pledge1"), users.backer1Address, address(testToken), TEST_TIP_AMOUNT, rewardSelection); + keepWhatsRaised.pledgeForAReward( + keccak256("pledge1"), users.backer1Address, address(testToken), TEST_TIP_AMOUNT, rewardSelection + ); vm.stopPrank(); - + // Pledge 2: Without reward, different gateway fee uint256 differentGatewayFee = 20e18; - setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("pledge2"), differentGatewayFee); + setPaymentGatewayFee( + users.platform2AdminAddress, address(keepWhatsRaised), keccak256("pledge2"), differentGatewayFee + ); vm.startPrank(users.backer2Address); testToken.approve(address(keepWhatsRaised), 2000e18); keepWhatsRaised.pledgeWithoutAReward(keccak256("pledge2"), users.backer2Address, address(testToken), 2000e18, 0); vm.stopPrank(); - + // Verify total raised and available amounts uint256 totalRaised = keepWhatsRaised.getRaisedAmount(); uint256 totalAvailable = keepWhatsRaised.getAvailableRaisedAmount(); - + assertEq(totalRaised, TEST_PLEDGE_AMOUNT + 2000e18); assertTrue(totalAvailable < totalRaised); // No colombian tax yet - + // Test partial withdrawal with Colombian tax applied vm.prank(users.platform2AdminAddress); keepWhatsRaised.approveWithdrawal(); - + uint256 partialWithdrawAmount = 1000e18; address owner = CampaignInfo(campaignAddress).owner(); uint256 ownerBalanceBefore = testToken.balanceOf(owner); - + vm.warp(LAUNCH_TIME + 1 days); vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(address(testToken), partialWithdrawAmount); - + uint256 ownerBalanceAfter = testToken.balanceOf(owner); uint256 netReceived = ownerBalanceAfter - ownerBalanceBefore; - + // Verify withdrawal amount equals requested (fees deducted from available) assertEq(netReceived, partialWithdrawAmount); } - + function testWithdrawalFeeStructure() public { // Testing different withdrawal scenarios and their fee implications - + // Small withdrawal (below exemption) before deadline uint256 smallAmount = 1000e18; setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("small"), 0); - + vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), smallAmount); - keepWhatsRaised.pledgeWithoutAReward(keccak256("small"), users.backer1Address, address(testToken), smallAmount, 0); + keepWhatsRaised.pledgeWithoutAReward( + keccak256("small"), users.backer1Address, address(testToken), smallAmount, 0 + ); vm.stopPrank(); - + vm.prank(users.platform2AdminAddress); keepWhatsRaised.approveWithdrawal(); - + address owner = CampaignInfo(campaignAddress).owner(); uint256 balanceBefore = testToken.balanceOf(owner); - + // Calculate available after pledge fees uint256 availableBeforeWithdraw = keepWhatsRaised.getAvailableRaisedAmount(); - + // Withdraw before deadline - should apply cumulative fee vm.warp(LAUNCH_TIME + 1 days); vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(address(testToken), availableBeforeWithdraw - uint256(CUMULATIVE_FLAT_FEE_VALUE) - 10); // Leave small buffer - + uint256 received = testToken.balanceOf(owner) - balanceBefore; assertTrue(received > 0, "Should receive something"); } - + /*////////////////////////////////////////////////////////////// FEE VALUE TESTS //////////////////////////////////////////////////////////////*/ - + function testGetFeeValue() public { // Test retrieval of stored fee values assertEq(keepWhatsRaised.getFeeValue(FLAT_FEE_KEY), uint256(FLAT_FEE_VALUE)); @@ -1364,26 +1418,26 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te assertEq(keepWhatsRaised.getFeeValue(PLATFORM_FEE_KEY), uint256(PLATFORM_FEE_VALUE)); assertEq(keepWhatsRaised.getFeeValue(VAKI_COMMISSION_KEY), uint256(VAKI_COMMISSION_VALUE)); } - + function testGetFeeValueForNonExistentKey() public { // Should return 0 for non-existent keys bytes32 nonExistentKey = keccak256("nonExistentFee"); assertEq(keepWhatsRaised.getFeeValue(nonExistentKey), 0); } - + /*////////////////////////////////////////////////////////////// HELPER FUNCTIONS //////////////////////////////////////////////////////////////*/ - + function _createTestReward(uint256 value, bool isRewardTier) internal pure returns (Reward memory) { bytes32[] memory itemIds = new bytes32[](1); uint256[] memory itemValues = new uint256[](1); uint256[] memory itemQuantities = new uint256[](1); - + itemIds[0] = keccak256("testItem"); itemValues[0] = value; itemQuantities[0] = 1; - + return Reward({ rewardValue: value, isRewardTier: isRewardTier, @@ -1392,40 +1446,48 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te itemQuantity: itemQuantities }); } - + function _setupReward() internal { bytes32[] memory rewardNames = new bytes32[](1); rewardNames[0] = TEST_REWARD_NAME; - + Reward[] memory rewards = new Reward[](1); rewards[0] = _createTestReward(TEST_PLEDGE_AMOUNT, true); - + vm.prank(users.creator1Address); keepWhatsRaised.addRewards(rewardNames, rewards); } - + function _setupPledges() internal { _setupReward(); - + // Set gateway fees for pledges - setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("pledge1"), PAYMENT_GATEWAY_FEE); - setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("pledge2"), PAYMENT_GATEWAY_FEE); - + setPaymentGatewayFee( + users.platform2AdminAddress, address(keepWhatsRaised), keccak256("pledge1"), PAYMENT_GATEWAY_FEE + ); + setPaymentGatewayFee( + users.platform2AdminAddress, address(keepWhatsRaised), keccak256("pledge2"), PAYMENT_GATEWAY_FEE + ); + // Make pledges from two backers vm.warp(LAUNCH_TIME); - + // Backer 1 pledge with reward vm.startPrank(users.backer1Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT + TEST_TIP_AMOUNT); bytes32[] memory rewardSelection = new bytes32[](1); rewardSelection[0] = TEST_REWARD_NAME; - keepWhatsRaised.pledgeForAReward(keccak256("pledge1"), users.backer1Address, address(testToken), TEST_TIP_AMOUNT, rewardSelection); + keepWhatsRaised.pledgeForAReward( + keccak256("pledge1"), users.backer1Address, address(testToken), TEST_TIP_AMOUNT, rewardSelection + ); vm.stopPrank(); - + // Backer 2 pledge without reward vm.startPrank(users.backer2Address); testToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT + TEST_TIP_AMOUNT); - keepWhatsRaised.pledgeWithoutAReward(keccak256("pledge2"), users.backer2Address, address(testToken), TEST_PLEDGE_AMOUNT, TEST_TIP_AMOUNT); + keepWhatsRaised.pledgeWithoutAReward( + keccak256("pledge2"), users.backer2Address, address(testToken), TEST_PLEDGE_AMOUNT, TEST_TIP_AMOUNT + ); vm.stopPrank(); } @@ -1435,7 +1497,7 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te vm.prank(users.platform2AdminAddress); keepWhatsRaised.pauseTreasury(message); } - + function _createFeeValues() internal pure returns (KeepWhatsRaised.FeeValues memory) { KeepWhatsRaised.FeeValues memory feeValues; feeValues.flatFeeValue = uint256(FLAT_FEE_VALUE); @@ -1452,37 +1514,29 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te function test_pledgeWithMultipleTokenTypes() public { _setupReward(); - + // Pledge with USDC uint256 usdcAmount = getTokenAmount(address(usdcToken), TEST_PLEDGE_AMOUNT); setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("usdc_pledge"), 0); - + vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); usdcToken.approve(address(keepWhatsRaised), usdcAmount); keepWhatsRaised.pledgeWithoutAReward( - keccak256("usdc_pledge"), - users.backer1Address, - address(usdcToken), - usdcAmount, - 0 + keccak256("usdc_pledge"), users.backer1Address, address(usdcToken), usdcAmount, 0 ); vm.stopPrank(); - + // Pledge with cUSD setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("cusd_pledge"), 0); - + vm.startPrank(users.backer2Address); cUSDToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); keepWhatsRaised.pledgeWithoutAReward( - keccak256("cusd_pledge"), - users.backer2Address, - address(cUSDToken), - TEST_PLEDGE_AMOUNT, - 0 + keccak256("cusd_pledge"), users.backer2Address, address(cUSDToken), TEST_PLEDGE_AMOUNT, 0 ); vm.stopPrank(); - + // Verify raised amount is normalized uint256 totalRaised = keepWhatsRaised.getRaisedAmount(); assertEq(totalRaised, TEST_PLEDGE_AMOUNT * 2, "Should normalize to same value"); @@ -1490,60 +1544,48 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te function test_withdrawMultipleTokensCorrectly() public { _setupReward(); - + // Use larger amounts to ensure enough remains after fees uint256 largeAmount = 100_000e18; // 100k base amount uint256 usdcAmount = getTokenAmount(address(usdcToken), largeAmount); uint256 cUSDAmount = largeAmount; - + // Pledge with USDC setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("usdc"), 0); - + vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); deal(address(usdcToken), users.backer1Address, usdcAmount); // Ensure enough tokens usdcToken.approve(address(keepWhatsRaised), usdcAmount); - keepWhatsRaised.pledgeWithoutAReward( - keccak256("usdc"), - users.backer1Address, - address(usdcToken), - usdcAmount, - 0 - ); + keepWhatsRaised.pledgeWithoutAReward(keccak256("usdc"), users.backer1Address, address(usdcToken), usdcAmount, 0); vm.stopPrank(); - + // Pledge with cUSD setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("cusd"), 0); - + vm.startPrank(users.backer2Address); deal(address(cUSDToken), users.backer2Address, cUSDAmount); // Ensure enough tokens cUSDToken.approve(address(keepWhatsRaised), cUSDAmount); - keepWhatsRaised.pledgeWithoutAReward( - keccak256("cusd"), - users.backer2Address, - address(cUSDToken), - cUSDAmount, - 0 - ); + keepWhatsRaised.pledgeWithoutAReward(keccak256("cusd"), users.backer2Address, address(cUSDToken), cUSDAmount, 0); vm.stopPrank(); - + // Approve withdrawal vm.prank(users.platform2AdminAddress); keepWhatsRaised.approveWithdrawal(); - + address owner = CampaignInfo(campaignAddress).owner(); uint256 ownerUSDCBefore = usdcToken.balanceOf(owner); uint256 ownerCUSDBefore = cUSDToken.balanceOf(owner); - + // Withdraw USDC vm.warp(DEADLINE + 1); vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(address(usdcToken), 0); - + // Withdraw cUSD vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(address(cUSDToken), 0); - + // Verify withdrawals assertTrue(usdcToken.balanceOf(owner) > ownerUSDCBefore, "Should receive USDC"); assertTrue(cUSDToken.balanceOf(owner) > ownerCUSDBefore, "Should receive cUSD"); @@ -1551,107 +1593,125 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te function test_disburseFeesForMultipleTokens() public { _setupReward(); - + // Make pledges with different tokens uint256 usdcAmount = getTokenAmount(address(usdcToken), PLEDGE_AMOUNT); uint256 usdtAmount = getTokenAmount(address(usdtToken), PLEDGE_AMOUNT); - + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("usdc"), 0); setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("usdt"), 0); setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("cusd"), 0); - + vm.warp(LAUNCH_TIME); - + // USDC pledge vm.startPrank(users.backer1Address); usdcToken.approve(address(keepWhatsRaised), usdcAmount); keepWhatsRaised.pledgeWithoutAReward(keccak256("usdc"), users.backer1Address, address(usdcToken), usdcAmount, 0); vm.stopPrank(); - + // USDT pledge vm.startPrank(users.backer2Address); usdtToken.approve(address(keepWhatsRaised), usdtAmount); keepWhatsRaised.pledgeWithoutAReward(keccak256("usdt"), users.backer2Address, address(usdtToken), usdtAmount, 0); vm.stopPrank(); - + // cUSD pledge vm.startPrank(users.backer1Address); cUSDToken.approve(address(keepWhatsRaised), PLEDGE_AMOUNT); - keepWhatsRaised.pledgeWithoutAReward(keccak256("cusd"), users.backer1Address, address(cUSDToken), PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward( + keccak256("cusd"), users.backer1Address, address(cUSDToken), PLEDGE_AMOUNT, 0 + ); vm.stopPrank(); - + // Approve and make partial withdrawal to generate fees vm.prank(users.platform2AdminAddress); keepWhatsRaised.approveWithdrawal(); - + vm.warp(DEADLINE + 1); vm.prank(users.platform2AdminAddress); keepWhatsRaised.withdraw(address(cUSDToken), 0); - + // Track balances before disbursement uint256 protocolUSDCBefore = usdcToken.balanceOf(users.protocolAdminAddress); uint256 protocolUSDTBefore = usdtToken.balanceOf(users.protocolAdminAddress); uint256 protocolCUSDBefore = cUSDToken.balanceOf(users.protocolAdminAddress); - + uint256 platformUSDCBefore = usdcToken.balanceOf(users.platform2AdminAddress); uint256 platformUSDTBefore = usdtToken.balanceOf(users.platform2AdminAddress); uint256 platformCUSDBefore = cUSDToken.balanceOf(users.platform2AdminAddress); - + // Disburse fees keepWhatsRaised.disburseFees(); - + // Verify fees were distributed for all tokens - assertTrue(usdcToken.balanceOf(users.protocolAdminAddress) > protocolUSDCBefore, "Should receive USDC protocol fees"); - assertTrue(usdtToken.balanceOf(users.protocolAdminAddress) > protocolUSDTBefore, "Should receive USDT protocol fees"); - assertTrue(cUSDToken.balanceOf(users.protocolAdminAddress) > protocolCUSDBefore, "Should receive cUSD protocol fees"); - - assertTrue(usdcToken.balanceOf(users.platform2AdminAddress) > platformUSDCBefore, "Should receive USDC platform fees"); - assertTrue(usdtToken.balanceOf(users.platform2AdminAddress) > platformUSDTBefore, "Should receive USDT platform fees"); - assertTrue(cUSDToken.balanceOf(users.platform2AdminAddress) > platformCUSDBefore, "Should receive cUSD platform fees"); + assertTrue( + usdcToken.balanceOf(users.protocolAdminAddress) > protocolUSDCBefore, "Should receive USDC protocol fees" + ); + assertTrue( + usdtToken.balanceOf(users.protocolAdminAddress) > protocolUSDTBefore, "Should receive USDT protocol fees" + ); + assertTrue( + cUSDToken.balanceOf(users.protocolAdminAddress) > protocolCUSDBefore, "Should receive cUSD protocol fees" + ); + + assertTrue( + usdcToken.balanceOf(users.platform2AdminAddress) > platformUSDCBefore, "Should receive USDC platform fees" + ); + assertTrue( + usdtToken.balanceOf(users.platform2AdminAddress) > platformUSDTBefore, "Should receive USDT platform fees" + ); + assertTrue( + cUSDToken.balanceOf(users.platform2AdminAddress) > platformCUSDBefore, "Should receive cUSD platform fees" + ); } function test_refundReturnsCorrectToken() public { _setupReward(); - + // Backer1 pledges with USDC uint256 usdcAmount = getTokenAmount(address(usdcToken), TEST_PLEDGE_AMOUNT); setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("usdc_pledge"), 0); - + vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); usdcToken.approve(address(keepWhatsRaised), usdcAmount); - keepWhatsRaised.pledgeWithoutAReward(keccak256("usdc_pledge"), users.backer1Address, address(usdcToken), usdcAmount, 0); + keepWhatsRaised.pledgeWithoutAReward( + keccak256("usdc_pledge"), users.backer1Address, address(usdcToken), usdcAmount, 0 + ); uint256 usdcTokenId = 1; // First pledge vm.stopPrank(); - + // Backer2 pledges with cUSD setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("cusd_pledge"), 0); - + vm.startPrank(users.backer2Address); cUSDToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT); - keepWhatsRaised.pledgeWithoutAReward(keccak256("cusd_pledge"), users.backer2Address, address(cUSDToken), TEST_PLEDGE_AMOUNT, 0); + keepWhatsRaised.pledgeWithoutAReward( + keccak256("cusd_pledge"), users.backer2Address, address(cUSDToken), TEST_PLEDGE_AMOUNT, 0 + ); uint256 cUSDTokenId = 2; // Second pledge vm.stopPrank(); - + uint256 backer1USDCBefore = usdcToken.balanceOf(users.backer1Address); uint256 backer2CUSDBefore = cUSDToken.balanceOf(users.backer2Address); - + // Claim refunds after deadline vm.warp(DEADLINE + 1); - + // Approve treasury to burn NFTs vm.prank(users.backer1Address); CampaignInfo(campaignAddress).approve(address(keepWhatsRaised), usdcTokenId); - + vm.prank(users.backer1Address); keepWhatsRaised.claimRefund(usdcTokenId); - + vm.prank(users.backer2Address); CampaignInfo(campaignAddress).approve(address(keepWhatsRaised), cUSDTokenId); - + vm.prank(users.backer2Address); keepWhatsRaised.claimRefund(cUSDTokenId); - + // Verify correct tokens were refunded (should get something back even after fees) assertTrue(usdcToken.balanceOf(users.backer1Address) > backer1USDCBefore, "Should refund USDC"); assertTrue(cUSDToken.balanceOf(users.backer2Address) > backer2CUSDBefore, "Should refund cUSD"); @@ -1659,36 +1719,40 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te function test_claimTipWithMultipleTokens() public { _setupReward(); - + uint256 tipAmountUSDC = getTokenAmount(address(usdcToken), TIP_AMOUNT); uint256 tipAmountCUSD = TIP_AMOUNT; - + // Pledge with USDC + tip uint256 usdcPledge = getTokenAmount(address(usdcToken), TEST_PLEDGE_AMOUNT); setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("usdc"), 0); - + vm.warp(LAUNCH_TIME); vm.startPrank(users.backer1Address); usdcToken.approve(address(keepWhatsRaised), usdcPledge + tipAmountUSDC); - keepWhatsRaised.pledgeWithoutAReward(keccak256("usdc"), users.backer1Address, address(usdcToken), usdcPledge, tipAmountUSDC); + keepWhatsRaised.pledgeWithoutAReward( + keccak256("usdc"), users.backer1Address, address(usdcToken), usdcPledge, tipAmountUSDC + ); vm.stopPrank(); - + // Pledge with cUSD + tip setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("cusd"), 0); - + vm.startPrank(users.backer2Address); cUSDToken.approve(address(keepWhatsRaised), TEST_PLEDGE_AMOUNT + tipAmountCUSD); - keepWhatsRaised.pledgeWithoutAReward(keccak256("cusd"), users.backer2Address, address(cUSDToken), TEST_PLEDGE_AMOUNT, tipAmountCUSD); + keepWhatsRaised.pledgeWithoutAReward( + keccak256("cusd"), users.backer2Address, address(cUSDToken), TEST_PLEDGE_AMOUNT, tipAmountCUSD + ); vm.stopPrank(); - + uint256 platformUSDCBefore = usdcToken.balanceOf(users.platform2AdminAddress); uint256 platformCUSDBefore = cUSDToken.balanceOf(users.platform2AdminAddress); - + // Claim tips vm.warp(DEADLINE + 1); vm.prank(users.platform2AdminAddress); keepWhatsRaised.claimTip(); - + // Verify tips in both tokens assertEq( usdcToken.balanceOf(users.platform2AdminAddress) - platformUSDCBefore, @@ -1704,43 +1768,43 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te function test_mixedTokenPledgesWithDecimalNormalization() public { _setupReward(); - + // Make three pledges with same normalized value but different decimals uint256 baseAmount = 1000e18; uint256 usdcAmount = baseAmount / 1e12; // 6 decimals uint256 usdtAmount = baseAmount / 1e12; // 6 decimals - uint256 cUSDAmount = baseAmount; // 18 decimals - + uint256 cUSDAmount = baseAmount; // 18 decimals + setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("p1"), 0); setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("p2"), 0); setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("p3"), 0); - + vm.warp(LAUNCH_TIME); - + // USDC pledge vm.startPrank(users.backer1Address); usdcToken.approve(address(keepWhatsRaised), usdcAmount); keepWhatsRaised.pledgeWithoutAReward(keccak256("p1"), users.backer1Address, address(usdcToken), usdcAmount, 0); vm.stopPrank(); - + uint256 raisedAfterUSDC = keepWhatsRaised.getRaisedAmount(); assertEq(raisedAfterUSDC, baseAmount, "USDC should normalize to base amount"); - + // USDT pledge vm.startPrank(users.backer2Address); usdtToken.approve(address(keepWhatsRaised), usdtAmount); keepWhatsRaised.pledgeWithoutAReward(keccak256("p2"), users.backer2Address, address(usdtToken), usdtAmount, 0); vm.stopPrank(); - + uint256 raisedAfterUSDT = keepWhatsRaised.getRaisedAmount(); assertEq(raisedAfterUSDT, baseAmount * 2, "USDT should normalize to base amount"); - + // cUSD pledge vm.startPrank(users.backer1Address); cUSDToken.approve(address(keepWhatsRaised), cUSDAmount); keepWhatsRaised.pledgeWithoutAReward(keccak256("p3"), users.backer1Address, address(cUSDToken), cUSDAmount, 0); vm.stopPrank(); - + uint256 finalRaised = keepWhatsRaised.getRaisedAmount(); assertEq(finalRaised, baseAmount * 3, "All pledges should contribute equally after normalization"); } @@ -1750,45 +1814,58 @@ contract KeepWhatsRaised_UnitTest is Test, KeepWhatsRaised_Integration_Shared_Te uint256 baseAmount = 1000e18; // 1000 tokens in 18 decimals uint256 usdtAmount = baseAmount / 1e12; // 1000 USDT (6 decimals) uint256 usdcAmount = baseAmount / 1e12; // 1000 USDC (6 decimals) - + // Set payment gateway fee (stored in 18 decimals) uint256 gatewayFee18Decimals = 40e18; // 40 tokens in 18 decimals - setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("usdt_pledge"), gatewayFee18Decimals); - setPaymentGatewayFee(users.platform2AdminAddress, address(keepWhatsRaised), keccak256("usdc_pledge"), gatewayFee18Decimals); - + setPaymentGatewayFee( + users.platform2AdminAddress, address(keepWhatsRaised), keccak256("usdt_pledge"), gatewayFee18Decimals + ); + setPaymentGatewayFee( + users.platform2AdminAddress, address(keepWhatsRaised), keccak256("usdc_pledge"), gatewayFee18Decimals + ); + vm.warp(LAUNCH_TIME); - + // USDT pledge vm.startPrank(users.backer1Address); usdtToken.approve(address(keepWhatsRaised), usdtAmount); - keepWhatsRaised.pledgeWithoutAReward(keccak256("usdt_pledge"), users.backer1Address, address(usdtToken), usdtAmount, 0); + keepWhatsRaised.pledgeWithoutAReward( + keccak256("usdt_pledge"), users.backer1Address, address(usdtToken), usdtAmount, 0 + ); vm.stopPrank(); - - // USDC pledge + + // USDC pledge vm.startPrank(users.backer2Address); usdcToken.approve(address(keepWhatsRaised), usdcAmount); - keepWhatsRaised.pledgeWithoutAReward(keccak256("usdc_pledge"), users.backer2Address, address(usdcToken), usdcAmount, 0); + keepWhatsRaised.pledgeWithoutAReward( + keccak256("usdc_pledge"), users.backer2Address, address(usdcToken), usdcAmount, 0 + ); vm.stopPrank(); - + // Verify that both pledges contribute equally to raised amount (normalized) uint256 raisedAmount = keepWhatsRaised.getRaisedAmount(); - assertEq(raisedAmount, baseAmount * 2, "Both 6-decimal token pledges should normalize to same 18-decimal amount"); - + assertEq( + raisedAmount, baseAmount * 2, "Both 6-decimal token pledges should normalize to same 18-decimal amount" + ); + // Verify that the payment gateway fees were properly denormalized // For 6-decimal tokens, 40e18 should become 40e6 uint256 expectedGatewayFee6Decimals = 40e6; - + // Check that fees were calculated correctly by checking available amount uint256 availableAmount = keepWhatsRaised.getAvailableRaisedAmount(); - + // Calculate expected available amount after fees uint256 platformFee = (baseAmount * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; uint256 vakiCommission = (baseAmount * uint256(VAKI_COMMISSION_VALUE)) / PERCENT_DIVIDER; uint256 protocolFee = (baseAmount * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; uint256 gatewayFeeNormalized = expectedGatewayFee6Decimals * 1e12; // Convert 6-decimal fee to 18-decimal for comparison - - uint256 expectedAvailable = (baseAmount * 2) - (platformFee * 2) - (vakiCommission * 2) - (protocolFee * 2) - (gatewayFeeNormalized * 2); - - assertEq(availableAmount, expectedAvailable, "Available amount should account for properly denormalized gateway fees"); + + uint256 expectedAvailable = + (baseAmount * 2) - (platformFee * 2) - (vakiCommission * 2) - (protocolFee * 2) - (gatewayFeeNormalized * 2); + + assertEq( + availableAmount, expectedAvailable, "Available amount should account for properly denormalized gateway fees" + ); } -} \ No newline at end of file +} diff --git a/test/foundry/unit/PaymentTreasury.t.sol b/test/foundry/unit/PaymentTreasury.t.sol index 70c30766..a07907c2 100644 --- a/test/foundry/unit/PaymentTreasury.t.sol +++ b/test/foundry/unit/PaymentTreasury.t.sol @@ -9,7 +9,6 @@ import {CampaignInfo} from "src/CampaignInfo.sol"; import {TestToken} from "../../mocks/TestToken.sol"; contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Test { - // Helper function to create payment tokens array with same token for all payments function _createPaymentTokensArray(uint256 length, address token) internal pure returns (address[] memory) { address[] memory paymentTokens = new address[](length); @@ -18,7 +17,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te } return paymentTokens; } - + function setUp() public virtual override { super.setUp(); // Fund test addresses @@ -32,20 +31,20 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.label(users.backer2Address, "Backer2"); vm.label(address(paymentTreasury), "PaymentTreasury"); } - + /*////////////////////////////////////////////////////////////// INITIALIZATION //////////////////////////////////////////////////////////////*/ - + function testInitialize() public { // Create a new campaign for this test bytes32 newIdentifierHash = keccak256(abi.encodePacked("newPaymentCampaign")); bytes32[] memory selectedPlatformHash = new bytes32[](1); selectedPlatformHash[0] = PLATFORM_1_HASH; - + bytes32[] memory platformDataKey = new bytes32[](0); bytes32[] memory platformDataValue = new bytes32[](0); - + vm.prank(users.creator1Address); campaignInfoFactory.createCampaign( users.creator1Address, @@ -60,28 +59,24 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te "ipfs://QmExampleContractURI" ); address newCampaignAddress = campaignInfoFactory.identifierToCampaignInfo(newIdentifierHash); - + // Deploy a new treasury vm.prank(users.platform1AdminAddress); - address newTreasury = treasuryFactory.deploy( - PLATFORM_1_HASH, - newCampaignAddress, - 2 - ); + address newTreasury = treasuryFactory.deploy(PLATFORM_1_HASH, newCampaignAddress, 2); PaymentTreasury newContract = PaymentTreasury(newTreasury); CampaignInfo newCampaignInfo = CampaignInfo(newCampaignAddress); - + // NFT name and symbol are now on CampaignInfo, not treasury assertEq(newCampaignInfo.name(), "Campaign Pledge NFT"); assertEq(newCampaignInfo.symbol(), "PLEDGE"); assertEq(newContract.getplatformHash(), PLATFORM_1_HASH); assertEq(newContract.getplatformFeePercent(), PLATFORM_FEE_PERCENT); } - + /*////////////////////////////////////////////////////////////// PAYMENT CREATION //////////////////////////////////////////////////////////////*/ - + function testCreatePayment() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.prank(users.platform1AdminAddress); @@ -100,7 +95,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te assertEq(paymentTreasury.getRaisedAmount(), 0); assertEq(paymentTreasury.getAvailableRaisedAmount(), 0); } - + function testCreatePaymentRevertWhenNotPlatformAdmin() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.expectRevert(); @@ -117,7 +112,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te new ICampaignPaymentTreasury.ExternalFees[](0) ); } - + function testCreatePaymentRevertWhenZeroBuyerId() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.expectRevert(); @@ -134,7 +129,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te new ICampaignPaymentTreasury.ExternalFees[](0) ); } - + function testCreatePaymentRevertWhenZeroAmount() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.expectRevert(); @@ -151,7 +146,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te new ICampaignPaymentTreasury.ExternalFees[](0) ); } - + function testCreatePaymentRevertWhenExpired() public { vm.expectRevert(); ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); @@ -167,7 +162,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te new ICampaignPaymentTreasury.ExternalFees[](0) ); } - + function testCreatePaymentRevertWhenZeroPaymentId() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.expectRevert(); @@ -184,7 +179,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te new ICampaignPaymentTreasury.ExternalFees[](0) ); } - + function testCreatePaymentRevertWhenZeroItemId() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.expectRevert(); @@ -201,7 +196,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te new ICampaignPaymentTreasury.ExternalFees[](0) ); } - + function testCreatePaymentRevertWhenZeroTokenAddress() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.expectRevert(); @@ -218,12 +213,12 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te new ICampaignPaymentTreasury.ExternalFees[](0) ); } - + function testCreatePaymentRevertWhenTokenNotAccepted() public { // Create unaccepted token TestToken unacceptedToken = new TestToken("Unaccepted", "UNACC", 18); uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; - + vm.expectRevert(); ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); @@ -238,7 +233,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te new ICampaignPaymentTreasury.ExternalFees[](0) ); } - + function testCreatePaymentRevertWhenPaymentExists() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.startPrank(users.platform1AdminAddress); @@ -267,7 +262,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te ); vm.stopPrank(); } - + function testCreatePaymentRevertWhenPaused() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; // Pause the treasury @@ -289,14 +284,14 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te new ICampaignPaymentTreasury.ExternalFees[](0) ); } - + function testCreatePaymentRevertWhenCampaignPaused() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; // Pause the campaign CampaignInfo actualCampaignInfo = CampaignInfo(campaignAddress); vm.prank(users.protocolAdminAddress); actualCampaignInfo._pauseCampaign(keccak256("Pause")); - + vm.expectRevert(); vm.prank(users.platform1AdminAddress); ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); @@ -311,26 +306,35 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te new ICampaignPaymentTreasury.ExternalFees[](0) ); } - + /*////////////////////////////////////////////////////////////// CRYPTO PAYMENT PROCESSING //////////////////////////////////////////////////////////////*/ - + function testProcessCryptoPayment() public { uint256 amount = 1500e18; deal(address(testToken), users.backer1Address, amount); - + vm.prank(users.backer1Address); testToken.approve(treasuryAddress, amount); - + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); - processCryptoPayment(users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), amount, emptyLineItems, new ICampaignPaymentTreasury.ExternalFees[](0)); - + processCryptoPayment( + users.backer1Address, + PAYMENT_ID_1, + ITEM_ID_1, + users.backer1Address, + address(testToken), + amount, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + assertEq(paymentTreasury.getRaisedAmount(), amount); assertEq(paymentTreasury.getAvailableRaisedAmount(), amount); assertEq(testToken.balanceOf(treasuryAddress), amount); } - + function testProcessCryptoPaymentStoresExternalFees() public { uint256 amount = 1000e18; deal(address(testToken), users.backer1Address, amount); @@ -368,27 +372,63 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testProcessCryptoPaymentRevertWhenZeroBuyerAddress() public { vm.expectRevert(); ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); - processCryptoPayment(users.platform1AdminAddress, PAYMENT_ID_1, ITEM_ID_1, address(0), address(testToken), 1000e18, emptyLineItems, new ICampaignPaymentTreasury.ExternalFees[](0)); + processCryptoPayment( + users.platform1AdminAddress, + PAYMENT_ID_1, + ITEM_ID_1, + address(0), + address(testToken), + 1000e18, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); } - + function testProcessCryptoPaymentRevertWhenZeroAmount() public { vm.expectRevert(); ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); - processCryptoPayment(users.platform1AdminAddress, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), 0, emptyLineItems, new ICampaignPaymentTreasury.ExternalFees[](0)); + processCryptoPayment( + users.platform1AdminAddress, + PAYMENT_ID_1, + ITEM_ID_1, + users.backer1Address, + address(testToken), + 0, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); } - + function testProcessCryptoPaymentRevertWhenPaymentExists() public { uint256 amount = 1500e18; deal(address(testToken), users.backer1Address, amount * 2); - + vm.prank(users.backer1Address); testToken.approve(treasuryAddress, amount * 2); - + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); - processCryptoPayment(users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), amount, emptyLineItems, new ICampaignPaymentTreasury.ExternalFees[](0)); - + processCryptoPayment( + users.backer1Address, + PAYMENT_ID_1, + ITEM_ID_1, + users.backer1Address, + address(testToken), + amount, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + vm.expectRevert(); - processCryptoPayment(users.backer1Address, PAYMENT_ID_1, ITEM_ID_1, users.backer1Address, address(testToken), amount, emptyLineItems, new ICampaignPaymentTreasury.ExternalFees[](0)); + processCryptoPayment( + users.backer1Address, + PAYMENT_ID_1, + ITEM_ID_1, + users.backer1Address, + address(testToken), + amount, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); } function testClaimExpiredFundsRevertsBeforeWindow() public { @@ -403,10 +443,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.platform1AdminAddress); vm.expectRevert( - abi.encodeWithSelector( - BasePaymentTreasury.PaymentTreasuryClaimWindowNotReached.selector, - claimableAt - ) + abi.encodeWithSelector(BasePaymentTreasury.PaymentTreasuryClaimWindowNotReached.selector, claimableAt) ); paymentTreasury.claimExpiredFunds(); } @@ -419,13 +456,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te bytes32 refundableTypeId = keccak256("refundable_non_goal_type"); vm.prank(users.platform1AdminAddress); globalParams.setPlatformLineItemType( - PLATFORM_1_HASH, - refundableTypeId, - "Refundable Non Goal", - false, - false, - true, - false + PLATFORM_1_HASH, refundableTypeId, "Refundable Non Goal", false, false, true, false ); uint256 lineItemAmount = 250e18; @@ -481,16 +512,14 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.warp(claimableAt + 1); vm.prank(users.platform1AdminAddress); - vm.expectRevert( - abi.encodeWithSelector(BasePaymentTreasury.PaymentTreasuryNoFundsToClaim.selector) - ); + vm.expectRevert(abi.encodeWithSelector(BasePaymentTreasury.PaymentTreasuryNoFundsToClaim.selector)); paymentTreasury.claimExpiredFunds(); } - + /*////////////////////////////////////////////////////////////// PAYMENT CANCELLATION //////////////////////////////////////////////////////////////*/ - + function testCancelPayment() public { // Create payment first uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; @@ -512,23 +541,23 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te // Payment should be deleted assertEq(paymentTreasury.getRaisedAmount(), 0); } - + function testCancelPaymentRevertWhenNotExists() public { vm.expectRevert(); vm.prank(users.platform1AdminAddress); paymentTreasury.cancelPayment(PAYMENT_ID_1); } - + function testCancelPaymentRevertWhenAlreadyConfirmed() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter - + vm.expectRevert(); vm.prank(users.platform1AdminAddress); paymentTreasury.cancelPayment(PAYMENT_ID_1); } - + function testCancelPaymentRevertWhenExpired() public { uint256 expiration = block.timestamp + 1 hours; vm.prank(users.platform1AdminAddress); @@ -545,137 +574,137 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te ); // Warp past expiration vm.warp(expiration + 1); - + vm.expectRevert(); vm.prank(users.platform1AdminAddress); paymentTreasury.cancelPayment(PAYMENT_ID_1); } - + function testCancelPaymentRevertWhenCryptoPayment() public { uint256 amount = 1500e18; _createAndProcessCryptoPayment(PAYMENT_ID_1, ITEM_ID_1, amount, users.backer1Address); - + vm.expectRevert(); vm.prank(users.platform1AdminAddress); paymentTreasury.cancelPayment(PAYMENT_ID_1); } - + /*////////////////////////////////////////////////////////////// PAYMENT CONFIRMATION //////////////////////////////////////////////////////////////*/ - + function testConfirmPayment() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter - + assertEq(paymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1); assertEq(paymentTreasury.getAvailableRaisedAmount(), PAYMENT_AMOUNT_1); } - + function testConfirmPaymentBatch() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); _createAndFundPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, PAYMENT_AMOUNT_2, users.backer2Address); _createAndFundPayment(PAYMENT_ID_3, BUYER_ID_1, ITEM_ID_1, 500e18, users.backer1Address); - + bytes32[] memory paymentIds = new bytes32[](3); paymentIds[0] = PAYMENT_ID_1; paymentIds[1] = PAYMENT_ID_2; paymentIds[2] = PAYMENT_ID_3; - + vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPaymentBatch(paymentIds, _createZeroAddressArray(paymentIds.length)); // Removed token array - + uint256 totalAmount = PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2 + 500e18; assertEq(paymentTreasury.getRaisedAmount(), totalAmount); assertEq(paymentTreasury.getAvailableRaisedAmount(), totalAmount); } - + function testConfirmPaymentRevertWhenNotExists() public { vm.expectRevert(); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter } - + function testConfirmPaymentRevertWhenAlreadyConfirmed() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.startPrank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter - + vm.expectRevert(); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter vm.stopPrank(); } - + function testConfirmPaymentRevertWhenCryptoPayment() public { uint256 amount = 1500e18; _createAndProcessCryptoPayment(PAYMENT_ID_1, ITEM_ID_1, amount, users.backer1Address); - + vm.expectRevert(); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter } - + /*////////////////////////////////////////////////////////////// REFUNDS //////////////////////////////////////////////////////////////*/ - + function testClaimRefund() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter - + uint256 balanceBefore = testToken.balanceOf(users.backer1Address); - + vm.prank(users.platform1AdminAddress); paymentTreasury.claimRefund(PAYMENT_ID_1, users.backer1Address); - + uint256 balanceAfter = testToken.balanceOf(users.backer1Address); - + assertEq(balanceAfter - balanceBefore, PAYMENT_AMOUNT_1); assertEq(paymentTreasury.getRaisedAmount(), 0); assertEq(paymentTreasury.getAvailableRaisedAmount(), 0); } - + function testClaimRefundBuyerInitiated() public { uint256 amount = 1500e18; _createAndProcessCryptoPayment(PAYMENT_ID_1, ITEM_ID_1, amount, users.backer1Address); - + uint256 balanceBefore = testToken.balanceOf(users.backer1Address); - + // Approve treasury to burn NFT vm.prank(users.backer1Address); CampaignInfo(campaignAddress).approve(address(paymentTreasury), 1); - + vm.prank(users.backer1Address); paymentTreasury.claimRefund(PAYMENT_ID_1); - + uint256 balanceAfter = testToken.balanceOf(users.backer1Address); - + assertEq(balanceAfter - balanceBefore, amount); assertEq(paymentTreasury.getRaisedAmount(), 0); assertEq(paymentTreasury.getAvailableRaisedAmount(), 0); } - + function testClaimRefundByPlatformAdminForCryptoPayment() public { uint256 amount = 1500e18; _createAndProcessCryptoPayment(PAYMENT_ID_1, ITEM_ID_1, amount, users.backer1Address); - + uint256 balanceBefore = testToken.balanceOf(users.backer1Address); - + // Approve treasury to burn NFT vm.prank(users.backer1Address); CampaignInfo(campaignAddress).approve(address(paymentTreasury), 1); - + vm.prank(users.platform1AdminAddress); paymentTreasury.claimRefund(PAYMENT_ID_1); - + uint256 balanceAfter = testToken.balanceOf(users.backer1Address); - + assertEq(balanceAfter - balanceBefore, amount); assertEq(paymentTreasury.getRaisedAmount(), 0); } - + function testClaimRefundRevertWhenNotConfirmed() public { uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.prank(users.platform1AdminAddress); @@ -694,152 +723,165 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.platform1AdminAddress); paymentTreasury.claimRefund(PAYMENT_ID_1, users.backer1Address); } - + function testClaimRefundRevertWhenNotExists() public { vm.expectRevert(); vm.prank(users.platform1AdminAddress); paymentTreasury.claimRefund(PAYMENT_ID_1, users.backer1Address); } - + function testClaimRefundRevertWhenPaused() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter - + // Pause treasury vm.prank(users.platform1AdminAddress); paymentTreasury.pauseTreasury(keccak256("Pause")); - + vm.expectRevert(); vm.prank(users.platform1AdminAddress); paymentTreasury.claimRefund(PAYMENT_ID_1, users.backer1Address); } - + function testClaimRefundRevertWhenUnauthorizedForCryptoPayment() public { uint256 amount = 1500e18; _createAndProcessCryptoPayment(PAYMENT_ID_1, ITEM_ID_1, amount, users.backer1Address); - + vm.expectRevert(); vm.prank(users.backer2Address); // Different buyer paymentTreasury.claimRefund(PAYMENT_ID_1); } - + /*////////////////////////////////////////////////////////////// FEE DISBURSEMENT //////////////////////////////////////////////////////////////*/ - + function testDisburseFees() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter - + // Withdraw first to calculate fees + address owner = CampaignInfo(campaignAddress).owner(); + vm.prank(owner); paymentTreasury.withdraw(); - + uint256 protocolBalanceBefore = testToken.balanceOf(users.protocolAdminAddress); uint256 platformBalanceBefore = testToken.balanceOf(users.platform1AdminAddress); - + paymentTreasury.disburseFees(); - + uint256 protocolBalanceAfter = testToken.balanceOf(users.protocolAdminAddress); uint256 platformBalanceAfter = testToken.balanceOf(users.platform1AdminAddress); assertTrue(protocolBalanceAfter > protocolBalanceBefore); assertTrue(platformBalanceAfter > platformBalanceBefore); } - + function testDisburseFeesMultipleTimes() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); _createAndFundPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, PAYMENT_AMOUNT_2, users.backer2Address); - + vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter - + // First withdrawal and disbursement + address owner = CampaignInfo(campaignAddress).owner(); + vm.prank(owner); paymentTreasury.withdraw(); paymentTreasury.disburseFees(); - + vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_2, address(0)); // Removed token parameter - + // Second withdrawal and disbursement + vm.prank(owner); paymentTreasury.withdraw(); paymentTreasury.disburseFees(); } - + function testDisburseFeesRevertWhenPaused() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter - + + address owner = CampaignInfo(campaignAddress).owner(); + vm.prank(owner); paymentTreasury.withdraw(); - + // Pause treasury vm.prank(users.platform1AdminAddress); paymentTreasury.pauseTreasury(keccak256("Pause")); - + vm.expectRevert(); paymentTreasury.disburseFees(); } - + /*////////////////////////////////////////////////////////////// WITHDRAWALS //////////////////////////////////////////////////////////////*/ - + function testWithdraw() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter - + address owner = CampaignInfo(campaignAddress).owner(); uint256 ownerBalanceBefore = testToken.balanceOf(owner); - + + vm.prank(owner); paymentTreasury.withdraw(); - + uint256 ownerBalanceAfter = testToken.balanceOf(owner); - + uint256 expectedProtocolFee = (PAYMENT_AMOUNT_1 * PROTOCOL_FEE_PERCENT) / PERCENT_DIVIDER; uint256 expectedPlatformFee = (PAYMENT_AMOUNT_1 * PLATFORM_FEE_PERCENT) / PERCENT_DIVIDER; uint256 expectedWithdrawal = PAYMENT_AMOUNT_1 - expectedProtocolFee - expectedPlatformFee; - + assertEq(ownerBalanceAfter - ownerBalanceBefore, expectedWithdrawal); assertEq(paymentTreasury.getAvailableRaisedAmount(), 0); } - + function testWithdrawRevertWhenAlreadyWithdrawn() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter - + + address owner = CampaignInfo(campaignAddress).owner(); + vm.prank(owner); paymentTreasury.withdraw(); paymentTreasury.disburseFees(); - + vm.expectRevert(); + vm.prank(owner); paymentTreasury.withdraw(); } - + function testWithdrawRevertWhenPaused() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter - + // Pause treasury vm.prank(users.platform1AdminAddress); paymentTreasury.pauseTreasury(keccak256("Pause")); - + + address owner = CampaignInfo(campaignAddress).owner(); vm.expectRevert(); + vm.prank(owner); paymentTreasury.withdraw(); } - + /*////////////////////////////////////////////////////////////// PAUSE AND CANCEL //////////////////////////////////////////////////////////////*/ - + function testPauseTreasury() public { // First create and confirm a payment to test functions that require it _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter - + // Pause the treasury vm.prank(users.platform1AdminAddress); paymentTreasury.pauseTreasury(keccak256("Pause")); @@ -848,7 +890,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.expectRevert(); vm.prank(users.platform1AdminAddress); paymentTreasury.claimRefund(PAYMENT_ID_1, users.backer1Address); - + // disburseFees uses whenNotPaused vm.expectRevert(); paymentTreasury.disburseFees(); @@ -869,14 +911,14 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te new ICampaignPaymentTreasury.ExternalFees[](0) ); } - + function testUnpauseTreasury() public { vm.prank(users.platform1AdminAddress); paymentTreasury.pauseTreasury(keccak256("Pause")); - + vm.prank(users.platform1AdminAddress); paymentTreasury.unpauseTreasury(keccak256("Unpause")); - + // Should be able to create payment uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.prank(users.platform1AdminAddress); @@ -900,8 +942,8 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.platform1AdminAddress); paymentTreasury.cancelTreasury(keccak256("Cancel")); - - vm.expectRevert(); + + // disburseFees() should succeed even when cancelled (fixes vulnerability) paymentTreasury.disburseFees(); uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; @@ -919,7 +961,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te new ICampaignPaymentTreasury.ExternalFees[](0) ); } - + function testCancelTreasuryByCampaignOwner() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); vm.prank(users.platform1AdminAddress); @@ -928,8 +970,8 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te address owner = CampaignInfo(campaignAddress).owner(); vm.prank(owner); paymentTreasury.cancelTreasury(keccak256("Cancel")); - - vm.expectRevert(); + + // disburseFees() should succeed even when cancelled (fixes vulnerability) paymentTreasury.disburseFees(); uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; @@ -953,67 +995,69 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te vm.prank(users.backer1Address); paymentTreasury.cancelTreasury(keccak256("Cancel")); } - + /*////////////////////////////////////////////////////////////// EDGE CASES //////////////////////////////////////////////////////////////*/ - + function testMultipleRefundsAfterBatchConfirm() public { // Create multiple payments _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); _createAndFundPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, PAYMENT_AMOUNT_2, users.backer2Address); _createAndFundPayment(PAYMENT_ID_3, BUYER_ID_1, ITEM_ID_1, 500e18, users.backer1Address); - + // Confirm all in batch bytes32[] memory paymentIds = new bytes32[](3); paymentIds[0] = PAYMENT_ID_1; paymentIds[1] = PAYMENT_ID_2; paymentIds[2] = PAYMENT_ID_3; - + vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPaymentBatch(paymentIds, _createZeroAddressArray(paymentIds.length)); // Removed token array - + uint256 totalAmount = PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2 + 500e18; assertEq(paymentTreasury.getRaisedAmount(), totalAmount); - + // Refund payments one by one vm.startPrank(users.platform1AdminAddress); paymentTreasury.claimRefund(PAYMENT_ID_1, users.backer1Address); assertEq(paymentTreasury.getRaisedAmount(), totalAmount - PAYMENT_AMOUNT_1); - + paymentTreasury.claimRefund(PAYMENT_ID_2, users.backer2Address); assertEq(paymentTreasury.getRaisedAmount(), totalAmount - PAYMENT_AMOUNT_1 - PAYMENT_AMOUNT_2); - + paymentTreasury.claimRefund(PAYMENT_ID_3, users.backer1Address); assertEq(paymentTreasury.getRaisedAmount(), 0); vm.stopPrank(); } - + function testZeroBalanceAfterAllRefunds() public { _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); _createAndFundPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, PAYMENT_AMOUNT_2, users.backer2Address); - + vm.startPrank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter paymentTreasury.confirmPayment(PAYMENT_ID_2, address(0)); // Removed token parameter - + // Refund all payments paymentTreasury.claimRefund(PAYMENT_ID_1, users.backer1Address); paymentTreasury.claimRefund(PAYMENT_ID_2, users.backer2Address); vm.stopPrank(); - + assertEq(paymentTreasury.getRaisedAmount(), 0); assertEq(paymentTreasury.getAvailableRaisedAmount(), 0); - + // Withdraw should revert because balance is 0 + address owner = CampaignInfo(campaignAddress).owner(); vm.expectRevert(); + vm.prank(owner); paymentTreasury.withdraw(); } - + function testPaymentExpirationScenarios() public { uint256 shortExpiration = block.timestamp + 1 hours; uint256 longExpiration = block.timestamp + 7 days; - + // Create payments with different expirations ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.startPrank(users.platform1AdminAddress); @@ -1038,11 +1082,11 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te new ICampaignPaymentTreasury.ExternalFees[](0) ); vm.stopPrank(); - + // Fund both payments vm.prank(users.backer1Address); testToken.transfer(treasuryAddress, PAYMENT_AMOUNT_1); - + vm.prank(users.backer2Address); testToken.transfer(treasuryAddress, PAYMENT_AMOUNT_2); // Confirm first payment before expiration @@ -1057,7 +1101,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te // Can still confirm non-expired payment vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_2, address(0)); // Removed token parameter - + assertEq(paymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2); } @@ -1065,20 +1109,22 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te // Create both regular and crypto payments _createAndFundPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, PAYMENT_AMOUNT_1, users.backer1Address); _createAndProcessCryptoPayment(PAYMENT_ID_2, ITEM_ID_2, PAYMENT_AMOUNT_2, users.backer2Address); - + // Confirm regular payment vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter - + // Both should contribute to raised amount uint256 totalAmount = PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2; assertEq(paymentTreasury.getRaisedAmount(), totalAmount); assertEq(paymentTreasury.getAvailableRaisedAmount(), totalAmount); - + // Withdraw and disburse fees + address owner = CampaignInfo(campaignAddress).owner(); + vm.prank(owner); paymentTreasury.withdraw(); paymentTreasury.disburseFees(); - + assertEq(paymentTreasury.getAvailableRaisedAmount(), 0); } @@ -1097,21 +1143,21 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te emptyLineItems, new ICampaignPaymentTreasury.ExternalFees[](0) ); - + // Try to confirm without any tokens - should revert vm.expectRevert(); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); - + // Send the tokens deal(address(testToken), users.backer1Address, 1000e18); vm.prank(users.backer1Address); testToken.transfer(treasuryAddress, 1000e18); - + // Now confirmation works vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); - + assertEq(paymentTreasury.getRaisedAmount(), 1000e18); } @@ -1120,24 +1166,42 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.startPrank(users.platform1AdminAddress); ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); - paymentTreasury.createPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, address(testToken), 500e18, expiration, emptyLineItems, new ICampaignPaymentTreasury.ExternalFees[](0)); - paymentTreasury.createPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, address(testToken), 500e18, expiration, emptyLineItems, new ICampaignPaymentTreasury.ExternalFees[](0)); + paymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + 500e18, + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + paymentTreasury.createPayment( + PAYMENT_ID_2, + BUYER_ID_2, + ITEM_ID_2, + address(testToken), + 500e18, + expiration, + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); vm.stopPrank(); - + // Send only 500 tokens total deal(address(testToken), users.backer1Address, 500e18); vm.prank(users.backer1Address); testToken.transfer(treasuryAddress, 500e18); - + // Can confirm one payment vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); // Removed token parameter - + // Cannot confirm second payment - total would exceed balance vm.expectRevert(); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_2, address(0)); // Removed token parameter - + assertEq(paymentTreasury.getRaisedAmount(), 500e18); } @@ -1146,21 +1210,40 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; vm.startPrank(users.platform1AdminAddress); ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); - ICampaignPaymentTreasury.ExternalFees[] memory emptyExternalFees = new ICampaignPaymentTreasury.ExternalFees[](0); - paymentTreasury.createPayment(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, address(testToken), 500e18, expiration, emptyLineItems, emptyExternalFees); - paymentTreasury.createPayment(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, address(testToken), 500e18, expiration, emptyLineItems, emptyExternalFees); + ICampaignPaymentTreasury.ExternalFees[] memory emptyExternalFees = + new ICampaignPaymentTreasury.ExternalFees[](0); + paymentTreasury.createPayment( + PAYMENT_ID_1, + BUYER_ID_1, + ITEM_ID_1, + address(testToken), + 500e18, + expiration, + emptyLineItems, + emptyExternalFees + ); + paymentTreasury.createPayment( + PAYMENT_ID_2, + BUYER_ID_2, + ITEM_ID_2, + address(testToken), + 500e18, + expiration, + emptyLineItems, + emptyExternalFees + ); vm.stopPrank(); - + // Send only 500 tokens deal(address(testToken), users.backer1Address, 500e18); vm.prank(users.backer1Address); testToken.transfer(treasuryAddress, 500e18); - - // Try to confirm both + + // Try to confirm both bytes32[] memory paymentIds = new bytes32[](2); paymentIds[0] = PAYMENT_ID_1; paymentIds[1] = PAYMENT_ID_2; - + vm.expectRevert(); vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPaymentBatch(paymentIds, _createZeroAddressArray(paymentIds.length)); // Removed token array @@ -1174,33 +1257,23 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te // Create payments expecting different tokens uint256 usdtAmount = getTokenAmount(address(usdtToken), 500e18); uint256 cUSDAmount = 700e18; - + // Create USDT payment - token specified during creation _createAndFundPaymentWithToken( - PAYMENT_ID_1, - BUYER_ID_1, - ITEM_ID_1, - usdtAmount, - users.backer1Address, - address(usdtToken) + PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, usdtAmount, users.backer1Address, address(usdtToken) ); - + // Create cUSD payment - token specified during creation _createAndFundPaymentWithToken( - PAYMENT_ID_2, - BUYER_ID_2, - ITEM_ID_2, - cUSDAmount, - users.backer2Address, - address(cUSDToken) + PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, cUSDAmount, users.backer2Address, address(cUSDToken) ); - + // Confirm without specifying token vm.startPrank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); paymentTreasury.confirmPayment(PAYMENT_ID_2, address(0)); vm.stopPrank(); - + uint256 expectedTotal = 500e18 + 700e18; assertEq(paymentTreasury.getRaisedAmount(), expectedTotal); } @@ -1208,7 +1281,7 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testProcessCryptoPaymentWithDifferentTokens() public { uint256 usdcAmount = getTokenAmount(address(usdcToken), 800e18); uint256 cUSDAmount = 1200e18; - + // USDC payment deal(address(usdcToken), users.backer1Address, usdcAmount); vm.prank(users.backer1Address); @@ -1221,9 +1294,10 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te users.backer1Address, address(usdcToken), usdcAmount, - emptyLineItems - , new ICampaignPaymentTreasury.ExternalFees[](0)); - + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + // cUSD payment deal(address(cUSDToken), users.backer2Address, cUSDAmount); vm.prank(users.backer2Address); @@ -1235,9 +1309,10 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te users.backer2Address, address(cUSDToken), cUSDAmount, - emptyLineItems - , new ICampaignPaymentTreasury.ExternalFees[](0)); - + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + uint256 expectedTotal = 800e18 + 1200e18; assertEq(paymentTreasury.getRaisedAmount(), expectedTotal); assertEq(usdcToken.balanceOf(treasuryAddress), usdcAmount); @@ -1248,92 +1323,76 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te uint256 usdtAmount = getTokenAmount(address(usdtToken), 500e18); uint256 usdcAmount = getTokenAmount(address(usdcToken), 600e18); uint256 cUSDAmount = 700e18; - + // Create payments with tokens specified - _createAndFundPaymentWithToken(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, usdtAmount, users.backer1Address, address(usdtToken)); - _createAndFundPaymentWithToken(PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, usdcAmount, users.backer2Address, address(usdcToken)); - _createAndFundPaymentWithToken(PAYMENT_ID_3, BUYER_ID_3, ITEM_ID_1, cUSDAmount, users.backer1Address, address(cUSDToken)); - + _createAndFundPaymentWithToken( + PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, usdtAmount, users.backer1Address, address(usdtToken) + ); + _createAndFundPaymentWithToken( + PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, usdcAmount, users.backer2Address, address(usdcToken) + ); + _createAndFundPaymentWithToken( + PAYMENT_ID_3, BUYER_ID_3, ITEM_ID_1, cUSDAmount, users.backer1Address, address(cUSDToken) + ); + // Batch confirm without token array bytes32[] memory paymentIds = new bytes32[](3); paymentIds[0] = PAYMENT_ID_1; paymentIds[1] = PAYMENT_ID_2; paymentIds[2] = PAYMENT_ID_3; - + vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPaymentBatch(paymentIds, _createZeroAddressArray(paymentIds.length)); - + uint256 expectedTotal = 500e18 + 600e18 + 700e18; assertEq(paymentTreasury.getRaisedAmount(), expectedTotal); } function testRefundReturnsCorrectTokenType() public { uint256 usdtAmount = getTokenAmount(address(usdtToken), PAYMENT_AMOUNT_1); - + _createAndFundPaymentWithToken( - PAYMENT_ID_1, - BUYER_ID_1, - ITEM_ID_1, - usdtAmount, - users.backer1Address, - address(usdtToken) + PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, usdtAmount, users.backer1Address, address(usdtToken) ); - + vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); - + uint256 usdtBefore = usdtToken.balanceOf(users.backer1Address); uint256 cUSDBefore = cUSDToken.balanceOf(users.backer1Address); - + vm.prank(users.platform1AdminAddress); paymentTreasury.claimRefund(PAYMENT_ID_1, users.backer1Address); - + // Should receive USDT, not cUSD - assertEq( - usdtToken.balanceOf(users.backer1Address) - usdtBefore, - usdtAmount, - "Should receive USDT" - ); - assertEq( - cUSDToken.balanceOf(users.backer1Address), - cUSDBefore, - "cUSD should be unchanged" - ); + assertEq(usdtToken.balanceOf(users.backer1Address) - usdtBefore, usdtAmount, "Should receive USDT"); + assertEq(cUSDToken.balanceOf(users.backer1Address), cUSDBefore, "cUSD should be unchanged"); } function testWithdrawDistributesAllTokens() public { uint256 usdtAmount = getTokenAmount(address(usdtToken), 1000e18); uint256 cUSDAmount = 1500e18; - + _createAndFundPaymentWithToken( - PAYMENT_ID_1, - BUYER_ID_1, - ITEM_ID_1, - usdtAmount, - users.backer1Address, - address(usdtToken) + PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, usdtAmount, users.backer1Address, address(usdtToken) ); - + _createAndFundPaymentWithToken( - PAYMENT_ID_2, - BUYER_ID_2, - ITEM_ID_2, - cUSDAmount, - users.backer2Address, - address(cUSDToken) + PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, cUSDAmount, users.backer2Address, address(cUSDToken) ); - + vm.startPrank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); paymentTreasury.confirmPayment(PAYMENT_ID_2, address(0)); vm.stopPrank(); - + address owner = CampaignInfo(campaignAddress).owner(); uint256 ownerUSDTBefore = usdtToken.balanceOf(owner); uint256 ownerCUSDBefore = cUSDToken.balanceOf(owner); - + + vm.prank(owner); paymentTreasury.withdraw(); - + // Should receive both tokens assertTrue(usdtToken.balanceOf(owner) > ownerUSDTBefore, "Should receive USDT"); assertTrue(cUSDToken.balanceOf(owner) > ownerCUSDBefore, "Should receive cUSD"); @@ -1342,55 +1401,43 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testDisburseFeesDistributesAllTokens() public { uint256 usdcAmount = getTokenAmount(address(usdcToken), PAYMENT_AMOUNT_1); uint256 cUSDAmount = PAYMENT_AMOUNT_2; - + _createAndFundPaymentWithToken( - PAYMENT_ID_1, - BUYER_ID_1, - ITEM_ID_1, - usdcAmount, - users.backer1Address, - address(usdcToken) + PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, usdcAmount, users.backer1Address, address(usdcToken) ); - + _createAndFundPaymentWithToken( - PAYMENT_ID_2, - BUYER_ID_2, - ITEM_ID_2, - cUSDAmount, - users.backer2Address, - address(cUSDToken) + PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, cUSDAmount, users.backer2Address, address(cUSDToken) ); - + vm.startPrank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); paymentTreasury.confirmPayment(PAYMENT_ID_2, address(0)); vm.stopPrank(); - + + address owner = CampaignInfo(campaignAddress).owner(); + vm.prank(owner); paymentTreasury.withdraw(); - + uint256 protocolUSDCBefore = usdcToken.balanceOf(users.protocolAdminAddress); uint256 protocolCUSDBefore = cUSDToken.balanceOf(users.protocolAdminAddress); uint256 platformUSDCBefore = usdcToken.balanceOf(users.platform1AdminAddress); uint256 platformCUSDBefore = cUSDToken.balanceOf(users.platform1AdminAddress); - + paymentTreasury.disburseFees(); - + // All token types should have fees disbursed assertTrue( - usdcToken.balanceOf(users.protocolAdminAddress) > protocolUSDCBefore, - "Should disburse USDC to protocol" + usdcToken.balanceOf(users.protocolAdminAddress) > protocolUSDCBefore, "Should disburse USDC to protocol" ); assertTrue( - cUSDToken.balanceOf(users.protocolAdminAddress) > protocolCUSDBefore, - "Should disburse cUSD to protocol" + cUSDToken.balanceOf(users.protocolAdminAddress) > protocolCUSDBefore, "Should disburse cUSD to protocol" ); assertTrue( - usdcToken.balanceOf(users.platform1AdminAddress) > platformUSDCBefore, - "Should disburse USDC to platform" + usdcToken.balanceOf(users.platform1AdminAddress) > platformUSDCBefore, "Should disburse USDC to platform" ); assertTrue( - cUSDToken.balanceOf(users.platform1AdminAddress) > platformCUSDBefore, - "Should disburse cUSD to platform" + cUSDToken.balanceOf(users.platform1AdminAddress) > platformCUSDBefore, "Should disburse cUSD to platform" ); } @@ -1398,35 +1445,25 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te // Test that 1000 USDT (6 decimals) = 1000 cUSD (18 decimals) after normalization uint256 baseAmount = 1000e18; uint256 usdtAmount = baseAmount / 1e12; // 1000 USDT (1000000000) - uint256 cUSDAmount = baseAmount; // 1000 cUSD (1000000000000000000000) - + uint256 cUSDAmount = baseAmount; // 1000 cUSD (1000000000000000000000) + _createAndFundPaymentWithToken( - PAYMENT_ID_1, - BUYER_ID_1, - ITEM_ID_1, - usdtAmount, - users.backer1Address, - address(usdtToken) + PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, usdtAmount, users.backer1Address, address(usdtToken) ); - + vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); - + uint256 raisedAfterUSDT = paymentTreasury.getRaisedAmount(); assertEq(raisedAfterUSDT, baseAmount, "1000 USDT should equal 1000e18 normalized"); - + _createAndFundPaymentWithToken( - PAYMENT_ID_2, - BUYER_ID_2, - ITEM_ID_2, - cUSDAmount, - users.backer2Address, - address(cUSDToken) + PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, cUSDAmount, users.backer2Address, address(cUSDToken) ); - + vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_2, address(0)); - + uint256 totalRaised = paymentTreasury.getRaisedAmount(); assertEq(totalRaised, baseAmount * 2, "Both should contribute equally"); } @@ -1434,10 +1471,12 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testCannotConfirmWithInsufficientBalancePerToken() public { uint256 usdtAmount = getTokenAmount(address(usdtToken), 1000e18); uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; - + // Create two payments expecting USDT - _createAndFundPaymentWithToken(PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, usdtAmount, users.backer1Address, address(usdtToken)); - + _createAndFundPaymentWithToken( + PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, usdtAmount, users.backer1Address, address(usdtToken) + ); + ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); paymentTreasury.createPayment( @@ -1450,13 +1489,13 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te emptyLineItems, new ICampaignPaymentTreasury.ExternalFees[](0) ); - + // Only funded first payment, second has no tokens - + // Can confirm first vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); - + // Cannot confirm second - insufficient USDT balance vm.expectRevert(); vm.prank(users.platform1AdminAddress); @@ -1467,33 +1506,25 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te // This tests the edge case where some tokens are withdrawn but others have pending refunds uint256 usdtAmount = getTokenAmount(address(usdtToken), 1000e18); uint256 cUSDAmount = 1500e18; - + _createAndFundPaymentWithToken( - PAYMENT_ID_1, - BUYER_ID_1, - ITEM_ID_1, - usdtAmount, - users.backer1Address, - address(usdtToken) + PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, usdtAmount, users.backer1Address, address(usdtToken) ); - + _createAndFundPaymentWithToken( - PAYMENT_ID_2, - BUYER_ID_2, - ITEM_ID_2, - cUSDAmount, - users.backer2Address, - address(cUSDToken) + PAYMENT_ID_2, BUYER_ID_2, ITEM_ID_2, cUSDAmount, users.backer2Address, address(cUSDToken) ); - + vm.startPrank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); paymentTreasury.confirmPayment(PAYMENT_ID_2, address(0)); vm.stopPrank(); - + // Withdraw (takes fees) + address owner = CampaignInfo(campaignAddress).owner(); + vm.prank(owner); paymentTreasury.withdraw(); - + // Try to refund - should fail because funds were withdrawn vm.expectRevert(); vm.prank(users.platform1AdminAddress); @@ -1503,25 +1534,22 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te function testZeroBalanceTokensHandledGracefully() public { // Create payment with USDT only uint256 usdtAmount = getTokenAmount(address(usdtToken), PAYMENT_AMOUNT_1); - + _createAndFundPaymentWithToken( - PAYMENT_ID_1, - BUYER_ID_1, - ITEM_ID_1, - usdtAmount, - users.backer1Address, - address(usdtToken) + PAYMENT_ID_1, BUYER_ID_1, ITEM_ID_1, usdtAmount, users.backer1Address, address(usdtToken) ); - + vm.prank(users.platform1AdminAddress); paymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); - + // Withdraw should handle zero-balance tokens (USDC, cUSD) gracefully + address owner = CampaignInfo(campaignAddress).owner(); + vm.prank(owner); paymentTreasury.withdraw(); - + // Disburse should also handle it paymentTreasury.disburseFees(); - + // Verify only USDT was processed assertEq(usdcToken.balanceOf(treasuryAddress), 0, "USDC should remain zero"); assertEq(cUSDToken.balanceOf(treasuryAddress), 0, "cUSD should remain zero"); @@ -1551,9 +1579,9 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te itemIds[1] = ITEM_ID_2; itemIds[2] = ITEM_ID_1; // Reuse existing item ID - amounts[0] = 100 * 10**18; - amounts[1] = 200 * 10**18; - amounts[2] = 300 * 10**18; + amounts[0] = 100 * 10 ** 18; + amounts[1] = 200 * 10 ** 18; + amounts[2] = 300 * 10 ** 18; expirations[0] = block.timestamp + 1 days; expirations[1] = block.timestamp + 2 days; @@ -1565,11 +1593,21 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te emptyLineItemsArray[1] = new ICampaignPaymentTreasury.LineItem[](0); emptyLineItemsArray[2] = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); - ICampaignPaymentTreasury.ExternalFees[][] memory emptyExternalFeesArray = new ICampaignPaymentTreasury.ExternalFees[][](3); + ICampaignPaymentTreasury.ExternalFees[][] memory emptyExternalFeesArray = + new ICampaignPaymentTreasury.ExternalFees[][](3); for (uint256 i = 0; i < 3; i++) { emptyExternalFeesArray[i] = new ICampaignPaymentTreasury.ExternalFees[](0); } - paymentTreasury.createPaymentBatch(paymentIds, buyerIds, itemIds, _createPaymentTokensArray(3, address(testToken)), amounts, expirations, emptyLineItemsArray, emptyExternalFeesArray); + paymentTreasury.createPaymentBatch( + paymentIds, + buyerIds, + itemIds, + _createPaymentTokensArray(3, address(testToken)), + amounts, + expirations, + emptyLineItemsArray, + emptyExternalFeesArray + ); // Verify that payments were created by checking raised amount is still 0 (not confirmed yet) assertEq(paymentTreasury.getRaisedAmount(), 0); @@ -1583,17 +1621,28 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te uint256[] memory amounts = new uint256[](2); uint256[] memory expirations = new uint256[](2); - ICampaignPaymentTreasury.LineItem[][] memory emptyLineItemsArray = new ICampaignPaymentTreasury.LineItem[][](paymentIds.length); + ICampaignPaymentTreasury.LineItem[][] memory emptyLineItemsArray = + new ICampaignPaymentTreasury.LineItem[][](paymentIds.length); for (uint256 i = 0; i < paymentIds.length; i++) { emptyLineItemsArray[i] = new ICampaignPaymentTreasury.LineItem[](0); } vm.prank(users.platform1AdminAddress); - ICampaignPaymentTreasury.ExternalFees[][] memory emptyExternalFeesArray = new ICampaignPaymentTreasury.ExternalFees[][](paymentIds.length); + ICampaignPaymentTreasury.ExternalFees[][] memory emptyExternalFeesArray = + new ICampaignPaymentTreasury.ExternalFees[][](paymentIds.length); for (uint256 i = 0; i < paymentIds.length; i++) { emptyExternalFeesArray[i] = new ICampaignPaymentTreasury.ExternalFees[](0); } vm.expectRevert(); - paymentTreasury.createPaymentBatch(paymentIds, buyerIds, itemIds, _createPaymentTokensArray(paymentIds.length, address(testToken)), amounts, expirations, emptyLineItemsArray, emptyExternalFeesArray); + paymentTreasury.createPaymentBatch( + paymentIds, + buyerIds, + itemIds, + _createPaymentTokensArray(paymentIds.length, address(testToken)), + amounts, + expirations, + emptyLineItemsArray, + emptyExternalFeesArray + ); } function testCreatePaymentBatchRevertWhenEmptyArray() public { @@ -1603,17 +1652,28 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te uint256[] memory amounts = new uint256[](0); uint256[] memory expirations = new uint256[](0); - ICampaignPaymentTreasury.LineItem[][] memory emptyLineItemsArray = new ICampaignPaymentTreasury.LineItem[][](paymentIds.length); + ICampaignPaymentTreasury.LineItem[][] memory emptyLineItemsArray = + new ICampaignPaymentTreasury.LineItem[][](paymentIds.length); for (uint256 i = 0; i < paymentIds.length; i++) { emptyLineItemsArray[i] = new ICampaignPaymentTreasury.LineItem[](0); } - ICampaignPaymentTreasury.ExternalFees[][] memory emptyExternalFeesArray = new ICampaignPaymentTreasury.ExternalFees[][](paymentIds.length); + ICampaignPaymentTreasury.ExternalFees[][] memory emptyExternalFeesArray = + new ICampaignPaymentTreasury.ExternalFees[][](paymentIds.length); for (uint256 i = 0; i < paymentIds.length; i++) { emptyExternalFeesArray[i] = new ICampaignPaymentTreasury.ExternalFees[](0); } vm.prank(users.platform1AdminAddress); vm.expectRevert(); - paymentTreasury.createPaymentBatch(paymentIds, buyerIds, itemIds, _createPaymentTokensArray(paymentIds.length, address(testToken)), amounts, expirations, emptyLineItemsArray, emptyExternalFeesArray); + paymentTreasury.createPaymentBatch( + paymentIds, + buyerIds, + itemIds, + _createPaymentTokensArray(paymentIds.length, address(testToken)), + amounts, + expirations, + emptyLineItemsArray, + emptyExternalFeesArray + ); } function testCreatePaymentBatchRevertWhenPaymentAlreadyExists() public { @@ -1645,17 +1705,28 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te amounts[0] = PAYMENT_AMOUNT_2; expirations[0] = block.timestamp + 2 days; - ICampaignPaymentTreasury.LineItem[][] memory emptyLineItemsArray = new ICampaignPaymentTreasury.LineItem[][](paymentIds.length); + ICampaignPaymentTreasury.LineItem[][] memory emptyLineItemsArray = + new ICampaignPaymentTreasury.LineItem[][](paymentIds.length); for (uint256 i = 0; i < paymentIds.length; i++) { emptyLineItemsArray[i] = new ICampaignPaymentTreasury.LineItem[](0); } - ICampaignPaymentTreasury.ExternalFees[][] memory emptyExternalFeesArray = new ICampaignPaymentTreasury.ExternalFees[][](paymentIds.length); + ICampaignPaymentTreasury.ExternalFees[][] memory emptyExternalFeesArray = + new ICampaignPaymentTreasury.ExternalFees[][](paymentIds.length); for (uint256 i = 0; i < paymentIds.length; i++) { emptyExternalFeesArray[i] = new ICampaignPaymentTreasury.ExternalFees[](0); } vm.prank(users.platform1AdminAddress); vm.expectRevert(); - paymentTreasury.createPaymentBatch(paymentIds, buyerIds, itemIds, _createPaymentTokensArray(paymentIds.length, address(testToken)), amounts, expirations, emptyLineItemsArray, emptyExternalFeesArray); + paymentTreasury.createPaymentBatch( + paymentIds, + buyerIds, + itemIds, + _createPaymentTokensArray(paymentIds.length, address(testToken)), + amounts, + expirations, + emptyLineItemsArray, + emptyExternalFeesArray + ); } function testCreatePaymentBatchRevertWhenNotPlatformAdmin() public { @@ -1671,17 +1742,28 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te amounts[0] = PAYMENT_AMOUNT_1; expirations[0] = block.timestamp + 1 days; - ICampaignPaymentTreasury.LineItem[][] memory emptyLineItemsArray = new ICampaignPaymentTreasury.LineItem[][](paymentIds.length); + ICampaignPaymentTreasury.LineItem[][] memory emptyLineItemsArray = + new ICampaignPaymentTreasury.LineItem[][](paymentIds.length); for (uint256 i = 0; i < paymentIds.length; i++) { emptyLineItemsArray[i] = new ICampaignPaymentTreasury.LineItem[](0); } - ICampaignPaymentTreasury.ExternalFees[][] memory emptyExternalFeesArray = new ICampaignPaymentTreasury.ExternalFees[][](paymentIds.length); + ICampaignPaymentTreasury.ExternalFees[][] memory emptyExternalFeesArray = + new ICampaignPaymentTreasury.ExternalFees[][](paymentIds.length); for (uint256 i = 0; i < paymentIds.length; i++) { emptyExternalFeesArray[i] = new ICampaignPaymentTreasury.ExternalFees[](0); } vm.prank(users.creator1Address); // Not platform admin vm.expectRevert(); - paymentTreasury.createPaymentBatch(paymentIds, buyerIds, itemIds, _createPaymentTokensArray(paymentIds.length, address(testToken)), amounts, expirations, emptyLineItemsArray, emptyExternalFeesArray); + paymentTreasury.createPaymentBatch( + paymentIds, + buyerIds, + itemIds, + _createPaymentTokensArray(paymentIds.length, address(testToken)), + amounts, + expirations, + emptyLineItemsArray, + emptyExternalFeesArray + ); } function testCreatePaymentBatchWithMultipleTokens() public { @@ -1710,9 +1792,9 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te paymentTokens[1] = address(testToken); // cUSD (same token for simplicity in test) paymentTokens[2] = address(testToken); // cUSD (same token for simplicity in test) - amounts[0] = 100 * 10**18; - amounts[1] = 200 * 10**18; - amounts[2] = 300 * 10**18; + amounts[0] = 100 * 10 ** 18; + amounts[1] = 200 * 10 ** 18; + amounts[2] = 300 * 10 ** 18; expirations[0] = block.timestamp + 1 days; expirations[1] = block.timestamp + 2 days; @@ -1724,11 +1806,14 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te emptyLineItemsArray[1] = new ICampaignPaymentTreasury.LineItem[](0); emptyLineItemsArray[2] = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); - ICampaignPaymentTreasury.ExternalFees[][] memory externalFeesArray = new ICampaignPaymentTreasury.ExternalFees[][](3); + ICampaignPaymentTreasury.ExternalFees[][] memory externalFeesArray = + new ICampaignPaymentTreasury.ExternalFees[][](3); externalFeesArray[0] = new ICampaignPaymentTreasury.ExternalFees[](0); externalFeesArray[1] = new ICampaignPaymentTreasury.ExternalFees[](0); externalFeesArray[2] = new ICampaignPaymentTreasury.ExternalFees[](0); - paymentTreasury.createPaymentBatch(paymentIds, buyerIds, itemIds, paymentTokens, amounts, expirations, emptyLineItemsArray, externalFeesArray); + paymentTreasury.createPaymentBatch( + paymentIds, buyerIds, itemIds, paymentTokens, amounts, expirations, emptyLineItemsArray, externalFeesArray + ); // Verify that payments were created assertEq(paymentTreasury.getRaisedAmount(), 0); @@ -1738,4 +1823,4 @@ contract PaymentTreasury_UnitTest is Test, PaymentTreasury_Integration_Shared_Te // (The fact that no revert occurred means all payments were created successfully) assertTrue(true); // This test passes if no revert occurred during batch creation } -} \ No newline at end of file +} diff --git a/test/foundry/unit/PledgeNFT.t.sol b/test/foundry/unit/PledgeNFT.t.sol index 45b1eb8c..a79122d7 100644 --- a/test/foundry/unit/PledgeNFT.t.sol +++ b/test/foundry/unit/PledgeNFT.t.sol @@ -6,32 +6,32 @@ import "../Base.t.sol"; contract PledgeNFT_Test is Base_Test { CampaignInfo public campaign; KeepWhatsRaised public treasury; - + bytes32 public constant PLATFORM_HASH = keccak256("PLATFORM_1"); bytes32 public constant TREASURY_ROLE = keccak256("TREASURY_ROLE"); - + function setUp() public override { super.setUp(); - + // Enlist platform vm.prank(users.protocolAdminAddress); - globalParams.enlistPlatform(PLATFORM_HASH, users.platform1AdminAddress, PLATFORM_FEE_PERCENT); - + globalParams.enlistPlatform(PLATFORM_HASH, users.platform1AdminAddress, PLATFORM_FEE_PERCENT, address(0)); + // Register treasury implementation vm.startPrank(users.platform1AdminAddress); treasuryFactory.registerTreasuryImplementation(PLATFORM_HASH, 1, address(keepWhatsRaisedImplementation)); vm.stopPrank(); - + vm.prank(users.protocolAdminAddress); treasuryFactory.approveTreasuryImplementation(PLATFORM_HASH, 1); - + // Create a campaign bytes32 identifierHash = keccak256("TEST_CAMPAIGN"); bytes32[] memory selectedPlatforms = new bytes32[](1); selectedPlatforms[0] = PLATFORM_HASH; bytes32[] memory keys = new bytes32[](0); bytes32[] memory values = new bytes32[](0); - + vm.prank(users.creator1Address); campaignInfoFactory.createCampaign( users.creator1Address, @@ -45,121 +45,74 @@ contract PledgeNFT_Test is Base_Test { "ipfs://QmTestImage", "ipfs://QmTestContract" ); - + address campaignAddress = campaignInfoFactory.identifierToCampaignInfo(identifierHash); campaign = CampaignInfo(campaignAddress); - + // Deploy treasury vm.prank(users.platform1AdminAddress); - address treasuryAddress = treasuryFactory.deploy( - PLATFORM_HASH, - campaignAddress, - 1 - ); + address treasuryAddress = treasuryFactory.deploy(PLATFORM_HASH, campaignAddress, 1); treasury = KeepWhatsRaised(treasuryAddress); } - + function test_OnlyTreasuryCanMintNFT() public { // Try to mint without TREASURY_ROLE - should revert vm.expectRevert(); vm.prank(users.backer1Address); - campaign.mintNFTForPledge( - users.backer1Address, - bytes32(0), - address(testToken), - 100e18, - 0, - 0 - ); + campaign.mintNFTForPledge(users.backer1Address, bytes32(0), address(testToken), 100e18, 0, 0); } - + function test_TreasuryCanMintNFT() public { // Treasury has TREASURY_ROLE, should be able to mint vm.prank(address(treasury)); - uint256 tokenId = campaign.mintNFTForPledge( - users.backer1Address, - bytes32(0), - address(testToken), - 100e18, - 0, - 0 - ); - + uint256 tokenId = campaign.mintNFTForPledge(users.backer1Address, bytes32(0), address(testToken), 100e18, 0, 0); + // Verify NFT was minted assertEq(tokenId, 1, "First token ID should be 1"); assertEq(campaign.balanceOf(users.backer1Address), 1, "Backer should have 1 NFT"); assertEq(campaign.ownerOf(tokenId), users.backer1Address, "Backer should own the NFT"); } - + function test_TokenIdIncrementsAndNeverReuses() public { // Mint first NFT vm.prank(address(treasury)); - uint256 tokenId1 = campaign.mintNFTForPledge( - users.backer1Address, - bytes32(0), - address(testToken), - 100e18, - 0, - 0 - ); + uint256 tokenId1 = campaign.mintNFTForPledge(users.backer1Address, bytes32(0), address(testToken), 100e18, 0, 0); assertEq(tokenId1, 1, "First token ID should be 1"); - + // Mint second NFT vm.prank(address(treasury)); - uint256 tokenId2 = campaign.mintNFTForPledge( - users.backer1Address, - bytes32(0), - address(testToken), - 100e18, - 0, - 0 - ); + uint256 tokenId2 = campaign.mintNFTForPledge(users.backer1Address, bytes32(0), address(testToken), 100e18, 0, 0); assertEq(tokenId2, 2, "Second token ID should be 2"); - + // Burn first NFT vm.prank(users.backer1Address); campaign.burn(tokenId1); - + // Mint third NFT - should be 3, NOT reusing 1 vm.prank(address(treasury)); - uint256 tokenId3 = campaign.mintNFTForPledge( - users.backer1Address, - bytes32(0), - address(testToken), - 100e18, - 0, - 0 - ); + uint256 tokenId3 = campaign.mintNFTForPledge(users.backer1Address, bytes32(0), address(testToken), 100e18, 0, 0); assertEq(tokenId3, 3, "Third token ID should be 3, not reusing burned ID 1"); - + // Verify balances assertEq(campaign.balanceOf(users.backer1Address), 2, "Backer should have 2 NFTs after burn"); } - + function test_BurnRemovesNFT() public { // Mint NFT vm.prank(address(treasury)); - uint256 tokenId = campaign.mintNFTForPledge( - users.backer1Address, - bytes32(0), - address(testToken), - 100e18, - 0, - 0 - ); - + uint256 tokenId = campaign.mintNFTForPledge(users.backer1Address, bytes32(0), address(testToken), 100e18, 0, 0); + assertEq(campaign.balanceOf(users.backer1Address), 1, "Backer should have 1 NFT"); - + // Burn NFT vm.prank(users.backer1Address); campaign.burn(tokenId); - + // Verify NFT was burned assertEq(campaign.balanceOf(users.backer1Address), 0, "Backer should have 0 NFTs after burn"); - + // Trying to query owner of burned token should revert vm.expectRevert(); campaign.ownerOf(tokenId); } } - diff --git a/test/foundry/unit/TimeConstrainedPaymentTreasury.t.sol b/test/foundry/unit/TimeConstrainedPaymentTreasury.t.sol index 12ad8564..845d2446 100644 --- a/test/foundry/unit/TimeConstrainedPaymentTreasury.t.sol +++ b/test/foundry/unit/TimeConstrainedPaymentTreasury.t.sol @@ -8,8 +8,10 @@ import {CampaignInfo} from "src/CampaignInfo.sol"; import {TestToken} from "../../mocks/TestToken.sol"; import {DataRegistryKeys} from "src/constants/DataRegistryKeys.sol"; -contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test { - +contract TimeConstrainedPaymentTreasury_UnitTest is + Test, + TimeConstrainedPaymentTreasuryFunction_Integration_Shared_Test +{ // Helper function to create payment tokens array with same token for all payments function _createPaymentTokensArray(uint256 length, address token) internal pure returns (address[] memory) { address[] memory paymentTokens = new address[](length); @@ -18,7 +20,7 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment } return paymentTokens; } - + function setUp() public virtual override { super.setUp(); // Fund test addresses @@ -32,20 +34,20 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment vm.label(users.backer2Address, "Backer2"); vm.label(address(timeConstrainedPaymentTreasury), "TimeConstrainedPaymentTreasury"); } - + /*////////////////////////////////////////////////////////////// INITIALIZATION //////////////////////////////////////////////////////////////*/ - + function testInitialize() public { // Create a new campaign for this test bytes32 newIdentifierHash = keccak256(abi.encodePacked("newTimeConstrainedCampaign")); bytes32[] memory selectedPlatformHash = new bytes32[](1); selectedPlatformHash[0] = PLATFORM_1_HASH; - + bytes32[] memory platformDataKey = new bytes32[](0); bytes32[] memory platformDataValue = new bytes32[](0); - + vm.prank(users.creator1Address); campaignInfoFactory.createCampaign( users.creator1Address, @@ -60,7 +62,7 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment "ipfs://QmExampleContractURI" ); address newCampaignAddress = campaignInfoFactory.identifierToCampaignInfo(newIdentifierHash); - + // Deploy a new treasury vm.prank(users.platform1AdminAddress); address newTreasury = treasuryFactory.deploy( @@ -70,21 +72,21 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment ); TimeConstrainedPaymentTreasury newContract = TimeConstrainedPaymentTreasury(newTreasury); CampaignInfo newCampaignInfo = CampaignInfo(newCampaignAddress); - + // NFT name and symbol are now on CampaignInfo, not treasury assertEq(newCampaignInfo.name(), "Campaign Pledge NFT"); assertEq(newCampaignInfo.symbol(), "PLEDGE"); assertEq(newContract.getplatformHash(), PLATFORM_1_HASH); assertEq(newContract.getplatformFeePercent(), PLATFORM_FEE_PERCENT); } - + /*////////////////////////////////////////////////////////////// TIME CONSTRAINT TESTS //////////////////////////////////////////////////////////////*/ - + function testCreatePaymentWithinTimeRange() public { advanceToWithinRange(); - + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); @@ -102,10 +104,10 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); assertEq(timeConstrainedPaymentTreasury.getAvailableRaisedAmount(), 0); } - + function testCreatePaymentRevertWhenBeforeLaunchTime() public { advanceToBeforeLaunch(); - + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.expectRevert(); @@ -121,10 +123,10 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment new ICampaignPaymentTreasury.ExternalFees[](0) ); } - + function testCreatePaymentRevertWhenAfterDeadlinePlusBuffer() public { advanceToAfterDeadline(); - + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.expectRevert(); @@ -140,100 +142,87 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment new ICampaignPaymentTreasury.ExternalFees[](0) ); } - + function testCreatePaymentBatchWithinTimeRange() public { advanceToWithinRange(); - + bytes32[] memory paymentIds = new bytes32[](2); paymentIds[0] = PAYMENT_ID_1; paymentIds[1] = PAYMENT_ID_2; - + bytes32[] memory buyerIds = new bytes32[](2); buyerIds[0] = BUYER_ID_1; buyerIds[1] = BUYER_ID_2; - + bytes32[] memory itemIds = new bytes32[](2); itemIds[0] = ITEM_ID_1; itemIds[1] = ITEM_ID_2; - + address[] memory paymentTokens = _createPaymentTokensArray(2, address(testToken)); - + uint256[] memory amounts = new uint256[](2); amounts[0] = PAYMENT_AMOUNT_1; amounts[1] = PAYMENT_AMOUNT_2; - + uint256[] memory expirations = new uint256[](2); expirations[0] = block.timestamp + PAYMENT_EXPIRATION; expirations[1] = block.timestamp + PAYMENT_EXPIRATION; - + ICampaignPaymentTreasury.LineItem[][] memory emptyLineItemsArray = new ICampaignPaymentTreasury.LineItem[][](2); emptyLineItemsArray[0] = new ICampaignPaymentTreasury.LineItem[](0); emptyLineItemsArray[1] = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); - ICampaignPaymentTreasury.ExternalFees[][] memory externalFeesArray = new ICampaignPaymentTreasury.ExternalFees[][](2); - externalFeesArray[0] = new ICampaignPaymentTreasury.ExternalFees[](0); - externalFeesArray[1] = new ICampaignPaymentTreasury.ExternalFees[](0); + ICampaignPaymentTreasury.ExternalFees[][] memory externalFeesArray = + new ICampaignPaymentTreasury.ExternalFees[][](2); + externalFeesArray[0] = new ICampaignPaymentTreasury.ExternalFees[](0); + externalFeesArray[1] = new ICampaignPaymentTreasury.ExternalFees[](0); timeConstrainedPaymentTreasury.createPaymentBatch( - paymentIds, - buyerIds, - itemIds, - paymentTokens, - amounts, - expirations, - emptyLineItemsArray, - - externalFeesArray + paymentIds, buyerIds, itemIds, paymentTokens, amounts, expirations, emptyLineItemsArray, externalFeesArray ); - + // Payments created successfully assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); } - + function testCreatePaymentBatchRevertWhenBeforeLaunchTime() public { advanceToBeforeLaunch(); - + bytes32[] memory paymentIds = new bytes32[](1); paymentIds[0] = PAYMENT_ID_1; - + bytes32[] memory buyerIds = new bytes32[](1); buyerIds[0] = BUYER_ID_1; - + bytes32[] memory itemIds = new bytes32[](1); itemIds[0] = ITEM_ID_1; - + address[] memory paymentTokens = _createPaymentTokensArray(1, address(testToken)); - + uint256[] memory amounts = new uint256[](1); amounts[0] = PAYMENT_AMOUNT_1; - + uint256[] memory expirations = new uint256[](1); expirations[0] = block.timestamp + PAYMENT_EXPIRATION; - + ICampaignPaymentTreasury.LineItem[][] memory emptyLineItemsArray = new ICampaignPaymentTreasury.LineItem[][](1); emptyLineItemsArray[0] = new ICampaignPaymentTreasury.LineItem[](0); - ICampaignPaymentTreasury.ExternalFees[][] memory externalFeesArray = new ICampaignPaymentTreasury.ExternalFees[][](1); + ICampaignPaymentTreasury.ExternalFees[][] memory externalFeesArray = + new ICampaignPaymentTreasury.ExternalFees[][](1); externalFeesArray[0] = new ICampaignPaymentTreasury.ExternalFees[](0); vm.expectRevert(); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.createPaymentBatch( - paymentIds, - buyerIds, - itemIds, - paymentTokens, - amounts, - expirations, - emptyLineItemsArray, - externalFeesArray + paymentIds, buyerIds, itemIds, paymentTokens, amounts, expirations, emptyLineItemsArray, externalFeesArray ); } - + function testProcessCryptoPaymentWithinTimeRange() public { advanceToWithinRange(); - + // Approve tokens for the treasury vm.prank(users.backer1Address); testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); - + vm.prank(users.platform1AdminAddress); ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); timeConstrainedPaymentTreasury.processCryptoPayment( @@ -242,16 +231,17 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment users.backer1Address, address(testToken), PAYMENT_AMOUNT_1, - emptyLineItems - , new ICampaignPaymentTreasury.ExternalFees[](0)); - + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + // Payment processed successfully assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1); } - + function testProcessCryptoPaymentRevertWhenBeforeLaunchTime() public { advanceToBeforeLaunch(); - + vm.expectRevert(); vm.prank(users.platform1AdminAddress); ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); @@ -261,13 +251,14 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment users.backer1Address, address(testToken), PAYMENT_AMOUNT_1, - emptyLineItems - , new ICampaignPaymentTreasury.ExternalFees[](0)); + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); } - + function testCancelPaymentWithinTimeRange() public { advanceToWithinRange(); - + // First create a payment uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); @@ -285,26 +276,26 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment // Then cancel it vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.cancelPayment(PAYMENT_ID_1); - + // Payment cancelled successfully assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); } - + function testCancelPaymentRevertWhenBeforeLaunchTime() public { advanceToBeforeLaunch(); - + vm.expectRevert(); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.cancelPayment(PAYMENT_ID_1); } - + function testConfirmPaymentWithinTimeRange() public { advanceToWithinRange(); - + // Use processCryptoPayment which creates and confirms payment in one step vm.prank(users.backer1Address); testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); - + vm.prank(users.platform1AdminAddress); ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); timeConstrainedPaymentTreasury.processCryptoPayment( @@ -313,28 +304,29 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment users.backer1Address, address(testToken), PAYMENT_AMOUNT_1, - emptyLineItems - , new ICampaignPaymentTreasury.ExternalFees[](0)); - + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + // Payment created and confirmed successfully by processCryptoPayment assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1); } - + function testConfirmPaymentRevertWhenBeforeLaunchTime() public { advanceToBeforeLaunch(); - + vm.expectRevert(); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.confirmPayment(PAYMENT_ID_1, address(0)); } - + function testConfirmPaymentBatchWithinTimeRange() public { advanceToWithinRange(); - + // Use processCryptoPayment for both payments which creates and confirms them vm.prank(users.backer1Address); testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); - + vm.prank(users.platform1AdminAddress); ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); timeConstrainedPaymentTreasury.processCryptoPayment( @@ -343,12 +335,13 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment users.backer1Address, address(testToken), PAYMENT_AMOUNT_1, - emptyLineItems - , new ICampaignPaymentTreasury.ExternalFees[](0)); - + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + vm.prank(users.backer2Address); testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_2); - + vm.prank(users.platform1AdminAddress); ICampaignPaymentTreasury.LineItem[] memory emptyLineItems2 = new ICampaignPaymentTreasury.LineItem[](0); timeConstrainedPaymentTreasury.processCryptoPayment( @@ -357,36 +350,37 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment users.backer2Address, address(testToken), PAYMENT_AMOUNT_2, - emptyLineItems2 - , new ICampaignPaymentTreasury.ExternalFees[](0)); - + emptyLineItems2, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + // Payments created and confirmed successfully by processCryptoPayment assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1 + PAYMENT_AMOUNT_2); } - + function testConfirmPaymentBatchRevertWhenBeforeLaunchTime() public { advanceToBeforeLaunch(); - + bytes32[] memory paymentIds = new bytes32[](1); paymentIds[0] = PAYMENT_ID_1; - + vm.expectRevert(); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.confirmPaymentBatch(paymentIds, _createZeroAddressArray(paymentIds.length)); } - + /*////////////////////////////////////////////////////////////// POST-LAUNCH TIME TESTS //////////////////////////////////////////////////////////////*/ - + function testClaimRefundAfterLaunchTime() public { // First create payment within the allowed time range advanceToWithinRange(); - + // Use processCryptoPayment which creates and confirms payment in one step vm.prank(users.backer1Address); testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); - + vm.prank(users.platform1AdminAddress); ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); timeConstrainedPaymentTreasury.processCryptoPayment( @@ -395,40 +389,41 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment users.backer1Address, address(testToken), PAYMENT_AMOUNT_1, - emptyLineItems - , new ICampaignPaymentTreasury.ExternalFees[](0)); - + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + // Advance to after launch to be able to claim refund advanceToAfterLaunch(); - + // Approve treasury to burn NFT vm.prank(users.backer1Address); CampaignInfo(campaignAddress).approve(address(timeConstrainedPaymentTreasury), 1); // tokenId 1 - + // Then claim refund (use the overload without refundAddress since processCryptoPayment uses buyerAddress) vm.prank(users.backer1Address); timeConstrainedPaymentTreasury.claimRefund(PAYMENT_ID_1); - + // Refund claimed successfully assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); } - + function testClaimRefundRevertWhenBeforeLaunchTime() public { advanceToBeforeLaunch(); - + vm.expectRevert(); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.claimRefund(PAYMENT_ID_1, users.backer1Address); } - + function testDisburseFeesAfterLaunchTime() public { // First create payment within the allowed time range advanceToWithinRange(); - + // Use processCryptoPayment which creates and confirms payment in one step vm.prank(users.backer1Address); testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); - + vm.prank(users.platform1AdminAddress); ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); timeConstrainedPaymentTreasury.processCryptoPayment( @@ -437,35 +432,36 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment users.backer1Address, address(testToken), PAYMENT_AMOUNT_1, - emptyLineItems - , new ICampaignPaymentTreasury.ExternalFees[](0)); - + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + // Advance to after launch time advanceToAfterLaunch(); - + // Then disburse fees vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.disburseFees(); - + // Fees disbursed successfully (no revert) } - + function testDisburseFeesRevertWhenBeforeLaunchTime() public { advanceToBeforeLaunch(); - + vm.expectRevert(); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.disburseFees(); } - + function testWithdrawAfterLaunchTime() public { // First create payment within the allowed time range advanceToWithinRange(); - + // Use processCryptoPayment which creates and confirms payment in one step vm.prank(users.backer1Address); testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); - + vm.prank(users.platform1AdminAddress); ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); timeConstrainedPaymentTreasury.processCryptoPayment( @@ -474,37 +470,38 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment users.backer1Address, address(testToken), PAYMENT_AMOUNT_1, - emptyLineItems - , new ICampaignPaymentTreasury.ExternalFees[](0)); - + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + // Advance to after launch time advanceToAfterLaunch(); - + // Then withdraw vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.withdraw(); - + // Withdrawal successful (no revert) } - + function testWithdrawRevertWhenBeforeLaunchTime() public { advanceToBeforeLaunch(); - + vm.expectRevert(); vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.withdraw(); } - + /*////////////////////////////////////////////////////////////// BUFFER TIME TESTS //////////////////////////////////////////////////////////////*/ - + function testBufferTimeRetrieval() public { // Test that buffer time is correctly retrieved from GlobalParams // We can't access _getBufferTime() directly, so we test it indirectly // by checking that operations work within the buffer time window vm.warp(campaignDeadline - 1); // Use deadline - 1 to be within range - + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); @@ -521,11 +518,11 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment // Should succeed at deadline - 1 assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); } - + function testOperationsAtDeadlinePlusBuffer() public { // Test operations at the exact deadline + buffer time vm.warp(campaignDeadline - 1); // Use deadline - 1 to be within range - + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); @@ -542,11 +539,11 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment // Should succeed at deadline - 1 assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); } - + function testOperationsAfterDeadlinePlusBuffer() public { // Test operations after deadline + buffer time advanceToAfterDeadline(); - + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.expectRevert(); @@ -562,15 +559,15 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment new ICampaignPaymentTreasury.ExternalFees[](0) ); } - + /*////////////////////////////////////////////////////////////// EDGE CASE TESTS //////////////////////////////////////////////////////////////*/ - + function testOperationsAtExactLaunchTime() public { // Test operations at the exact launch time vm.warp(campaignLaunchTime); - + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); @@ -587,11 +584,11 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment // Should succeed at the exact launch time assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); } - + function testOperationsAtExactDeadline() public { // Test operations at the exact deadline vm.warp(campaignDeadline); - + uint256 expiration = block.timestamp + PAYMENT_EXPIRATION; ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); vm.prank(users.platform1AdminAddress); @@ -608,15 +605,15 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment // Should succeed at the exact deadline assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), 0); } - + function testMultipleTimeConstraintChecks() public { // Test that multiple operations respect time constraints advanceToWithinRange(); - + // Use processCryptoPayment which creates and confirms payment in one step vm.prank(users.backer1Address); testToken.approve(address(timeConstrainedPaymentTreasury), PAYMENT_AMOUNT_1); - + vm.prank(users.platform1AdminAddress); ICampaignPaymentTreasury.LineItem[] memory emptyLineItems = new ICampaignPaymentTreasury.LineItem[](0); timeConstrainedPaymentTreasury.processCryptoPayment( @@ -625,16 +622,17 @@ contract TimeConstrainedPaymentTreasury_UnitTest is Test, TimeConstrainedPayment users.backer1Address, address(testToken), PAYMENT_AMOUNT_1, - emptyLineItems - , new ICampaignPaymentTreasury.ExternalFees[](0)); - + emptyLineItems, + new ICampaignPaymentTreasury.ExternalFees[](0) + ); + // Advance to after launch time advanceToAfterLaunch(); - + // Withdraw (should work after launch time) vm.prank(users.platform1AdminAddress); timeConstrainedPaymentTreasury.withdraw(); - + // All operations should succeed assertEq(timeConstrainedPaymentTreasury.getRaisedAmount(), PAYMENT_AMOUNT_1); } diff --git a/test/foundry/unit/TreasuryFactory.t.sol b/test/foundry/unit/TreasuryFactory.t.sol index c3680d0e..e1ea5ff5 100644 --- a/test/foundry/unit/TreasuryFactory.t.sol +++ b/test/foundry/unit/TreasuryFactory.t.sol @@ -27,40 +27,27 @@ contract TreasuryFactory_UpdatedUnitTest is Test, Defaults { function setUp() public { testToken = new TestToken(tokenName, tokenSymbol, 18); - + // Setup currencies and tokens for multi-token support bytes32[] memory currencies = new bytes32[](1); currencies[0] = bytes32("USD"); - + address[][] memory tokensPerCurrency = new address[][](1); tokensPerCurrency[0] = new address[](1); tokensPerCurrency[0][0] = address(testToken); - + // Deploy GlobalParams with proxy GlobalParams globalParamsImpl = new GlobalParams(); - bytes memory globalParamsInitData = abi.encodeWithSelector( - GlobalParams.initialize.selector, - protocolAdmin, - 300, - currencies, - tokensPerCurrency - ); - ERC1967Proxy globalParamsProxy = new ERC1967Proxy( - address(globalParamsImpl), - globalParamsInitData - ); + bytes memory globalParamsInitData = + abi.encodeWithSelector(GlobalParams.initialize.selector, protocolAdmin, 300, currencies, tokensPerCurrency); + ERC1967Proxy globalParamsProxy = new ERC1967Proxy(address(globalParamsImpl), globalParamsInitData); globalParams = GlobalParams(address(globalParamsProxy)); - + // Deploy TreasuryFactory with proxy TreasuryFactory factoryImpl = new TreasuryFactory(); - bytes memory factoryInitData = abi.encodeWithSelector( - TreasuryFactory.initialize.selector, - IGlobalParams(address(globalParams)) - ); - ERC1967Proxy factoryProxy = new ERC1967Proxy( - address(factoryImpl), - factoryInitData - ); + bytes memory factoryInitData = + abi.encodeWithSelector(TreasuryFactory.initialize.selector, IGlobalParams(address(globalParams))); + ERC1967Proxy factoryProxy = new ERC1967Proxy(address(factoryImpl), factoryInitData); factory = TreasuryFactory(address(factoryProxy)); // Label addresses for clarity @@ -68,7 +55,7 @@ contract TreasuryFactory_UpdatedUnitTest is Test, Defaults { vm.label(platformAdmin, "PlatformAdmin"); vm.label(implementation, "Implementation"); vm.startPrank(protocolAdmin); - globalParams.enlistPlatform(platformHash, platformAdmin, platformFee); + globalParams.enlistPlatform(platformHash, platformAdmin, platformFee, address(0)); vm.stopPrank(); } @@ -76,18 +63,10 @@ contract TreasuryFactory_UpdatedUnitTest is Test, Defaults { vm.startPrank(platformAdmin); vm.mockCall( address(globalParams), - abi.encodeWithSignature( - "isPlatformAdmin(bytes32,address)", - platformHash, - platformAdmin - ), + abi.encodeWithSignature("isPlatformAdmin(bytes32,address)", platformHash, platformAdmin), abi.encode(true) ); - factory.registerTreasuryImplementation( - platformHash, - implementationId, - implementation - ); + factory.registerTreasuryImplementation(platformHash, implementationId, implementation); vm.stopPrank(); } @@ -95,19 +74,11 @@ contract TreasuryFactory_UpdatedUnitTest is Test, Defaults { vm.startPrank(platformAdmin); vm.mockCall( address(globalParams), - abi.encodeWithSignature( - "isPlatformAdmin(bytes32,address)", - platformHash, - platformAdmin - ), + abi.encodeWithSignature("isPlatformAdmin(bytes32,address)", platformHash, platformAdmin), abi.encode(true) ); vm.expectRevert(TreasuryFactory.TreasuryFactoryInvalidAddress.selector); - factory.registerTreasuryImplementation( - platformHash, - implementationId, - address(0) - ); + factory.registerTreasuryImplementation(platformHash, implementationId, address(0)); vm.stopPrank(); } @@ -116,18 +87,10 @@ contract TreasuryFactory_UpdatedUnitTest is Test, Defaults { vm.startPrank(platformAdmin); vm.mockCall( address(globalParams), - abi.encodeWithSignature( - "isPlatformAdmin(bytes32,address)", - platformHash, - platformAdmin - ), + abi.encodeWithSignature("isPlatformAdmin(bytes32,address)", platformHash, platformAdmin), abi.encode(true) ); - factory.registerTreasuryImplementation( - platformHash, - implementationId, - implementation - ); + factory.registerTreasuryImplementation(platformHash, implementationId, implementation); vm.stopPrank(); // Then approve as protocol admin @@ -140,54 +103,34 @@ contract TreasuryFactory_UpdatedUnitTest is Test, Defaults { vm.startPrank(platformAdmin); vm.mockCall( address(globalParams), - abi.encodeWithSignature( - "isPlatformAdmin(bytes32,address)", - platformHash, - platformAdmin - ), + abi.encodeWithSignature("isPlatformAdmin(bytes32,address)", platformHash, platformAdmin), abi.encode(true) ); - factory.registerTreasuryImplementation( - platformHash, - implementationId, - implementation - ); + factory.registerTreasuryImplementation(platformHash, implementationId, implementation); - vm.expectRevert( - TreasuryFactory - .TreasuryFactoryImplementationNotSetOrApproved - .selector - ); - factory.deploy( - platformHash, - address(0x1234), - implementationId - ); + vm.expectRevert(TreasuryFactory.TreasuryFactoryImplementationNotSetOrApproved.selector); + factory.deploy(platformHash, address(0x1234), implementationId); vm.stopPrank(); } function testUpgrade() public { // Deploy new implementation TreasuryFactory newImplementation = new TreasuryFactory(); - + // Upgrade as protocol admin vm.prank(protocolAdmin); factory.upgradeToAndCall(address(newImplementation), ""); - + // Factory should still work after upgrade vm.startPrank(platformAdmin); - factory.registerTreasuryImplementation( - platformHash, - implementationId, - implementation - ); + factory.registerTreasuryImplementation(platformHash, implementationId, implementation); vm.stopPrank(); } function testUpgradeUnauthorizedReverts() public { // Deploy new implementation TreasuryFactory newImplementation = new TreasuryFactory(); - + // Try to upgrade as non-protocol-admin (should revert) vm.prank(other); vm.expectRevert(); diff --git a/test/foundry/unit/Upgrades.t.sol b/test/foundry/unit/Upgrades.t.sol index 30bbc6dc..0dbb08e1 100644 --- a/test/foundry/unit/Upgrades.t.sol +++ b/test/foundry/unit/Upgrades.t.sol @@ -20,52 +20,39 @@ contract Upgrades_Test is Test, Defaults { TreasuryFactory internal treasuryFactory; CampaignInfoFactory internal campaignFactory; TestToken internal testToken; - + address internal admin = address(0xA11CE); address internal platformAdmin = address(0xBEEF); address internal attacker = address(0xDEAD); - + bytes32 internal platformHash = keccak256(abi.encodePacked("TEST_PLATFORM")); uint256 internal protocolFee = 300; uint256 internal platformFee = 200; function setUp() public { testToken = new TestToken("Test", "TST", 18); - + bytes32[] memory currencies = new bytes32[](1); currencies[0] = bytes32("USD"); - + address[][] memory tokensPerCurrency = new address[][](1); tokensPerCurrency[0] = new address[](1); tokensPerCurrency[0][0] = address(testToken); - + // Deploy GlobalParams with proxy GlobalParams globalParamsImpl = new GlobalParams(); - bytes memory globalParamsInitData = abi.encodeWithSelector( - GlobalParams.initialize.selector, - admin, - protocolFee, - currencies, - tokensPerCurrency - ); - ERC1967Proxy globalParamsProxy = new ERC1967Proxy( - address(globalParamsImpl), - globalParamsInitData - ); + bytes memory globalParamsInitData = + abi.encodeWithSelector(GlobalParams.initialize.selector, admin, protocolFee, currencies, tokensPerCurrency); + ERC1967Proxy globalParamsProxy = new ERC1967Proxy(address(globalParamsImpl), globalParamsInitData); globalParams = GlobalParams(address(globalParamsProxy)); - + // Deploy TreasuryFactory with proxy TreasuryFactory treasuryFactoryImpl = new TreasuryFactory(); - bytes memory treasuryFactoryInitData = abi.encodeWithSelector( - TreasuryFactory.initialize.selector, - IGlobalParams(address(globalParams)) - ); - ERC1967Proxy treasuryFactoryProxy = new ERC1967Proxy( - address(treasuryFactoryImpl), - treasuryFactoryInitData - ); + bytes memory treasuryFactoryInitData = + abi.encodeWithSelector(TreasuryFactory.initialize.selector, IGlobalParams(address(globalParams))); + ERC1967Proxy treasuryFactoryProxy = new ERC1967Proxy(address(treasuryFactoryImpl), treasuryFactoryInitData); treasuryFactory = TreasuryFactory(address(treasuryFactoryProxy)); - + // Deploy CampaignInfoFactory with proxy CampaignInfo campaignInfoImpl = new CampaignInfo(); CampaignInfoFactory campaignFactoryImpl = new CampaignInfoFactory(); @@ -76,15 +63,12 @@ contract Upgrades_Test is Test, Defaults { address(campaignInfoImpl), address(treasuryFactory) ); - ERC1967Proxy campaignFactoryProxy = new ERC1967Proxy( - address(campaignFactoryImpl), - campaignFactoryInitData - ); + ERC1967Proxy campaignFactoryProxy = new ERC1967Proxy(address(campaignFactoryImpl), campaignFactoryInitData); campaignFactory = CampaignInfoFactory(address(campaignFactoryProxy)); - + // Enlist a platform vm.prank(admin); - globalParams.enlistPlatform(platformHash, platformAdmin, platformFee); + globalParams.enlistPlatform(platformHash, platformAdmin, platformFee, address(0)); } // ============ GlobalParams Upgrade Tests ============ @@ -93,18 +77,18 @@ contract Upgrades_Test is Test, Defaults { // Record initial state uint256 initialFee = globalParams.getProtocolFeePercent(); address initialAdmin = globalParams.getProtocolAdminAddress(); - + // Deploy new implementation GlobalParams newImpl = new GlobalParams(); - + // Upgrade vm.prank(admin); globalParams.upgradeToAndCall(address(newImpl), ""); - + // Verify state is preserved assertEq(globalParams.getProtocolFeePercent(), initialFee); assertEq(globalParams.getProtocolAdminAddress(), initialAdmin); - + // Verify functionality still works vm.prank(admin); globalParams.updateProtocolFeePercent(500); @@ -113,7 +97,7 @@ contract Upgrades_Test is Test, Defaults { function testGlobalParamsUpgradeUnauthorized() public { GlobalParams newImpl = new GlobalParams(); - + // Try to upgrade as non-owner vm.prank(attacker); vm.expectRevert(); @@ -124,17 +108,17 @@ contract Upgrades_Test is Test, Defaults { // Add some data vm.prank(admin); globalParams.addTokenToCurrency(bytes32("EUR"), address(testToken)); - + // Verify data before upgrade address[] memory eurTokens = globalParams.getTokensForCurrency(bytes32("EUR")); assertEq(eurTokens.length, 1); assertEq(eurTokens[0], address(testToken)); - + // Upgrade GlobalParams newImpl = new GlobalParams(); vm.prank(admin); globalParams.upgradeToAndCall(address(newImpl), ""); - + // Verify data after upgrade eurTokens = globalParams.getTokensForCurrency(bytes32("EUR")); assertEq(eurTokens.length, 1); @@ -144,7 +128,7 @@ contract Upgrades_Test is Test, Defaults { function testGlobalParamsCannotInitializeTwice() public { bytes32[] memory currencies = new bytes32[](0); address[][] memory tokensPerCurrency = new address[][](0); - + vm.expectRevert(); globalParams.initialize(admin, protocolFee, currencies, tokensPerCurrency); } @@ -156,14 +140,14 @@ contract Upgrades_Test is Test, Defaults { address mockImpl = address(0xC0DE); vm.prank(platformAdmin); treasuryFactory.registerTreasuryImplementation(platformHash, 1, mockImpl); - + // Deploy new implementation TreasuryFactory newImpl = new TreasuryFactory(); - + // Upgrade as protocol admin vm.prank(admin); treasuryFactory.upgradeToAndCall(address(newImpl), ""); - + // Verify functionality still works after upgrade vm.prank(platformAdmin); treasuryFactory.registerTreasuryImplementation(platformHash, 2, address(0xBEEF)); @@ -171,7 +155,7 @@ contract Upgrades_Test is Test, Defaults { function testTreasuryFactoryUpgradeUnauthorized() public { TreasuryFactory newImpl = new TreasuryFactory(); - + // Try to upgrade as non-protocol-admin vm.prank(attacker); vm.expectRevert(); @@ -183,15 +167,15 @@ contract Upgrades_Test is Test, Defaults { address mockImpl = address(0xC0DE); vm.prank(platformAdmin); treasuryFactory.registerTreasuryImplementation(platformHash, 1, mockImpl); - + vm.prank(admin); treasuryFactory.approveTreasuryImplementation(platformHash, 1); - + // Upgrade TreasuryFactory newImpl = new TreasuryFactory(); vm.prank(admin); treasuryFactory.upgradeToAndCall(address(newImpl), ""); - + // Verify registered implementations are preserved after upgrade // by registering another implementation (which proves the mapping still works) address mockImpl2 = address(0xBEEF); @@ -212,7 +196,7 @@ contract Upgrades_Test is Test, Defaults { platforms[0] = platformHash; bytes32[] memory keys = new bytes32[](0); bytes32[] memory values = new bytes32[](0); - + vm.prank(admin); campaignFactory.createCampaign( address(0xBEEF), @@ -226,17 +210,17 @@ contract Upgrades_Test is Test, Defaults { "ipfs://QmExampleImageURI", "ipfs://QmExampleContractURI" ); - + address campaignBefore = campaignFactory.identifierToCampaignInfo(CAMPAIGN_1_IDENTIFIER_HASH); assertTrue(campaignBefore != address(0), "Campaign not created"); - + // Deploy new implementation CampaignInfoFactory newImpl = new CampaignInfoFactory(); - + // Upgrade as owner vm.prank(admin); campaignFactory.upgradeToAndCall(address(newImpl), ""); - + // Verify previous campaign is still accessible address campaignAfter = campaignFactory.identifierToCampaignInfo(CAMPAIGN_1_IDENTIFIER_HASH); assertEq(campaignAfter, campaignBefore, "Campaign address changed after upgrade"); @@ -245,7 +229,7 @@ contract Upgrades_Test is Test, Defaults { function testCampaignInfoFactoryUpgradeUnauthorized() public { CampaignInfoFactory newImpl = new CampaignInfoFactory(); - + // Try to upgrade as non-owner vm.prank(attacker); vm.expectRevert(); @@ -258,10 +242,10 @@ contract Upgrades_Test is Test, Defaults { platforms[0] = platformHash; bytes32[] memory keys = new bytes32[](0); bytes32[] memory values = new bytes32[](0); - + bytes32 identifier1 = bytes32(uint256(1)); bytes32 identifier2 = bytes32(uint256(2)); - + vm.startPrank(admin); campaignFactory.createCampaign( address(0xBEEF), @@ -275,7 +259,7 @@ contract Upgrades_Test is Test, Defaults { "ipfs://QmExampleImageURI", "ipfs://QmExampleContractURI" ); - + campaignFactory.createCampaign( address(0xCAFE), identifier2, @@ -289,15 +273,15 @@ contract Upgrades_Test is Test, Defaults { "ipfs://QmExampleContractURI" ); vm.stopPrank(); - + address campaign1Before = campaignFactory.identifierToCampaignInfo(identifier1); address campaign2Before = campaignFactory.identifierToCampaignInfo(identifier2); - + // Upgrade CampaignInfoFactory newImpl = new CampaignInfoFactory(); vm.prank(admin); campaignFactory.upgradeToAndCall(address(newImpl), ""); - + // Verify all campaigns are preserved assertEq(campaignFactory.identifierToCampaignInfo(identifier1), campaign1Before); assertEq(campaignFactory.identifierToCampaignInfo(identifier2), campaign2Before); @@ -307,13 +291,10 @@ contract Upgrades_Test is Test, Defaults { function testCampaignInfoFactoryCannotInitializeTwice() public { CampaignInfo campaignInfoImpl = new CampaignInfo(); - + vm.expectRevert(); campaignFactory.initialize( - admin, - IGlobalParams(address(globalParams)), - address(campaignInfoImpl), - address(treasuryFactory) + admin, IGlobalParams(address(globalParams)), address(campaignInfoImpl), address(treasuryFactory) ); } @@ -324,24 +305,24 @@ contract Upgrades_Test is Test, Defaults { GlobalParams newGlobalParamsImpl = new GlobalParams(); TreasuryFactory newTreasuryFactoryImpl = new TreasuryFactory(); CampaignInfoFactory newCampaignFactoryImpl = new CampaignInfoFactory(); - + vm.startPrank(admin); globalParams.upgradeToAndCall(address(newGlobalParamsImpl), ""); treasuryFactory.upgradeToAndCall(address(newTreasuryFactoryImpl), ""); campaignFactory.upgradeToAndCall(address(newCampaignFactoryImpl), ""); vm.stopPrank(); - + // Verify all contracts still function correctly assertEq(globalParams.getProtocolAdminAddress(), admin); - + vm.prank(platformAdmin); treasuryFactory.registerTreasuryImplementation(platformHash, 99, address(0xABCD)); - + bytes32[] memory platforms = new bytes32[](1); platforms[0] = platformHash; bytes32[] memory keys = new bytes32[](0); bytes32[] memory values = new bytes32[](0); - + vm.prank(admin); campaignFactory.createCampaign( address(0xBEEF), @@ -360,13 +341,13 @@ contract Upgrades_Test is Test, Defaults { function testUpgradeDoesNotAffectImplementationContract() public { // The implementation contract itself should not be usable directly GlobalParams standaloneImpl = new GlobalParams(); - + bytes32[] memory currencies = new bytes32[](1); currencies[0] = bytes32("USD"); address[][] memory tokensPerCurrency = new address[][](1); tokensPerCurrency[0] = new address[](1); tokensPerCurrency[0][0] = address(testToken); - + // Should revert because initializers are disabled in constructor vm.expectRevert(); standaloneImpl.initialize(admin, protocolFee, currencies, tokensPerCurrency); @@ -379,14 +360,14 @@ contract Upgrades_Test is Test, Defaults { vm.startPrank(admin); globalParams.updateProtocolFeePercent(999); globalParams.addTokenToCurrency(bytes32("BRL"), address(0x1111)); - globalParams.enlistPlatform(bytes32("NEW_PLATFORM"), address(0x2222), 123); + globalParams.enlistPlatform(bytes32("NEW_PLATFORM"), address(0x2222), 123, address(0)); vm.stopPrank(); - + // Upgrade GlobalParams newImpl = new GlobalParams(); vm.prank(admin); globalParams.upgradeToAndCall(address(newImpl), ""); - + // Verify all data is intact assertEq(globalParams.getProtocolFeePercent(), 999); address[] memory brlTokens = globalParams.getTokensForCurrency(bytes32("BRL")); @@ -395,4 +376,3 @@ contract Upgrades_Test is Test, Defaults { assertTrue(globalParams.checkIfPlatformIsListed(bytes32("NEW_PLATFORM"))); } } - diff --git a/test/foundry/utils/Defaults.sol b/test/foundry/utils/Defaults.sol index 9235f3d2..e590ba50 100644 --- a/test/foundry/utils/Defaults.sol +++ b/test/foundry/utils/Defaults.sol @@ -10,7 +10,7 @@ import {IReward} from "src/interfaces/IReward.sol"; /// @notice Contract with default values used throughout the tests. contract Defaults is Constants, ICampaignData, IReward { //Constant Variables - uint256 public constant PROTOCOL_FEE_PERCENT = 20 * 100; + uint256 public constant PROTOCOL_FEE_PERCENT = 20 * 100; uint256 public constant TOKEN_MINT_AMOUNT = 1_000_000e18; uint256 public constant PLATFORM_FEE_PERCENT = 10 * 100; // 10% bytes32 public constant PLATFORM_1_HASH = keccak256(abi.encodePacked("KickStarter")); @@ -49,7 +49,7 @@ contract Defaults is Constants, ICampaignData, IReward { // Fee Values bytes32 public constant FLAT_FEE_VALUE = bytes32(uint256(100e18)); // 100 token flat fee - bytes32 public constant CUMULATIVE_FLAT_FEE_VALUE = bytes32(uint256(200e18)); // 200 token cumulative fee + bytes32 public constant CUMULATIVE_FLAT_FEE_VALUE = bytes32(uint256(200e18)); // 200 token cumulative fee bytes32 public constant PLATFORM_FEE_VALUE = bytes32(PLATFORM_FEE_PERCENT); // 10% bytes32 public constant VAKI_COMMISSION_VALUE = bytes32(uint256(6 * 100)); // 6% for regular campaigns @@ -192,4 +192,4 @@ contract Defaults is Constants, ICampaignData, IReward { isColombianCreator: true }); } -} \ No newline at end of file +} diff --git a/test/foundry/utils/LogDecoder.sol b/test/foundry/utils/LogDecoder.sol index 53c345bb..d6e8d791 100644 --- a/test/foundry/utils/LogDecoder.sol +++ b/test/foundry/utils/LogDecoder.sol @@ -4,10 +4,7 @@ pragma solidity ^0.8.22; import "forge-std/Test.sol"; abstract contract LogDecoder is Test { - function findLogByTopic( - Vm.Log[] memory logs, - bytes32 topic0 - ) internal pure returns (Vm.Log memory) { + function findLogByTopic(Vm.Log[] memory logs, bytes32 topic0) internal pure returns (Vm.Log memory) { for (uint256 i = 0; i < logs.length; i++) { if (logs[i].topics.length > 0 && logs[i].topics[0] == topic0) { return logs[i]; @@ -16,37 +13,30 @@ abstract contract LogDecoder is Test { revert("Log with specified topic not found"); } - function decodeEventFromLogs( - Vm.Log[] memory logs, - string memory eventSignature, - address expectedEmitter - ) internal pure returns (bytes memory) { + function decodeEventFromLogs(Vm.Log[] memory logs, string memory eventSignature, address expectedEmitter) + internal + pure + returns (bytes memory) + { bytes32 expectedTopic = keccak256(bytes(eventSignature)); for (uint256 i = 0; i < logs.length; i++) { - if ( - logs[i].topics[0] == expectedTopic && - logs[i].emitter == expectedEmitter - ) { + if (logs[i].topics[0] == expectedTopic && logs[i].emitter == expectedEmitter) { return logs[i].data; } } revert("Event not found in logs"); } - function decodeTopicsAndData( - Vm.Log[] memory logs, - string memory eventSignature, - address expectedEmitter - ) internal pure returns (bytes32[] memory topics, bytes memory data) { + function decodeTopicsAndData(Vm.Log[] memory logs, string memory eventSignature, address expectedEmitter) + internal + pure + returns (bytes32[] memory topics, bytes memory data) + { bytes32 expectedTopic = keccak256(bytes(eventSignature)); for (uint256 i = 0; i < logs.length; i++) { - if ( - logs[i].topics.length > 0 && - logs[i].topics[0] == expectedTopic && - logs[i].emitter == expectedEmitter - ) { + if (logs[i].topics.length > 0 && logs[i].topics[0] == expectedTopic && logs[i].emitter == expectedEmitter) { return (logs[i].topics, logs[i].data); } } diff --git a/test/mocks/TestToken.sol b/test/mocks/TestToken.sol index 9f649192..482ad5cd 100644 --- a/test/mocks/TestToken.sol +++ b/test/mocks/TestToken.sol @@ -11,11 +11,10 @@ import {Ownable} from "../../lib/openzeppelin-contracts/contracts/access/Ownable contract TestToken is ERC20, Ownable { uint8 private _decimals; - constructor( - string memory _name, - string memory _symbol, - uint8 decimals_ - ) ERC20(_name, _symbol) Ownable(msg.sender) { + constructor(string memory _name, string memory _symbol, uint8 decimals_) + ERC20(_name, _symbol) + Ownable(msg.sender) + { _decimals = decimals_; } From 559989b0a5193ce638a4721b7c1a048e91056a10 Mon Sep 17 00:00:00 2001 From: mahabubAlahi <32974385+mahabubAlahi@users.noreply.github.com> Date: Tue, 2 Dec 2025 21:16:51 +0600 Subject: [PATCH 55/63] Add Immunefi Audit Report for Creative Crowdfunding v1.0 (#59) --- ...Audit-Report-CreativeCrowdfunding_v1.0.pdf | Bin 0 -> 2817526 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 audits/Immunefi-Audit-Report-CreativeCrowdfunding_v1.0.pdf diff --git a/audits/Immunefi-Audit-Report-CreativeCrowdfunding_v1.0.pdf b/audits/Immunefi-Audit-Report-CreativeCrowdfunding_v1.0.pdf new file mode 100644 index 0000000000000000000000000000000000000000..2b336219d6d539ba127152a3637215ce09dd950a GIT binary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