If you notice some outdated information please let us know!
PASS
The final review score is indicated as a percentage. The percentage is calculated as Achieved Points due to MAX Possible Points. For each element the answer can be either Yes/No or a percentage. For a detailed breakdown of the individual weights of each question, please consult this document.
Very simply, the audit looks for the following declarations from the developer's site. With these declarations, it is reasonable to trust the smart contracts.
This report is for informational purposes only and does not constitute investment advice of any kind, nor does it constitute an offer to provide investment advisory or other services. Nothing in this report shall be considered a solicitation or offer to buy or sell any security, token, future, option or other financial instrument or to offer or provide any investment advice or service to any person in any jurisdiction. Nothing contained in this report constitutes investment advice or offers any opinion with respect to the suitability of any security, and the views expressed in this report should not be taken as advice to buy, sell or hold any security. The information in this report should not be relied upon for the purpose of investing. In preparing the information contained in this report, we have not taken into account the investment needs, objectives and financial circumstances of any particular investor. This information has no regard to the specific investment objectives, financial situation and particular needs of any specific recipient of this information and investments discussed may not be suitable for all investors.
Any views expressed in this report by us were prepared based upon the information available to us at the time such views were written. The views expressed within this report are limited to DeFiSafety and the author and do not reflect those of any additional or third party and are strictly based upon DeFiSafety, its authors, interpretations and evaluation of relevant data. Changed or additional information could cause such views to change. All information is subject to possible correction. Information may quickly become unreliable for various reasons, including changes in market conditions or economic circumstances.
This completed report is copyright (c) DeFiSafety 2023. Permission is given to copy in whole, retaining this copyright label.
This section looks at the code deployed on the Mainnet that gets reviewed and its corresponding software repository. The document explaining these questions is here.
1. Are the executing code addresses readily available? (%)
All of the executing ShapeShift smart contracts are available in their respective GitHub repositories, as indicated in the Appendix.
2. Is the code actively being used? (%)
Activity is 10+ transactions a day on contract FOX Staking Rewards, as indicated in the Appendix.
3. Is there a public software repository? (Y/N)
GitHub: https://github.com/shapeshift
Is there a public software repository with the code at a minimum, but also normally test and scripts. Even if the repository was created just to hold the files and has just 1 transaction, it gets a "Yes". For teams with private repositories, this answer is "No"
4. Is there a development history visible? (%)
At 2,654 commits and 3 branches, the Fox staking repository is the extensive foxhole network the developer's would like it to be.
This metric checks if the software repository demonstrates a strong steady history. This is normally demonstrated by commits, branches and releases in a software repository. A healthy history demonstrates a history of more than a month (at a minimum).
5. Is the team public (not anonymous)? (Y/N)
For a "Yes" in this question, the real names of some team members must be public on the website or other documentation (LinkedIn, etc). If the team is anonymous, then this question is a "No".
This section looks at the software documentation. The document explaining these questions is here.
7. Are the basic software functions documented? (Y/N)
ShapeShift documents their basic software functions at https://raw.githack.com/shapeshift/fox-staking-unified-history/master/docs/index.html#/.
8. Does the software function documentation fully (100%) cover the deployed contracts? (%)
All of ShapeShift's main executing contracts and functions are documented at https://raw.githack.com/shapeshift/fox-staking-unified-history/master/docs/index.html#/.
9. Are there sufficiently detailed comments for all functions within the deployed contract code (%)
The Comments to Code (CtC) ratio is the primary metric for this score.
10. Is it possible to trace from software documentation to the implementation in code (%)
ShapeShift lists and describes all their functions at https://raw.githack.com/shapeshift/fox-staking-unified-history/master/docs/index.html#/.
11. Full test suite (Covers all the deployed code) (%)
This score is guided by the Test to Code ratio (TtC). Generally a good test to code ratio is over 100%. However the reviewers best judgement is the final deciding factor.
12. Code coverage (Covers all the deployed lines of code, or explains misses) (%)
As per https://raw.githack.com/shapeshift/fox-staking-unified-history/master/coverage/index.html, ShapeShift has a 91% code coverage.
13. Scripts and instructions to run the tests? (Y/N)
Scripts/Instructions location: https://github.com/shapeshift/docs/blob/main/testing.md
14. Report of the results (%)
A code coverage report is visible at https://raw.githack.com/shapeshift/fox-staking-unified-history/master/coverage/index.html.
15. Formal Verification test done (%)
No formal verification was undertaken.
This section looks at the 3rd party software audits done. It is explained in this document.
17. Did 3rd Party audits take place? (%)
Multiple audits were performed before the public deployment of multiple of their smart contracts. Notably, the token, and the staker, and airdrop contracts have all been audited pre-launch.
18. Is the bug bounty acceptable high? (%)
According to https://shapeshift.com/responsible-disclosure-program, ShapeShift has given approximately 40k in rewards for bug finds.
This section covers the documentation of special access controls for a DeFi protocol. The admin access controls are the contracts that allow updating contracts or coefficients in the protocol. Since these contracts can allow the protocol admins to "change the rules", complete disclosure of capabilities is vital for user's transparency. It is explained in this document.
19. Can a user clearly and quickly find the status of the access controls (%)
Immutability of contracts and absence of owner privileges are clearly described at https://github.com/shapeshift/fox-staking-unified-history.
20. Is the information clear and complete (%)
Immutability of contracts and absence of owner privileges are clearly described at https://github.com/shapeshift/fox-staking-unified-history.
21. Is the information in non-technical terms that pertain to the investments (%)
Immutability of contracts and absence of owner privileges are clearly described at https://github.com/shapeshift/fox-staking-unified-history.
22. Is there Pause Control documentation including records of tests (%)
Although no pause control function exists in the ShapeShift code, their smart contracts are entirely immutable, and the protocol functionalities that do not make pause control functions a necessity are described at https://github.com/shapeshift/fox-staking-unified-history/blob/master/README.md
1pragma solidity ^0.7.6;
2
3import '../openzeppelin-solidity-3.4.0/contracts/token/ERC20/IERC20.sol';
4import '../openzeppelin-solidity-3.4.0/contracts/access/Ownable.sol';
5
6import './StakingRewards.sol';
7
8contract StakingRewardsFactory is Ownable {
9 // immutables
10 address public rewardsToken;
11 uint public stakingRewardsGenesis;
12
13 // the staking tokens for which the rewards contract has been deployed
14 address[] public stakingTokens;
15
16 // info about rewards for a particular staking token
17 struct StakingRewardsInfo {
18 address stakingRewards;
19 uint rewardAmount;
20 }
21
22 // rewards info by staking token
23 mapping(address => StakingRewardsInfo) public stakingRewardsInfoByStakingToken;
24
25 constructor(
26 address _rewardsToken,
27 uint _stakingRewardsGenesis
28 ) Ownable() {
29 require(_stakingRewardsGenesis >= block.timestamp, 'StakingRewardsFactory::constructor: genesis too soon');
30
31 rewardsToken = _rewardsToken;
32 stakingRewardsGenesis = _stakingRewardsGenesis;
33 }
34
35 ///// permissioned functions
36
37 // deploy a staking reward contract for the staking token, and store the reward amount
38 // the reward will be distributed to the staking reward contract no sooner than the genesis
39 function deploy(address stakingToken, uint rewardAmount) external onlyOwner {
40 StakingRewardsInfo storage info = stakingRewardsInfoByStakingToken[stakingToken];
41 require(info.stakingRewards == address(0), 'StakingRewardsFactory::deploy: already deployed');
42
43 info.stakingRewards = address(new StakingRewards(/*_rewardsDistribution=*/ address(this), rewardsToken, stakingToken));
44 info.rewardAmount = rewardAmount;
45 stakingTokens.push(stakingToken);
46 }
47
48 ///// permissionless functions
49
50 // call notifyRewardAmount for all staking tokens.
51 function notifyRewardAmounts() external {
52 require(stakingTokens.length > 0, 'StakingRewardsFactory::notifyRewardAmounts: called before any deploys');
53 for (uint i = 0; i < stakingTokens.length; i++) {
54 notifyRewardAmount(stakingTokens[i]);
55 }
56 }
57
58 // notify reward amount for an individual staking token.
59 // this is a fallback in case the notifyRewardAmounts costs too much gas to call for all contracts
60 function notifyRewardAmount(address stakingToken) public {
61 require(block.timestamp >= stakingRewardsGenesis, 'StakingRewardsFactory::notifyRewardAmount: not ready');
62
63 StakingRewardsInfo storage info = stakingRewardsInfoByStakingToken[stakingToken];
64 require(info.stakingRewards != address(0), 'StakingRewardsFactory::notifyRewardAmount: not deployed');
65
66 if (info.rewardAmount > 0) {
67 uint rewardAmount = info.rewardAmount;
68 info.rewardAmount = 0;
69
70 require(
71 IERC20(rewardsToken).transfer(info.stakingRewards, rewardAmount),
72 'StakingRewardsFactory::notifyRewardAmount: transfer failed'
73 );
74 StakingRewards(info.stakingRewards).notifyRewardAmount(rewardAmount);
75 }
76 }
77}
78
79pragma solidity ^0.7.6;
80
81import "../openzeppelin-solidity-3.4.0/contracts/math/Math.sol";
82import "../openzeppelin-solidity-3.4.0/contracts/math/SafeMath.sol";
83import "../openzeppelin-solidity-3.4.0/contracts/token/ERC20/SafeERC20.sol";
84import "../openzeppelin-solidity-3.4.0/contracts/utils/ReentrancyGuard.sol";
85
86// Inheritance
87import "./interfaces/IStakingRewards.sol";
88import "./RewardsDistributionRecipient.sol";
89
90contract StakingRewards is IStakingRewards, RewardsDistributionRecipient, ReentrancyGuard {
91 using SafeMath for uint256;
92 using SafeERC20 for IERC20;
93
94 /* ========= STATE VARIABLES ========= */
95
96 IERC20 public rewardsToken;
97 IERC20 public stakingToken;
98 uint256 public periodFinish = 0;
99 uint256 public rewardRate = 0;
100 uint256 public rewardsDuration = 135 days;
101 uint256 public lastUpdateTime;
102 uint256 public rewardPerTokenStored;
103
104 mapping(address => uint256) public userRewardPerTokenPaid;
105 mapping(address => uint256) public rewards;
106
107 uint256 private _totalSupply;
108 mapping(address => uint256) private _balances;
109
110 /* ========== CONSTRUCTOR ========== */
111
112 constructor(
113 address _rewardsDistribution,
114 address _rewardsToken,
115 address _stakingToken
116 ) {
117 rewardsToken = IERC20(_rewardsToken);
118 stakingToken = IERC20(_stakingToken);
119 rewardsDistribution = _rewardsDistribution;
120 }
121
122 /* ========== VIEWS ========== */
123
124 function totalSupply() external view override returns (uint256) {
125 return _totalSupply;
126 }
127
128 function balanceOf(address account) external view override returns (uint256) {
129 return _balances[account];
130 }
131
132 function lastTimeRewardApplicable() public view override returns (uint256) {
133 return Math.min(block.timestamp, periodFinish);
134 }
135
136 function rewardPerToken() public view override returns (uint256) {
137 if (_totalSupply == 0) {
138 return rewardPerTokenStored;
139 }
140 return
141 rewardPerTokenStored.add(
142 lastTimeRewardApplicable().sub(lastUpdateTime).mul(rewardRate).mul(1e18).div(_totalSupply)
143 );
144 }
145
146 function earned(address account) public view override returns (uint256) {
147 return _balances[account].mul(rewardPerToken().sub(userRewardPerTokenPaid[account])).div(1e18).add(rewards[account]);
148 }
149
150 function getRewardForDuration() external view override returns (uint256) {
151 return rewardRate.mul(rewardsDuration);
152 }
153
154 /* ========== MUTATIVE FUNCTIONS ========== */
155
156 function stakeWithPermit(uint256 amount, uint deadline, uint8 v, bytes32 r, bytes32 s) external nonReentrant updateReward(msg.sender) {
157 require(amount > 0, "Cannot stake 0");
158 _totalSupply = _totalSupply.add(amount);
159 _balances[msg.sender] = _balances[msg.sender].add(amount);
160
161 // permit
162 IUniswapV2ERC20(address(stakingToken)).permit(msg.sender, address(this), amount, deadline, v, r, s);
163
164 stakingToken.safeTransferFrom(msg.sender, address(this), amount);
165 emit Staked(msg.sender, amount);
166 }
167
168 function stake(uint256 amount) external override nonReentrant updateReward(msg.sender) {
169 require(amount > 0, "Cannot stake 0");
170 _totalSupply = _totalSupply.add(amount);
171 _balances[msg.sender] = _balances[msg.sender].add(amount);
172 stakingToken.safeTransferFrom(msg.sender, address(this), amount);
173 emit Staked(msg.sender, amount);
174 }
175
176 function withdraw(uint256 amount) public override nonReentrant updateReward(msg.sender) {
177 require(amount > 0, "Cannot withdraw 0");
178 _totalSupply = _totalSupply.sub(amount);
179 _balances[msg.sender] = _balances[msg.sender].sub(amount);
180 stakingToken.safeTransfer(msg.sender, amount);
181 emit Withdrawn(msg.sender, amount);
182 }
183
184 function getReward() public override nonReentrant updateReward(msg.sender) {
185 uint256 reward = rewards[msg.sender];
186 if (reward > 0) {
187 rewards[msg.sender] = 0;
188 rewardsToken.safeTransfer(msg.sender, reward);
189 emit RewardPaid(msg.sender, reward);
190 }
191 }
192
193 function exit() external override {
194 withdraw(_balances[msg.sender]);
195 getReward();
196 }
197
198 /* ========== RESTRICTED FUNCTIONS ========== */
199
200 function notifyRewardAmount(uint256 reward) external override onlyRewardsDistribution updateReward(address(0)) {
201 if (block.timestamp >= periodFinish) {
202 rewardRate = reward.div(rewardsDuration);
203 } else {
204 uint256 remaining = periodFinish.sub(block.timestamp);
205 uint256 leftover = remaining.mul(rewardRate);
206 rewardRate = reward.add(leftover).div(rewardsDuration);
207 }
208
209 // Ensure the provided reward amount is not more than the balance in the contract.
210 // This keeps the reward rate in the right range, preventing overflows due to
211 // very high values of rewardRate in the earned and rewardsPerToken functions;
212 // Reward + leftover must be less than 2^256 / 10^18 to avoid overflow.
213 uint balance = rewardsToken.balanceOf(address(this));
214 require(rewardRate <= balance.div(rewardsDuration), "Provided reward too high");
215
216 lastUpdateTime = block.timestamp;
217 periodFinish = block.timestamp.add(rewardsDuration);
218 emit RewardAdded(reward);
219 }
220
221 /* ========== MODIFIERS ========== */
222
223 modifier updateReward(address account) {
224 rewardPerTokenStored = rewardPerToken();
225 lastUpdateTime = lastTimeRewardApplicable();
226 if (account != address(0)) {
227 rewards[account] = earned(account);
228 userRewardPerTokenPaid[account] = rewardPerTokenStored;
229 }
230 _;
231 }
232
233 /* ========== EVENTS ========== */
234
235 event RewardAdded(uint256 reward);
236 event Staked(address indexed user, uint256 amount);
237 event Withdrawn(address indexed user, uint256 amount);
238 event RewardPaid(address indexed user, uint256 reward);
239}
240
241interface IUniswapV2ERC20 {
242 function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
243}