Skip to content

Commit

Permalink
feat: 1 smart contract per activity
Browse files Browse the repository at this point in the history
  • Loading branch information
andresaiello committed Oct 31, 2024
1 parent a857666 commit e076ca4
Show file tree
Hide file tree
Showing 4 changed files with 414 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ contract InstantRewards is Ownable2Step, Pausable, ReentrancyGuard, EIP712 {
if (block.timestamp > claimData.sigExpiration) revert SignatureExpired();
}

function claim(ClaimData memory claimData) external nonReentrant whenNotPaused {
function claim(ClaimData memory claimData) public virtual nonReentrant whenNotPaused {
claimData.to = msg.sender;
_verify(claimData);

Expand All @@ -72,7 +72,7 @@ contract InstantRewards is Ownable2Step, Pausable, ReentrancyGuard, EIP712 {
emit SignerUpdated(signerAddress_);
}

function withdraw(address wallet, uint256 amount) external onlyOwner {
function withdraw(address wallet, uint256 amount) public virtual onlyOwner {
if (wallet == address(0)) revert InvalidAddress();
if (amount > address(this).balance) revert TransferFailed();
(bool success, ) = wallet.call{value: amount}("");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/access/Ownable2Step.sol";
import "./InstantRewardsV2.sol";

contract InstantRewardsFactory is Ownable2Step {
event InstantRewardsCreated(address indexed instantRewards, address indexed owner);

function createInstantRewards(
address signerAddress,
uint256 start,
uint256 end,
string memory name
) external returns (address) {
InstantRewardsV2 instantRewards = new InstantRewardsV2(signerAddress, owner(), start, end, name);
instantRewards.transferOwnership(owner());
emit InstantRewardsCreated(address(instantRewards), owner());
return address(instantRewards);
}

Check notice

Code scanning / Slither

Reentrancy vulnerabilities Low

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "./InstantRewards.sol";

contract InstantRewardsV2 is InstantRewards {
string public name;

uint256 public start;
uint256 public end;

event TimeframeUpdated(uint256 start, uint256 end);

error InvalidTimeframe();
error InstantRewardNotActive();
error InstantRewardStillActive();

constructor(
address signerAddress_,
address owner,
uint256 start_,
uint256 end_,
string memory name_
) InstantRewards(signerAddress_, owner) {
if (signerAddress_ == address(0)) revert InvalidAddress();
if (start_ > end_) revert InvalidTimeframe();
start = start_;
end = end_;
name = name_;
}

function isActive() public view returns (bool) {
return block.timestamp >= start && block.timestamp <= end;
}

Check notice

Code scanning / Slither

Block timestamp Low

InstantRewardsV2.isActive() uses timestamp for comparisons
Dangerous comparisons:
- block.timestamp >= start && block.timestamp <= end

function setTimeframe(uint256 start_, uint256 end_) external onlyOwner {
if (start_ > end_) revert InvalidTimeframe();
if (start_ < block.timestamp || end_ < block.timestamp) revert InvalidTimeframe();
if (isActive()) revert InstantRewardStillActive();
start = start_;
end = end_;
emit TimeframeUpdated(start_, end_);
}

Check notice

Code scanning / Slither

Block timestamp Low


function claim(ClaimData memory claimData) public override {
if (!isActive()) revert InstantRewardNotActive();
super.claim(claimData);
}

function withdraw(address wallet, uint256 amount) public override {
if (isActive()) revert InstantRewardStillActive();
super.withdraw(wallet, amount);
}
}
Loading

0 comments on commit e076ca4

Please sign in to comment.