Skip to content

Commit

Permalink
chore: add docstrings to contract, remove unused interface
Browse files Browse the repository at this point in the history
  • Loading branch information
woodenfurniture committed Apr 11, 2024
1 parent 14c2976 commit 9b16916
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 64 deletions.
26 changes: 25 additions & 1 deletion foundry/src/FoxStakingV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/U
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol";
import {IFoxStaking, StakingInfo} from "./IFoxStaking.sol";
import {StakingInfo} from "./StakingInfo.sol";

contract FoxStakingV1 is
Initializable,
Expand Down Expand Up @@ -61,34 +61,42 @@ contract FoxStakingV1 is
return _getInitializedVersion();
}

/// @notice Pauses deposits
function pauseStaking() external onlyOwner {
stakingPaused = true;
}

/// @notice Unpauses deposits
function unpauseStaking() external onlyOwner {
stakingPaused = false;
}

/// @notice Pauses withdrawals
function pauseWithdrawals() external onlyOwner {
withdrawalsPaused = true;
}

/// @notice Unpauses withdrawals
function unpauseWithdrawals() external onlyOwner {
withdrawalsPaused = false;
}

/// @notice Pauses unstaking
function pauseUnstaking() external onlyOwner {
unstakingPaused = true;
}

/// @notice Unpauses unstaking
function unpauseUnstaking() external onlyOwner {
unstakingPaused = false;
}

/// @notice Sets contract-level paused state
function pause() external onlyOwner {
_pause();
}

/// @notice Sets contract-level unpaused state
function unpause() external onlyOwner {
_unpause();
}
Expand All @@ -113,6 +121,10 @@ contract FoxStakingV1 is
emit UpdateCooldownPeriod(newCooldownPeriod);
}

/// @notice Allows a user to stake a specified amount of FOX tokens and assign a RUNE address for rewards - which can be changed later on.
/// This has to be initiated by the user itself i.e msg.sender only, cannot be called by an address for another
/// @param amount The amount of FOX tokens to be staked.
/// @param runeAddress The RUNE address to be associated with the user's staked FOX position.
function stake(
uint256 amount,
string memory runeAddress
Expand All @@ -130,6 +142,9 @@ contract FoxStakingV1 is
emit Stake(msg.sender, amount, runeAddress);
}

/// @notice Initiates the unstake process for a specified amount of FOX, starting the cooldown period (28 days).
/// This has to be initiated by the user itself i.e msg.sender only, cannot be called by an address for another
/// @param amount The amount of FOX tokens to be unstaked.
function unstake(
uint256 amount
) external whenNotPaused whenUnstakingNotPaused {
Expand All @@ -152,6 +167,8 @@ contract FoxStakingV1 is
emit Unstake(msg.sender, amount);
}

/// @notice Withdraws FOX tokens - assuming there's anything to withdraw and unstake cooldown period has completed - else reverts
/// This has to be initiated by the user itself i.e msg.sender only, cannot be called by an address for another
function withdraw() external whenNotPaused whenWithdrawalsNotPaused {
StakingInfo storage info = stakingInfo[msg.sender];

Expand All @@ -163,6 +180,9 @@ contract FoxStakingV1 is
emit Withdraw(msg.sender, withdrawAmount);
}

/// @notice Allows a user to initially set (or update) their THORChain (RUNE) address for receiving staking rewards.
/// This has to be initiated by the user itself i.e msg.sender only, cannot be called by an address for another
/// @param runeAddress The new RUNE address to be associated with the user's staked FOX position.
function setRuneAddress(string memory runeAddress) external {
require(
bytes(runeAddress).length == 43,
Expand All @@ -174,6 +194,10 @@ contract FoxStakingV1 is
emit SetRuneAddress(msg.sender, oldRuneAddress, runeAddress);
}

/// @notice View the staked balance of FOX tokens for a given address.
/// 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) {
StakingInfo memory info = stakingInfo[account];
return info.stakingBalance + info.unstakingBalance;
Expand Down
62 changes: 0 additions & 62 deletions foundry/src/IFoxStaking.sol

This file was deleted.

9 changes: 9 additions & 0 deletions foundry/src/StakingInfo.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.25;

struct StakingInfo {
uint256 stakingBalance;
uint256 unstakingBalance;
uint256 cooldownExpiry;
string runeAddress;
}
2 changes: 1 addition & 1 deletion foundry/test/FoxStakingTestUpgrades.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/U
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {IFoxStaking, StakingInfo} from "../src/IFoxStaking.sol";
import {StakingInfo} from "../src/StakingInfo.sol";

/// @custom:oz-upgrades-from FoxStakingV1
contract MockFoxStakingV2 is
Expand Down

0 comments on commit 9b16916

Please sign in to comment.