diff --git a/README.md b/README.md index 7f35072..79a04c4 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,16 @@ yarn coverage Configure the `.env` variables. +### Private Key management + +Deployment private keys are encripted using ERC2335. Run: + +```bash +cast wallet import nameOfAccountGoesHere --interactive +``` + +And you will be able to deploy with our scripts + ### Sepolia ```bash diff --git a/src/contracts/Grateful.sol b/src/contracts/Grateful.sol index 093183b..b7dc3a7 100644 --- a/src/contracts/Grateful.sol +++ b/src/contracts/Grateful.sol @@ -106,19 +106,19 @@ contract Grateful is IGrateful, Ownable2Step { address _sender, address _merchant, address _token, - uint256 _AMOUNT_USDC + uint256 _amount ) public view returns (uint256) { - return uint256(keccak256(abi.encodePacked(_sender, _merchant, _token, _AMOUNT_USDC, block.timestamp))); + return uint256(keccak256(abi.encodePacked(_sender, _merchant, _token, _amount, block.timestamp))); } /// @inheritdoc IGrateful - function applyFee(address _merchant, uint256 _AMOUNT_USDC) public view returns (uint256) { + function applyFee(address _merchant, uint256 _amount) public view returns (uint256) { uint256 feePercentage = fee; if (customFees[_merchant].isSet) { feePercentage = customFees[_merchant].fee; } - uint256 feeAmount = (_AMOUNT_USDC * feePercentage) / 10_000; - return _AMOUNT_USDC - feeAmount; + uint256 feeAmount = (_amount * feePercentage) / 10_000; + return _amount - feeAmount; } /// @inheritdoc IGrateful @@ -148,29 +148,29 @@ contract Grateful is IGrateful, Ownable2Step { function pay( address _merchant, address _token, - uint256 _AMOUNT_USDC, + uint256 _amount, uint256 _id ) external onlyWhenTokenWhitelisted(_token) { - _processPayment(msg.sender, _merchant, _token, _AMOUNT_USDC, _id, new address[](0), new uint256[](0)); + _processPayment(msg.sender, _merchant, _token, _amount, _id, new address[](0), new uint256[](0)); } /// @inheritdoc IGrateful function pay( address _merchant, address _token, - uint256 _AMOUNT_USDC, + uint256 _amount, uint256 _id, address[] calldata _recipients, uint256[] calldata _percentages ) external onlyWhenTokenWhitelisted(_token) { - _processPayment(msg.sender, _merchant, _token, _AMOUNT_USDC, _id, _recipients, _percentages); + _processPayment(msg.sender, _merchant, _token, _amount, _id, _recipients, _percentages); } /// @inheritdoc IGrateful function createOneTimePayment( address _merchant, address[] memory _tokens, - uint256 _AMOUNT_USDC, + uint256 _amount, uint256 _salt, uint256 _paymentId, address precomputed, @@ -179,9 +179,9 @@ contract Grateful is IGrateful, Ownable2Step { ) external onlyWhenTokensWhitelisted(_tokens) returns (OneTime oneTime) { oneTimePayments[precomputed] = true; oneTime = new OneTime{salt: bytes32(_salt)}( - IGrateful(address(this)), _tokens, _merchant, _AMOUNT_USDC, _paymentId, _recipients, _percentages + IGrateful(address(this)), _tokens, _merchant, _amount, _paymentId, _recipients, _percentages ); - emit OneTimePaymentCreated(_merchant, _tokens, _AMOUNT_USDC); + emit OneTimePaymentCreated(_merchant, _tokens, _amount); } /// @inheritdoc IGrateful @@ -189,21 +189,21 @@ contract Grateful is IGrateful, Ownable2Step { address _merchant, address _token, uint256 _paymentId, - uint256 _AMOUNT_USDC, + uint256 _amount, address[] calldata _recipients, uint256[] calldata _percentages ) external { if (!oneTimePayments[msg.sender]) { revert Grateful_OneTimeNotFound(); } - _processPayment(msg.sender, _merchant, _token, _AMOUNT_USDC, _paymentId, _recipients, _percentages); + _processPayment(msg.sender, _merchant, _token, _amount, _paymentId, _recipients, _percentages); } /// @inheritdoc IGrateful function computeOneTimeAddress( address _merchant, address[] memory _tokens, - uint256 _AMOUNT_USDC, + uint256 _amount, uint256 _salt, uint256 _paymentId, address[] calldata _recipients, @@ -211,7 +211,7 @@ contract Grateful is IGrateful, Ownable2Step { ) external view returns (OneTime oneTime) { bytes memory bytecode = abi.encodePacked( type(OneTime).creationCode, - abi.encode(address(this), _tokens, _merchant, _AMOUNT_USDC, _paymentId, _recipients, _percentages) + abi.encode(address(this), _tokens, _merchant, _amount, _paymentId, _recipients, _percentages) ); bytes32 bytecodeHash = keccak256(bytecode); bytes32 addressHash = keccak256(abi.encodePacked(bytes1(0xff), address(this), bytes32(_salt), bytecodeHash)); @@ -223,16 +223,16 @@ contract Grateful is IGrateful, Ownable2Step { function createOneTimePayment( address _merchant, address[] memory _tokens, - uint256 _AMOUNT_USDC, + uint256 _amount, uint256 _salt, uint256 _paymentId, address precomputed ) external onlyWhenTokensWhitelisted(_tokens) returns (OneTime oneTime) { oneTimePayments[precomputed] = true; oneTime = new OneTime{salt: bytes32(_salt)}( - IGrateful(address(this)), _tokens, _merchant, _AMOUNT_USDC, _paymentId, new address[](0), new uint256[](0) + IGrateful(address(this)), _tokens, _merchant, _amount, _paymentId, new address[](0), new uint256[](0) ); - emit OneTimePaymentCreated(_merchant, _tokens, _AMOUNT_USDC); + emit OneTimePaymentCreated(_merchant, _tokens, _amount); } /// @inheritdoc IGrateful @@ -240,15 +240,15 @@ contract Grateful is IGrateful, Ownable2Step { address _merchant, IERC20[] memory _tokens, uint256 _paymentId, - uint256 _AMOUNT_USDC + uint256 _amount ) external { if (!oneTimePayments[msg.sender]) { revert Grateful_OneTimeNotFound(); } for (uint256 i = 0; i < _tokens.length; i++) { - if (_tokens[i].balanceOf(msg.sender) >= _AMOUNT_USDC) { + if (_tokens[i].balanceOf(msg.sender) >= _amount) { _processPayment( - msg.sender, _merchant, address(_tokens[i]), _AMOUNT_USDC, _paymentId, new address[](0), new uint256[](0) + msg.sender, _merchant, address(_tokens[i]), _amount, _paymentId, new address[](0), new uint256[](0) ); } } @@ -258,13 +258,13 @@ contract Grateful is IGrateful, Ownable2Step { function computeOneTimeAddress( address _merchant, address[] memory _tokens, - uint256 _AMOUNT_USDC, + uint256 _amount, uint256 _salt, uint256 _paymentId ) external view returns (OneTime oneTime) { bytes memory bytecode = abi.encodePacked( type(OneTime).creationCode, - abi.encode(address(this), _tokens, _merchant, _AMOUNT_USDC, _paymentId, new address[](0), new uint256[](0)) + abi.encode(address(this), _tokens, _merchant, _amount, _paymentId, new address[](0), new uint256[](0)) ); bytes32 bytecodeHash = keccak256(bytecode); bytes32 addressHash = keccak256(abi.encodePacked(bytes1(0xff), address(this), bytes32(_salt), bytecodeHash)); @@ -378,7 +378,7 @@ contract Grateful is IGrateful, Ownable2Step { * @param _sender Address of the sender. * @param _merchant Address of the merchant. * @param _token Address of the token. - * @param _AMOUNT_USDC Amount of the token. + * @param _amount Amount of the token. * @param _paymentId ID of the payment. * @param _recipients List of recipients for payment splitting. * @param _percentages Corresponding percentages for each recipient. @@ -387,13 +387,13 @@ contract Grateful is IGrateful, Ownable2Step { address _sender, address _merchant, address _token, - uint256 _AMOUNT_USDC, + uint256 _amount, uint256 _paymentId, address[] memory _recipients, uint256[] memory _percentages ) internal { // Transfer the full amount from the sender to this contract - IERC20(_token).safeTransferFrom(_sender, address(this), _AMOUNT_USDC); + IERC20(_token).safeTransferFrom(_sender, address(this), _amount); // Check payment id if (paymentIds[_paymentId]) { @@ -401,10 +401,10 @@ contract Grateful is IGrateful, Ownable2Step { } // Apply the fee - uint256 amountWithFee = applyFee(_merchant, _AMOUNT_USDC); + uint256 amountWithFee = applyFee(_merchant, _amount); // Transfer fee to owner - IERC20(_token).safeTransfer(owner(), _AMOUNT_USDC - amountWithFee); + IERC20(_token).safeTransfer(owner(), _amount - amountWithFee); // If payment splitting is requested if (_recipients.length > 0) { @@ -455,6 +455,6 @@ contract Grateful is IGrateful, Ownable2Step { paymentIds[_paymentId] = true; - emit PaymentProcessed(_sender, _merchant, _token, _AMOUNT_USDC, yieldingFunds[_merchant], _paymentId); + emit PaymentProcessed(_sender, _merchant, _token, _amount, yieldingFunds[_merchant], _paymentId); } } diff --git a/src/contracts/OneTime.sol b/src/contracts/OneTime.sol index e385767..04d5a05 100644 --- a/src/contracts/OneTime.sol +++ b/src/contracts/OneTime.sol @@ -17,7 +17,7 @@ contract OneTime { IGrateful _grateful, address[] memory _tokens, address _merchant, - uint256 _AMOUNT_USDC, + uint256 _amount, uint256 _paymentId, address[] memory _recipients, uint256[] memory _percentages @@ -26,18 +26,18 @@ contract OneTime { for (uint256 i = 0; i < _tokens.length; i++) { IERC20 token = IERC20(_tokens[i]); - if (token.balanceOf(address(this)) >= _AMOUNT_USDC) { - token.safeIncreaseAllowance(address(_grateful), _AMOUNT_USDC); - _grateful.receiveOneTimePayment(_merchant, address(token), _paymentId, _AMOUNT_USDC, _recipients, _percentages); + if (token.balanceOf(address(this)) >= _amount) { + token.safeIncreaseAllowance(address(_grateful), _amount); + _grateful.receiveOneTimePayment(_merchant, address(token), _paymentId, _amount, _recipients, _percentages); } } } - function rescueFunds(IERC20 _token, address _receiver, uint256 _AMOUNT_USDC) external { + function rescueFunds(IERC20 _token, address _receiver, uint256 _amount) external { if (msg.sender != grateful.owner()) { revert Ownable.OwnableUnauthorizedAccount(msg.sender); } - IERC20(_token).safeTransfer(_receiver, _AMOUNT_USDC); + IERC20(_token).safeTransfer(_receiver, _amount); } } diff --git a/src/interfaces/IGrateful.sol b/src/interfaces/IGrateful.sol index 89d2ac2..6019b9d 100644 --- a/src/interfaces/IGrateful.sol +++ b/src/interfaces/IGrateful.sol @@ -172,16 +172,16 @@ interface IGrateful { * @notice Makes a payment to a merchant. * @param _merchant Address of the merchant receiving payment. * @param _token Address of the token used for payment. - * @param _AMOUNT_USDC Amount of the token to be paid. + * @param _amount Amount of the token to be paid. * @param _id ID of the payment. */ - function pay(address _merchant, address _token, uint256 _AMOUNT_USDC, uint256 _id) external; + function pay(address _merchant, address _token, uint256 _amount, uint256 _id) external; /** * @notice Makes a payment to a merchant with payment splitting. * @param _merchant Address of the merchant receiving payment. * @param _token Address of the token used for payment. - * @param _AMOUNT_USDC Amount of the token to be paid. + * @param _amount Amount of the token to be paid. * @param _id ID of the payment. * @param _recipients List of recipients for payment splitting. * @param _percentages Corresponding percentages for each recipient (in basis points, 10000 = 100%). @@ -189,7 +189,7 @@ interface IGrateful { function pay( address _merchant, address _token, - uint256 _AMOUNT_USDC, + uint256 _amount, uint256 _id, address[] calldata _recipients, uint256[] calldata _percentages @@ -199,7 +199,7 @@ interface IGrateful { * @notice Creates a one-time payment with payment splitting. * @param _merchant Address of the merchant. * @param _tokens Array of token addresses. - * @param _AMOUNT_USDC Amount of the token. + * @param _amount Amount of the token. * @param _salt Salt used for address computation. * @param _paymentId ID of the payment. * @param precomputed Precomputed address of the OneTime contract. @@ -210,7 +210,7 @@ interface IGrateful { function createOneTimePayment( address _merchant, address[] memory _tokens, - uint256 _AMOUNT_USDC, + uint256 _amount, uint256 _salt, uint256 _paymentId, address precomputed, @@ -222,7 +222,7 @@ interface IGrateful { * @notice Creates a one-time payment without payment splitting. * @param _merchant Address of the merchant. * @param _tokens Array of token addresses. - * @param _AMOUNT_USDC Amount of the token. + * @param _amount Amount of the token. * @param _salt Salt used for address computation. * @param _paymentId ID of the payment. * @param precomputed Precomputed address of the OneTime contract. @@ -231,7 +231,7 @@ interface IGrateful { function createOneTimePayment( address _merchant, address[] memory _tokens, - uint256 _AMOUNT_USDC, + uint256 _amount, uint256 _salt, uint256 _paymentId, address precomputed @@ -242,7 +242,7 @@ interface IGrateful { * @param _merchant Address of the merchant. * @param _token Address of the token. * @param _paymentId ID of the payment. - * @param _AMOUNT_USDC Amount of the token. + * @param _amount Amount of the token. * @param _recipients List of recipients for payment splitting. * @param _percentages Corresponding percentages for each recipient. */ @@ -250,7 +250,7 @@ interface IGrateful { address _merchant, address _token, uint256 _paymentId, - uint256 _AMOUNT_USDC, + uint256 _amount, address[] calldata _recipients, uint256[] calldata _percentages ) external; @@ -260,20 +260,20 @@ interface IGrateful { * @param _merchant Address of the merchant. * @param _tokens Array of token addresses. * @param _paymentId ID of the payment. - * @param _AMOUNT_USDC Amount of the token. + * @param _amount Amount of the token. */ function receiveOneTimePayment( address _merchant, IERC20[] memory _tokens, uint256 _paymentId, - uint256 _AMOUNT_USDC + uint256 _amount ) external; /** * @notice Computes the address of a one-time payment contract with payment splitting. * @param _merchant Address of the merchant. * @param _tokens Array of token addresses. - * @param _AMOUNT_USDC Amount of the token. + * @param _amount Amount of the token. * @param _salt Salt used for address computation. * @param _paymentId ID of the payment. * @param _recipients List of recipients for payment splitting. @@ -283,7 +283,7 @@ interface IGrateful { function computeOneTimeAddress( address _merchant, address[] memory _tokens, - uint256 _AMOUNT_USDC, + uint256 _amount, uint256 _salt, uint256 _paymentId, address[] calldata _recipients, @@ -294,7 +294,7 @@ interface IGrateful { * @notice Computes the address of a one-time payment contract without payment splitting. * @param _merchant Address of the merchant. * @param _tokens Array of token addresses. - * @param _AMOUNT_USDC Amount of the token. + * @param _amount Amount of the token. * @param _salt Salt used for address computation. * @param _paymentId ID of the payment. * @return oneTime Address of the computed OneTime contract. @@ -302,7 +302,7 @@ interface IGrateful { function computeOneTimeAddress( address _merchant, address[] memory _tokens, - uint256 _AMOUNT_USDC, + uint256 _amount, uint256 _salt, uint256 _paymentId ) external view returns (OneTime oneTime); @@ -347,23 +347,23 @@ interface IGrateful { * @param _sender Address of the sender. * @param _merchant Address of the merchant. * @param _token Address of the token. - * @param _AMOUNT_USDC Amount of the token. + * @param _amount Amount of the token. * @return id ID of the payment. */ function calculateId( address _sender, address _merchant, address _token, - uint256 _AMOUNT_USDC + uint256 _amount ) external view returns (uint256 id); /** * @notice Applies the fee to an amount. * @param _merchant Address of the merchant. - * @param _AMOUNT_USDC Amount before fee. + * @param _amount Amount before fee. * @return amountWithFee Amount after fee is applied. */ - function applyFee(address _merchant, uint256 _AMOUNT_USDC) external view returns (uint256 amountWithFee); + function applyFee(address _merchant, uint256 _amount) external view returns (uint256 amountWithFee); /** * @notice Sets a new fee.