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

Pessimistic audit followup #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion out/RPSV1.sol/RPSV1.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion out/RPSV1Factory.sol/RPSV1Factory.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions src/RPS/RPSV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ contract RPSV1 is IRPS, Initializable {
uint256 subscriptionCost_,
uint256 frequency_,
uint8 processingFee_
) public initializer {
) external initializer {
require(settlementAddress_ != address(0), "RPS: Invalid settlement address");
require(tokenAddress_ != address(0), "RPS: Invalid token address");
require(YokiHelper.isERC20(tokenAddress_), "RPS: Provided token address is not ERC20");
require(subscriptionCost_ >= 1, "RPS: Subscription cost should be at least 1");
require(frequency_ >= MIN_FREQUENCY, "RPS: Frequency should be at least 1 minute");
require(processingFee_ >= 0 && processingFee_ <= 100, "RPS: Processing fee must be less than 100 (10%)");
require(processingFee_ <= 100, "RPS: Processing fee must be less than 100 (10%)");

merchantName = merchantName_;
settlementAddress = settlementAddress_;
Expand All @@ -60,7 +60,7 @@ contract RPSV1 is IRPS, Initializable {
return true;
}

function subscribe() public {
function subscribe() external {
address subscriber = msg.sender;
require(!isTerminated, "RPS: Contract was terminated");
require(!isSubscriber(subscriber), "RPS: Already subscribed");
Expand Down Expand Up @@ -89,9 +89,6 @@ contract RPSV1 is IRPS, Initializable {
uint256 feeAmount = (subscriptionCost * processingFee) / 1000;
uint256 amountToTransfer = subscriptionCost - feeAmount;

YokiHelper.safeTransferFrom(address(tokenAddress), subscriber, TREASURY, feeAmount);
YokiHelper.safeTransferFrom(address(tokenAddress), subscriber, settlementAddress, amountToTransfer);

uint256 currentExecutionTimestamp = subscriberLastExecutionTimestamp + frequency;
uint256 nextTimestamp = currentExecutionTimestamp + frequency;
// if execute was not called in proper time-period (ex. previouse frequency was skipped) - reset timer
Expand All @@ -103,10 +100,13 @@ contract RPSV1 is IRPS, Initializable {
lastExecutionTimestamp[subscriber] = currentExecutionTimestamp;
}

YokiHelper.safeTransferFrom(address(tokenAddress), subscriber, TREASURY, feeAmount);
YokiHelper.safeTransferFrom(address(tokenAddress), subscriber, settlementAddress, amountToTransfer);

return (nextTimestamp, feeAmount, amountToTransfer);
}

function execute(address subscriber) public returns (uint256 nextExectuionTimestamp) {
function execute(address subscriber) external returns (uint256 nextExectuionTimestamp) {
require(canExecute(subscriber), "RPS: Can't execute");

(uint256 nextExecutionTimestamp, uint256 fee, uint256 transfered) = processPayment(subscriber);
Expand Down Expand Up @@ -149,7 +149,7 @@ contract RPSV1 is IRPS, Initializable {
emit Unsubscribed(address(this), subscriber);
}

function terminate() public {
function terminate() external {
require(msg.sender == settlementAddress, "RPS: Forbidden");
isTerminated = true;
emit Terminated(address(this));
Expand Down