Skip to content

Commit

Permalink
refactor: Add an onlyOWner function to set the gas limit for hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
mgnfy-view committed Nov 2, 2024
1 parent 4ef2113 commit 50d8783
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 3 additions & 1 deletion script/DeployPayStreams.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import { PayStreams } from "../src/PayStreams.sol";
contract DeployPayStreams is Script {
uint16 public feeInBasisPoints;
address public pyusd;
uint256 public gasLimitForHooks;

function run() external returns (address) {
feeInBasisPoints = 10;
pyusd = 0xCaC524BcA292aaade2DF8A05cC58F0a65B1B3bB9;
gasLimitForHooks = 1_000_000;

vm.startBroadcast();
PayStreams stream = new PayStreams(feeInBasisPoints);
PayStreams stream = new PayStreams(feeInBasisPoints, gasLimitForHooks);
vm.stopBroadcast();

return address(stream);
Expand Down
22 changes: 21 additions & 1 deletion src/PayStreams.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ contract PayStreams is Ownable, IPayStreams {
* @notice Initializes the owner and the fee value in basis points.
* @param _feeInBasisPoints The fee value in basis points.
*/
constructor(uint16 _feeInBasisPoints) Ownable(msg.sender) {
constructor(uint16 _feeInBasisPoints, uint256 _gasLimitForHooks) Ownable(msg.sender) {
if (_feeInBasisPoints > BASIS_POINTS) revert PayStreams__InvalidFeeInBasisPoints(_feeInBasisPoints);
s_feeInBasisPoints = _feeInBasisPoints;
s_gasLimitForHooks = _gasLimitForHooks;
}

/**
Expand All @@ -70,6 +71,17 @@ contract PayStreams is Ownable, IPayStreams {
emit FeeInBasisPointsSet(_feeInBasisPoints);
}

/**
* @notice Allows the owner to set the gas limit for hooks.
* @param _gasLimitForHooks The gas limit for hooks.
*/
function setGasLimitForHooks(uint16 _gasLimitForHooks) external onlyOwner {
if (_gasLimitForHooks == 0) revert PayStreams__GasLimitZero();
s_gasLimitForHooks = _gasLimitForHooks;

emit GasLimitForHooksSet(_gasLimitForHooks);
}

/**
* @notice Allows the owner to withdraw any collected fees.
* @param _token The address of the token.
Expand Down Expand Up @@ -356,6 +368,14 @@ contract PayStreams is Ownable, IPayStreams {
return s_recipientToStreamHashes[_recipient];
}

/**
* @notice Gets the gas limit for hooks.
* @return The gas limit for hooks.
*/
function getGasLimitForHooks() external view returns (uint256) {
return s_gasLimitForHooks;
}

/**
* @notice Computes the hash of a stream from the streamer, recipient, token addresses and a string tag.
* @param _streamer The address of the stream creator.
Expand Down
3 changes: 3 additions & 0 deletions src/interfaces/IPayStreams.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ interface IPayStreams {

event FeeRecipientSet(address indexed newFeeRecipient);
event FeeInBasisPointsSet(uint16 indexed _feeInBasisPoints);
event GasLimitForHooksSet(uint256 gasLimitForHooks);
event TokenSet(address indexed token, bool indexed support);
event StreamCreated(bytes32 indexed streamHash);
event FeesCollected(address indexed token, uint256 indexed amount);
Expand All @@ -84,6 +85,7 @@ interface IPayStreams {

error PayStreams__AddressZero();
error PayStreams__InvalidFeeInBasisPoints(uint16 feeInBasisPoints);
error PayStreams__GasLimitZero();
error PayStreams__InsufficientCollectedFees();
error PayStreams__InvalidStreamConfig();
error PayStreams__StreamAlreadyExists(bytes32 streamHash);
Expand All @@ -93,6 +95,7 @@ interface IPayStreams {
error PayStreams__ZeroAmountToCollect();

function setFeeInBasisPoints(uint16 _feeInBasisPoints) external;
function setGasLimitForHooks(uint16 _gasLimitForHooks) external;
function collectFees(address _token, uint256 _amount) external;
function setStream(
StreamData calldata _streamData,
Expand Down

0 comments on commit 50d8783

Please sign in to comment.