-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setup test/unit/StakingUnitTest.t.sol
- Loading branch information
1 parent
904529a
commit 41e5fd6
Showing
7 changed files
with
172 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
@forge-std/=lib/forge-std/src/ | ||
@openzeppelin=lib/openzeppelin-contracts/ | ||
@openzeppelin-upgradeable=lib/openzeppelin-contracts-upgradeable/ | ||
@solmate=lib/solmate/src/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.25; | ||
|
||
interface IRewardsDistributor { | ||
struct RewardConfiguration { | ||
address token; // the reward token | ||
uint256 emissionRate; // emission per second | ||
uint256 lastUpdate; // last update timestamp | ||
} | ||
|
||
function addRewardConfiguration( | ||
address receiver, | ||
address token, | ||
uint256 emissionRate | ||
) external; | ||
|
||
function updateEmissonRate( | ||
address receiver, | ||
address token, | ||
uint256 emissionRate | ||
) external; | ||
|
||
function distributeReward(address token) external; | ||
|
||
function rewardConfigurations( | ||
address receiver, | ||
uint256 index | ||
) | ||
external | ||
view | ||
returns (address token, uint256 emissionRate, uint256 lastUpdate); | ||
|
||
function rewardConfigurationsIds( | ||
address receiver, | ||
address token | ||
) external view returns (uint256); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.25; | ||
|
||
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import {IRewardsDistributor} from "./IRewardsDistributor.sol"; | ||
|
||
interface IStaking { | ||
function initialize( | ||
address newOwner, | ||
IERC20 _stakingToken, | ||
IRewardsDistributor _rewardsDistributor, | ||
uint256 _lockPeriod, | ||
uint256 _minStake | ||
) external; | ||
|
||
function stake(uint256 amount) external; | ||
|
||
function unstake( | ||
address keyper, | ||
uint256 stakeIndex, | ||
uint256 amount | ||
) external; | ||
|
||
function claimReward(IERC20 rewardToken, uint256 amount) external; | ||
|
||
function harvest(address keyper) external; | ||
|
||
function setRewardsDistributor( | ||
IRewardsDistributor _rewardsDistributor | ||
) external; | ||
|
||
function setLockPeriod(uint256 _lockPeriod) external; | ||
|
||
function setMinStake(uint256 _minStake) external; | ||
|
||
function setKeyper(address keyper, bool isKeyper) external; | ||
|
||
function setKeypers(address[] memory _keypers, bool isKeyper) external; | ||
|
||
function addRewardToken(address rewardToken) external; | ||
|
||
function convertToShares(uint256 assets) external view returns (uint256); | ||
|
||
function convertToAssets(uint256 shares) external view returns (uint256); | ||
|
||
function totalAssets() external view returns (uint256); | ||
|
||
function maxWithdraw(address keyper) external view returns (uint256); | ||
|
||
function maxClaimableRewards( | ||
address keyper | ||
) external view returns (uint256); | ||
|
||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.25; | ||
|
||
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
|
||
contract MockShu is ERC20 { | ||
constructor() ERC20("Shu", "SHU") { | ||
_mint(msg.sender, 5_000_000 * 1e18); | ||
} | ||
|
||
function mint(address account, uint256 amount) external { | ||
_mint(account, amount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.25; | ||
|
||
import "@forge-std/Test.sol"; | ||
|
||
import {TransparentUpgradeableProxy, ITransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; | ||
|
||
import {Staking} from "../../src/Staking.sol"; | ||
import {IStaking} from "../../src/interfaces/IStaking.sol"; | ||
import {RewardsDistributor} from "../../src/RewardsDistributor.sol"; | ||
import {IRewardsDistributor} from "../../src/interfaces/IRewardsDistributor.sol"; | ||
|
||
import {MockShu} from "../mocks/MockShu.sol"; | ||
|
||
contract StakingUnitTest is Test { | ||
IStaking staking; | ||
|
||
function setUp() public { | ||
// deploy mock shu | ||
MockShu shu = new MockShu(); | ||
|
||
// deploy rewards distributor | ||
address rewardsDistributor = address(new RewardsDistributor()); | ||
|
||
TransparentUpgradeableProxy rewardsDistributionProxy = new TransparentUpgradeableProxy( | ||
rewardsDistributor, | ||
address(this), | ||
abi.encodeWithSignature("initialize(address)", address(this)) | ||
); | ||
|
||
// deploy staking | ||
address stakingContract = address(new Staking()); | ||
|
||
address stakingProxy = address( | ||
new TransparentUpgradeableProxy(stakingContract, address(this), "") | ||
); | ||
|
||
uint256 lockPeriod = 60 * 24 * 30 * 6; // 6 months | ||
uint256 minStake = 50_000 * 1e18; // 50k | ||
|
||
Staking(address(stakingProxy)).initialize( | ||
address(this), // owner | ||
address(shu), | ||
address(rewardsDistributionProxy), | ||
lockPeriod, | ||
minStake | ||
); | ||
|
||
staking = IStaking(stakingProxy); | ||
} | ||
} |