Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
gomesalexandre committed Apr 10, 2024
1 parent e18e30a commit 727d05c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 33 deletions.
66 changes: 41 additions & 25 deletions foundry/src/FoxStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";
import {IFoxStaking, StakingInfo} from "./IFoxStaking.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

contract FoxStaking is
IFoxStaking,
Ownable(msg.sender), // Deployer is the owner
Pausable
{
contract FoxStaking is
IFoxStaking,
Ownable(msg.sender), // Deployer is the owner
Pausable
{
using SafeERC20 for IERC20;
IERC20 public foxToken;
mapping(address => StakingInfo) public stakingInfo;
Expand All @@ -24,29 +24,37 @@ contract FoxStaking is

event UpdateCooldownPeriod(uint256 newCooldownPeriod);

event Stake(address indexed account, uint256 amount, string indexed runeAddress);
event Stake(
address indexed account,
uint256 amount,
string indexed runeAddress
);
event Unstake(address indexed account, uint256 amount);
event Withdraw(address indexed account, uint256 amount);
event SetRuneAddress(address indexed account, string indexed oldRuneAddress, string indexed newRuneAddress);
event SetRuneAddress(
address indexed account,
string indexed oldRuneAddress,
string indexed newRuneAddress
);

constructor(address foxTokenAddress) {
foxToken = IERC20(foxTokenAddress);
}

function pauseStaking() external onlyOwner {
stakingPaused = true;
stakingPaused = true;
}

function unpauseStaking() external onlyOwner {
stakingPaused = false;
stakingPaused = false;
}

function pauseWithdrawals() external onlyOwner {
withdrawalsPaused = true;
withdrawalsPaused = true;
}

function unpauseWithdrawals() external onlyOwner {
withdrawalsPaused = false;
withdrawalsPaused = false;
}

function pauseUnstaking() external onlyOwner {
Expand All @@ -66,27 +74,33 @@ contract FoxStaking is
}

modifier whenStakingNotPaused() {
require(!stakingPaused, "Staking is paused");
_;
require(!stakingPaused, "Staking is paused");
_;
}

modifier whenUnstakingNotPaused() {
require(!unstakingPaused, "Unstaking is paused");
_;
require(!unstakingPaused, "Unstaking is paused");
_;
}

modifier whenWithdrawalsNotPaused() {
require(!withdrawalsPaused, "Withdrawals are paused");
_;
require(!withdrawalsPaused, "Withdrawals are paused");
_;
}

function setCooldownPeriod(uint256 newCooldownPeriod) external onlyOwner {
cooldownPeriod = newCooldownPeriod;
emit UpdateCooldownPeriod(newCooldownPeriod);
}

function stake(uint256 amount, string memory runeAddress) external whenNotPaused whenStakingNotPaused {
require(bytes(runeAddress).length == 43, "Rune address must be 43 characters");
function stake(
uint256 amount,
string memory runeAddress
) external whenNotPaused whenStakingNotPaused {
require(
bytes(runeAddress).length == 43,
"Rune address must be 43 characters"
);
require(amount > 0, "FOX amount to stake must be greater than 0");
foxToken.safeTransferFrom(msg.sender, address(this), amount);

Expand All @@ -96,7 +110,9 @@ contract FoxStaking is
emit Stake(msg.sender, amount, runeAddress);
}

function unstake(uint256 amount) external whenNotPaused whenUnstakingNotPaused {
function unstake(
uint256 amount
) external whenNotPaused whenUnstakingNotPaused {
require(amount > 0, "Cannot unstake 0");
StakingInfo storage info = stakingInfo[msg.sender];

Expand All @@ -120,18 +136,18 @@ contract FoxStaking is
StakingInfo storage info = stakingInfo[msg.sender];

require(info.unstakingBalance > 0, "Cannot withdraw 0");
require(
block.timestamp >= info.cooldownExpiry,
"Not cooled down yet"
);
require(block.timestamp >= info.cooldownExpiry, "Not cooled down yet");
uint256 withdrawAmount = info.unstakingBalance;
info.unstakingBalance = 0;
foxToken.safeTransfer(msg.sender, withdrawAmount);
emit Withdraw(msg.sender, withdrawAmount);
}

function setRuneAddress(string memory runeAddress) external {
require(bytes(runeAddress).length == 43, "Rune address must be 43 characters");
require(
bytes(runeAddress).length == 43,
"Rune address must be 43 characters"
);
StakingInfo storage info = stakingInfo[msg.sender];
string memory oldRuneAddress = info.runeAddress;
info.runeAddress = runeAddress;
Expand Down
13 changes: 5 additions & 8 deletions foundry/src/IFoxStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
pragma solidity ^0.8.25;

struct StakingInfo {
uint256 stakingBalance;
uint256 unstakingBalance;
uint256 cooldownExpiry;
string runeAddress;
uint256 stakingBalance;
uint256 unstakingBalance;
uint256 cooldownExpiry;
string runeAddress;
}


/// @notice This interface outlines the functions for staking FOX tokens, managing RUNE addresses for rewards, and claiming 'em.
interface IFoxStaking {
/// @notice Pauses deposits
Expand Down Expand Up @@ -59,7 +58,5 @@ interface IFoxStaking {
/// This can be initiated by any address with any address as param, as this has view modifier i.e everything is public on-chain
/// @param account The address we're getting the staked FOX balance for.
/// @return total The total amount of FOX tokens held.
function balanceOf(
address account
) external view returns (uint256 total);
function balanceOf(address account) external view returns (uint256 total);
}

0 comments on commit 727d05c

Please sign in to comment.