Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sender fee shouldn't be more than 5% of order amount #28

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions contracts/Paycrest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ contract Paycrest is IPaycrest, PaycrestSettingManager, PausableUpgradeable {
string calldata messageHash
) external whenNotPaused() returns(bytes32 orderId) {
// checks that are required
_handler(_token, _amount, _refundAddress, _institutionCode);
// require that sender fee is less than protocol fee
require(_senderFee <= (_amount * protocolFeePercent) / MAX_BPS, "SenderFeeTooHigh");
// first transfer token from msg.sender
_handler(_token, _amount, _refundAddress, _senderFeeRecipient, _senderFee, _institutionCode);

// transfer token from msg.sender to contract
IERC20(_token).transferFrom(msg.sender, address(this), _amount);

// increase users nonce to avoid replay attacks
_nonce[msg.sender] ++;
// @chibie @5ran6
// @todo sender fee should have limit, let say the maximum amount of sender fee should be 1% of the amount

// generate transaction id for the transaction
orderId = keccak256(abi.encode(msg.sender, _nonce[msg.sender]));

// update transaction
order[orderId] = Order({
seller: msg.sender,
Expand All @@ -92,16 +92,21 @@ contract Paycrest is IPaycrest, PaycrestSettingManager, PausableUpgradeable {
currentBPS: uint64(MAX_BPS),
amount: _amount
});

// emit deposit event
emit Deposit(_token, _amount, orderId, _rate, _institutionCode, _label, messageHash);
}

function _handler(address _token, uint256 _amount, address _refundAddress, bytes32 _institutionCode) internal view {
// use require for all the custom errors
function _handler(address _token, uint256 _amount, address _refundAddress, address _senderFeeRecipient, uint256 _senderFee, bytes32 _institutionCode) internal view {
require(_isTokenSupported[_token], "TokenNotSupported");
require(_amount > 0, "AmountIsZero");
require(_refundAddress != address(0), "ThrowZeroAddress");
require(supportedInstitutionsByCode[_institutionCode].name != bytes32(0), "InvalidInstitutionCode");

if (_senderFee > 0) {
require(_senderFeeRecipient != address(0), "InvalidSenderFeeRecipient");
}
require(_senderFee <= (_amount * 500) / MAX_BPS, "SenderFeeTooHigh");
OnahProsperity marked this conversation as resolved.
Show resolved Hide resolved
}

/* ##################################################################
Expand Down
6 changes: 3 additions & 3 deletions contracts/PaycrestSettingManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

contract PaycrestSettingManager is OwnableUpgradeable {
struct Institution {
bytes32 code; // usually not more than 8 letters
bytes32 name; //
bytes32 code;
bytes32 name;
}
struct InstitutionByCode {
bytes32 name;
bytes32 currency;
}
uint256 internal MAX_BPS;
uint64 internal protocolFeePercent; // 5%
uint64 internal protocolFeePercent;
address internal feeRecipient;
address internal _aggregatorAddress;
bytes internal _aggregator;
Expand Down
4 changes: 2 additions & 2 deletions contracts/interface/IPaycrestStake.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

/**
* @author Chef Photons, Vaultka Team serving high quality drinks; drink responsibly.
* @author Paycrest Team
* Factory and global config params
*/
interface IPaycrestStake {
Expand Down