Skip to content

Commit

Permalink
add faq
Browse files Browse the repository at this point in the history
  • Loading branch information
anajuliabit committed Jun 10, 2024
1 parent 96ae6a6 commit 553276c
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 19 deletions.
7 changes: 6 additions & 1 deletion docs/simplified-staking-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ The architecture consists of two contracts:

The contracts are designed to be customizable, with adjustable parameters such as the lock period, minimum stake, and reward emission. Additionally, the contracts uses the Transparent Proxy pattern, where only the DAO has the permission to upgrade the contract and call the owner functions defined below.

## FAQ

1. There is a end date for the rewards distribution?
2. Is the stkSHU token transferable?

## Requirements

1. Compound at each interaction
Expand Down Expand Up @@ -84,7 +89,7 @@ struct Stake {
anyone interacts with state changes functions. This includes staking, unstaking, and claiming rewards.
As the contract balance of SHU and other reward tokens increases, when the
keyper decides to claim the rewards, they will get a better conversion rate from
shares (xSHU) to the reward token. As the staking token is SHU, when the rewards
shares (stkSHU) to the reward token. As the staking token is SHU, when the rewards
are claimed, the SHU balance of the contract increases, causing a coumpound effect.
- For unstaking, the keyper also gets the SHU rewards accumulated.
- The reward earned by a user is proportional to the amount they have
Expand Down
1 change: 1 addition & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@openzeppelin=lib/openzeppelin-contracts/
@openzeppelin-upgradeable=lib/openzeppelin-contracts-upgradeable/
81 changes: 63 additions & 18 deletions src/Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,91 @@
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable2Step.sol";
import {Ownable2StepUpgradeable} from "@openzeppelin-upgradeable/contracts/access/Ownable2StepUpgradeable.sol";

contract Staking is Ownable2Step {
event Staked(
address indexed user,
uint256 indexed amount,
uint256 indexed shares,
uint256 lockPeriod
);
event Unstaked(address user, uint256 amount, uint256 shares);
event ClaimRewards(address user, address rewardToken, uint256 rewards);
interface IRewardsDistributor {
function distributeRewards() external;
}

contract Staking is Ownable2StepUpgradeable {
//// ------------------------------------------------------------
//// ------------------------------------------------------------
//// ------------------- State Variables ------------------------
//// ------------------------------------------------------------
//// ------------------------------------------------------------

IERC20 public immutable shu;
RewardsDistributor public rewardsDistributor;
IERC20 public shu;
IRewardsDistributor public rewardsDistributor;
uint256 public totalSupply;
uint256 public lockPeriod; // lock period in seconds
uint256 public minStake;

//// ------------------------------------------------------------
//// ------------------------------------------------------------
//// ----------------------- Structs ----------------------------
//// ------------------------------------------------------------
//// ------------------------------------------------------------

struct Stake {
uint256 amount;
uint256 shares;
uint256 timestamp;
uint256 lockPeriod;
}

//// ------------------------------------------------------------
//// ------------------------------------------------------------
//// ------------------ Mappings/Arrays -------------------------
//// ------------------------------------------------------------
//// ------------------------------------------------------------

mapping(address keyper => Stake[]) public userStakes;

Check warning on line 43 in src/Staking.sol

View workflow job for this annotation

GitHub Actions / lint

Value parameter in mapping userStakes is not named
mapping(address keyper => uint256) public balances;

Check warning on line 44 in src/Staking.sol

View workflow job for this annotation

GitHub Actions / lint

Value parameter in mapping balances is not named
mapping(address keyper => bool isKeyper) public keypers;

address[] public rewardTokenList;

//// ------------------------------------------------------------
//// ------------------------------------------------------------
//// ------------------------ Events ----------------------------
//// ------------------------------------------------------------

event Staked(
address indexed user,
uint256 indexed amount,
uint256 indexed shares,
uint256 lockPeriod
);
event Unstaked(address user, uint256 amount, uint256 shares);
event ClaimRewards(address user, address rewardToken, uint256 rewards);

/// @notice ensure logic contract is unusable
constructor() {
_disableInitializers();
}

/// --------------------------------------------------------
/// --------------------------------------------------------
/// ---------------------- Initialize ----------------------
/// --------------------------------------------------------
/// --------------------------------------------------------

/// @notice Initialize the bridge
function initialize(
address newOwner,
address stakingToken,
address _rewardsDistributor,
uint256 _lockPeriod,
uint256 _minStake
) public initializer {
transferOwnership(newOwner);

shu = IERC20(stakingToken);
rewardsDistributor = IRewardsDistributor(_rewardsDistributor);
lockPeriod = _lockPeriod;
minStake = _minStake;
}

function addRewardToken(IERC20 _rewardToken) external {
require(

Check warning on line 91 in src/Staking.sol

View workflow job for this annotation

GitHub Actions / lint

Error message for require is too long: 46 counted / 32 allowed
msg.sender == address(rewardsDistributor),
Expand All @@ -60,7 +109,7 @@ contract Staking is Ownable2Step {
// If no shares exist, mint it 1:1 to the amount put in
sharesToMint = _amount;
} else {
// Calculate and mint the amount of shares the Shu is worth. The ratio will change over time, as shares are burned/minted and SHU distributed to this contract
// Calculate and mint the amount of shares the SHU is worth. The ratio will change over time, as shares are burned/minted and SHU distributed to this contract
sharesToMint = (_amount * totalSupply) / totalShu;
}

Expand Down Expand Up @@ -123,7 +172,7 @@ contract Staking is Ownable2Step {
userStakes[msg.sender].pop();
}

function claimRewards(address rewardToken, uint256 amount) public {
function claimRewards(address rewardToken, uint256 amount) external {
rewardsDistributor.distributeRewards();

IERC20 token = IERC20(rewardToken);
Expand Down Expand Up @@ -153,7 +202,3 @@ contract Staking is Ownable2Step {
totalSupply -= amount;
}
}

abstract contract RewardsDistributor {
function distributeRewards() external virtual;
}

0 comments on commit 553276c

Please sign in to comment.