Skip to content

Commit

Permalink
feat: sender fee shouldn't be more than 5% of order amount
Browse files Browse the repository at this point in the history
  • Loading branch information
chibie committed Dec 19, 2023
1 parent ad6286e commit a95ae3f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
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");
}

/* ##################################################################
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

0 comments on commit a95ae3f

Please sign in to comment.