mirror of
https://github.com/vacp2p/staking-reward-streamer.git
synced 2026-01-09 21:18:01 -05:00
chore: make linter and formatter happy
This commit is contained in:
43
.gas-report
Normal file
43
.gas-report
Normal file
@@ -0,0 +1,43 @@
|
||||
| src/RewardsStreamer.sol:RewardsStreamer contract | | | | | |
|
||||
|--------------------------------------------------|-----------------|--------|--------|--------|---------|
|
||||
| Deployment Cost | Deployment Size | | | | |
|
||||
| 690902 | 3154 | | | | |
|
||||
| Function Name | min | avg | median | max | # calls |
|
||||
| accountedRewards | 351 | 601 | 351 | 2351 | 8 |
|
||||
| getUserInfo | 793 | 793 | 793 | 793 | 12 |
|
||||
| rewardIndex | 350 | 600 | 350 | 2350 | 8 |
|
||||
| stake | 85235 | 100736 | 105135 | 111838 | 3 |
|
||||
| totalStaked | 351 | 351 | 351 | 351 | 8 |
|
||||
| unstake | 110100 | 110106 | 110106 | 110112 | 2 |
|
||||
| updateRewardIndex | 23374 | 45581 | 39585 | 73785 | 3 |
|
||||
|
||||
|
||||
| src/RewardsStreamerMP.sol:RewardsStreamerMP contract | | | | | |
|
||||
|------------------------------------------------------|-----------------|--------|--------|--------|---------|
|
||||
| Deployment Cost | Deployment Size | | | | |
|
||||
| 1096353 | 4939 | | | | |
|
||||
| Function Name | min | avg | median | max | # calls |
|
||||
| accountedRewards | 373 | 595 | 373 | 2373 | 9 |
|
||||
| getUserInfo | 1553 | 1553 | 1553 | 1553 | 16 |
|
||||
| potentialMP | 330 | 330 | 330 | 330 | 9 |
|
||||
| rewardIndex | 373 | 595 | 373 | 2373 | 9 |
|
||||
| stake | 167821 | 194716 | 187721 | 228608 | 3 |
|
||||
| totalMP | 352 | 352 | 352 | 352 | 9 |
|
||||
| totalStaked | 330 | 330 | 330 | 330 | 9 |
|
||||
| unstake | 133268 | 133274 | 133274 | 133280 | 2 |
|
||||
| updateGlobalState | 30008 | 52396 | 49622 | 80335 | 4 |
|
||||
|
||||
|
||||
| test/mocks/MockToken.sol:MockToken contract | | | | | |
|
||||
|---------------------------------------------|-----------------|-------|--------|-------|---------|
|
||||
| Deployment Cost | Deployment Size | | | | |
|
||||
| 639406 | 3369 | | | | |
|
||||
| Function Name | min | avg | median | max | # calls |
|
||||
| approve | 46346 | 46346 | 46346 | 46346 | 10 |
|
||||
| balanceOf | 561 | 1143 | 561 | 2561 | 79 |
|
||||
| mint | 51284 | 58124 | 51284 | 68384 | 10 |
|
||||
| transfer | 34390 | 42940 | 42940 | 51490 | 4 |
|
||||
|
||||
|
||||
|
||||
|
||||
2
.gas-snapshot
Normal file
2
.gas-snapshot
Normal file
@@ -0,0 +1,2 @@
|
||||
RewardsStreamerMPTest:testStake() (gas: 1377536)
|
||||
RewardsStreamerTest:testStake() (gas: 869874)
|
||||
@@ -1,14 +1,12 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import { Script, console } from "forge-std/Script.sol";
|
||||
import { Script } from "forge-std/Script.sol";
|
||||
import { RewardsStreamer } from "../src/RewardsStreamer.sol";
|
||||
|
||||
contract RewardsStreamerScript is Script {
|
||||
RewardsStreamer public rewardsStreamer;
|
||||
|
||||
function setUp() public { }
|
||||
|
||||
function run() public {
|
||||
vm.startBroadcast();
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ contract RewardsStreamer is ReentrancyGuard {
|
||||
error StakingManager__TransferFailed();
|
||||
error StakingManager__InsufficientBalance();
|
||||
|
||||
IERC20 public immutable stakingToken;
|
||||
IERC20 public immutable rewardToken;
|
||||
IERC20 public immutable STAKING_TOKEN;
|
||||
IERC20 public immutable REWARD_TOKEN;
|
||||
|
||||
uint256 public constant SCALE_FACTOR = 1e18;
|
||||
|
||||
@@ -23,11 +23,11 @@ contract RewardsStreamer is ReentrancyGuard {
|
||||
uint256 userRewardIndex;
|
||||
}
|
||||
|
||||
mapping(address => UserInfo) public users;
|
||||
mapping(address account => UserInfo data) public users;
|
||||
|
||||
constructor(address _stakingToken, address _rewardToken) {
|
||||
stakingToken = IERC20(_stakingToken);
|
||||
rewardToken = IERC20(_rewardToken);
|
||||
STAKING_TOKEN = IERC20(_stakingToken);
|
||||
REWARD_TOKEN = IERC20(_rewardToken);
|
||||
}
|
||||
|
||||
function stake(uint256 amount) external nonReentrant {
|
||||
@@ -43,7 +43,7 @@ contract RewardsStreamer is ReentrancyGuard {
|
||||
distributeRewards(msg.sender, userRewards);
|
||||
}
|
||||
|
||||
bool success = stakingToken.transferFrom(msg.sender, address(this), amount);
|
||||
bool success = STAKING_TOKEN.transferFrom(msg.sender, address(this), amount);
|
||||
if (!success) {
|
||||
revert StakingManager__TransferFailed();
|
||||
}
|
||||
@@ -69,7 +69,7 @@ contract RewardsStreamer is ReentrancyGuard {
|
||||
user.stakedBalance -= amount;
|
||||
totalStaked -= amount;
|
||||
|
||||
bool success = stakingToken.transfer(msg.sender, amount);
|
||||
bool success = STAKING_TOKEN.transfer(msg.sender, amount);
|
||||
if (!success) {
|
||||
revert StakingManager__TransferFailed();
|
||||
}
|
||||
@@ -82,7 +82,7 @@ contract RewardsStreamer is ReentrancyGuard {
|
||||
return;
|
||||
}
|
||||
|
||||
uint256 rewardBalance = rewardToken.balanceOf(address(this));
|
||||
uint256 rewardBalance = REWARD_TOKEN.balanceOf(address(this));
|
||||
uint256 newRewards = rewardBalance > accountedRewards ? rewardBalance - accountedRewards : 0;
|
||||
|
||||
if (newRewards > 0) {
|
||||
@@ -106,18 +106,18 @@ contract RewardsStreamer is ReentrancyGuard {
|
||||
|
||||
// send the rewards and updates accountedRewards
|
||||
function distributeRewards(address to, uint256 amount) internal {
|
||||
uint256 rewardBalance = rewardToken.balanceOf(address(this));
|
||||
uint256 rewardBalance = REWARD_TOKEN.balanceOf(address(this));
|
||||
// If amount is higher than the contract's balance (for rounding error), transfer the balance.
|
||||
if (amount > rewardBalance) {
|
||||
amount = rewardBalance;
|
||||
}
|
||||
|
||||
bool success = rewardToken.transfer(to, amount);
|
||||
accountedRewards -= amount;
|
||||
|
||||
bool success = REWARD_TOKEN.transfer(to, amount);
|
||||
if (!success) {
|
||||
revert StakingManager__TransferFailed();
|
||||
}
|
||||
|
||||
accountedRewards -= amount;
|
||||
}
|
||||
|
||||
function getUserInfo(address userAddress) public view returns (UserInfo memory) {
|
||||
|
||||
@@ -13,8 +13,8 @@ contract RewardsStreamerMP is ReentrancyGuard {
|
||||
error StakingManager__CannotRestakeWithLockedFunds();
|
||||
error StakingManager__TokensAreLocked();
|
||||
|
||||
IERC20 public immutable stakingToken;
|
||||
IERC20 public immutable rewardToken;
|
||||
IERC20 public immutable STAKING_TOKEN;
|
||||
IERC20 public immutable REWARD_TOKEN;
|
||||
|
||||
uint256 public constant SCALE_FACTOR = 1e18;
|
||||
uint256 public constant MP_RATE_PER_YEAR = 1e18;
|
||||
@@ -39,11 +39,11 @@ contract RewardsStreamerMP is ReentrancyGuard {
|
||||
uint256 lockUntil;
|
||||
}
|
||||
|
||||
mapping(address => UserInfo) public users;
|
||||
mapping(address account => UserInfo data) public users;
|
||||
|
||||
constructor(address _stakingToken, address _rewardToken) {
|
||||
stakingToken = IERC20(_stakingToken);
|
||||
rewardToken = IERC20(_rewardToken);
|
||||
STAKING_TOKEN = IERC20(_stakingToken);
|
||||
REWARD_TOKEN = IERC20(_rewardToken);
|
||||
lastMPUpdatedTime = block.timestamp;
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ contract RewardsStreamerMP is ReentrancyGuard {
|
||||
distributeRewards(msg.sender, userRewards);
|
||||
}
|
||||
|
||||
bool success = stakingToken.transferFrom(msg.sender, address(this), amount);
|
||||
bool success = STAKING_TOKEN.transferFrom(msg.sender, address(this), amount);
|
||||
if (!success) {
|
||||
revert StakingManager__TransferFailed();
|
||||
}
|
||||
@@ -131,7 +131,7 @@ contract RewardsStreamerMP is ReentrancyGuard {
|
||||
totalMP -= mpToReduce;
|
||||
potentialMP -= potentialMPToReduce;
|
||||
|
||||
bool success = stakingToken.transfer(msg.sender, amount);
|
||||
bool success = STAKING_TOKEN.transfer(msg.sender, amount);
|
||||
if (!success) {
|
||||
revert StakingManager__TransferFailed();
|
||||
}
|
||||
@@ -184,7 +184,7 @@ contract RewardsStreamerMP is ReentrancyGuard {
|
||||
return;
|
||||
}
|
||||
|
||||
uint256 rewardBalance = rewardToken.balanceOf(address(this));
|
||||
uint256 rewardBalance = REWARD_TOKEN.balanceOf(address(this));
|
||||
uint256 newRewards = rewardBalance > accountedRewards ? rewardBalance - accountedRewards : 0;
|
||||
|
||||
if (newRewards > 0) {
|
||||
@@ -226,18 +226,18 @@ contract RewardsStreamerMP is ReentrancyGuard {
|
||||
}
|
||||
|
||||
function distributeRewards(address to, uint256 amount) internal {
|
||||
uint256 rewardBalance = rewardToken.balanceOf(address(this));
|
||||
uint256 rewardBalance = REWARD_TOKEN.balanceOf(address(this));
|
||||
// If amount is higher than the contract's balance (for rounding error), transfer the balance.
|
||||
if (amount > rewardBalance) {
|
||||
amount = rewardBalance;
|
||||
}
|
||||
|
||||
bool success = rewardToken.transfer(to, amount);
|
||||
accountedRewards -= amount;
|
||||
|
||||
bool success = REWARD_TOKEN.transfer(to, amount);
|
||||
if (!success) {
|
||||
revert StakingManager__TransferFailed();
|
||||
}
|
||||
|
||||
accountedRewards -= amount;
|
||||
}
|
||||
|
||||
function getStakedBalance(address userAddress) external view returns (uint256) {
|
||||
|
||||
Reference in New Issue
Block a user