mirror of
https://github.com/vacp2p/staking-reward-streamer.git
synced 2026-01-09 21:18:01 -05:00
feat(StakeManager): implement upgradability
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
block_timestamp = 1_680_220_800 # March 31, 2023 at 00:00 GMT
|
||||
bytecode_hash = "none"
|
||||
cbor_metadata = false
|
||||
evm_version = "paris"
|
||||
evm_version = "cancun"
|
||||
fuzz = { runs = 1_000 }
|
||||
gas_reports = ["*"]
|
||||
libs = ["lib"]
|
||||
@@ -16,6 +16,10 @@
|
||||
solc = "0.8.26"
|
||||
src = "src"
|
||||
test = "test"
|
||||
ast = true
|
||||
ffi = true
|
||||
build_info = true
|
||||
extra_output = ["storageLayout"]
|
||||
|
||||
[profile.ci]
|
||||
fuzz = { runs = 10_000 }
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
forge-std/=lib/forge-std/src/
|
||||
@openzeppelin/contracts=./lib/openzeppelin-contracts/contracts
|
||||
@openzeppelin/contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/
|
||||
@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/
|
||||
@@ -9,7 +9,7 @@ import { IStakeManager } from "./interfaces/IStakeManager.sol";
|
||||
import { TrustedCodehashAccess } from "./TrustedCodehashAccess.sol";
|
||||
|
||||
// Rewards Streamer with Multiplier Points
|
||||
contract RewardsStreamerMP is UUPSUpgradeable, Initializable, IStakeManager, TrustedCodehashAccess, ReentrancyGuardTransient {
|
||||
contract RewardsStreamerMP is UUPSUpgradeable, IStakeManager, TrustedCodehashAccess, ReentrancyGuardTransient {
|
||||
error StakingManager__AmountCannotBeZero();
|
||||
error StakingManager__TransferFailed();
|
||||
error StakingManager__InsufficientBalance();
|
||||
@@ -55,16 +55,12 @@ contract RewardsStreamerMP is UUPSUpgradeable, Initializable, IStakeManager, Tru
|
||||
_;
|
||||
}
|
||||
|
||||
constructor() TrustedCodehashAccess(msg.sender) {
|
||||
_transferOwnership(address(0));
|
||||
constructor() {
|
||||
_disableInitializers();
|
||||
}
|
||||
|
||||
|
||||
function initialize(address _owner, address _stakingToken, address _rewardToken) public initializer {
|
||||
if (_owner == address(0)) {
|
||||
revert OwnableInvalidOwner(address(0));
|
||||
}
|
||||
_transferOwnership(_owner);
|
||||
__TrustedCodehashAccess_init(_owner);
|
||||
|
||||
STAKING_TOKEN = IERC20(_stakingToken);
|
||||
REWARD_TOKEN = IERC20(_rewardToken);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
|
||||
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
||||
import { ITrustedCodehashAccess } from "./interfaces/ITrustedCodehashAccess.sol";
|
||||
/**
|
||||
* @title TrustedCodehashAccess
|
||||
@@ -10,7 +10,7 @@ import { ITrustedCodehashAccess } from "./interfaces/ITrustedCodehashAccess.sol"
|
||||
* interact with the functions using the `onlyTrustedCodehash` modifier.
|
||||
*/
|
||||
|
||||
contract TrustedCodehashAccess is ITrustedCodehashAccess, Ownable {
|
||||
abstract contract TrustedCodehashAccess is ITrustedCodehashAccess, OwnableUpgradeable {
|
||||
mapping(bytes32 codehash => bool permission) private trustedCodehashes;
|
||||
|
||||
/**
|
||||
@@ -25,7 +25,9 @@ contract TrustedCodehashAccess is ITrustedCodehashAccess, Ownable {
|
||||
_;
|
||||
}
|
||||
|
||||
constructor(address _owner) Ownable(_owner) { }
|
||||
function __TrustedCodehashAccess_init(address _initialOwner) public onlyInitializing {
|
||||
__Ownable_init(_initialOwner);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Allows the owner to set or update the trust status for a contract's codehash.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import { UnsafeUpgrades } from "openzeppelin-foundry-upgrades/Upgrades.sol";
|
||||
import { Test } from "forge-std/Test.sol";
|
||||
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
|
||||
import { RewardsStreamerMP } from "../src/RewardsStreamerMP.sol";
|
||||
@@ -10,6 +11,7 @@ import { MockToken } from "./mocks/MockToken.sol";
|
||||
contract RewardsStreamerMPTest is Test {
|
||||
MockToken rewardToken;
|
||||
MockToken stakingToken;
|
||||
RewardsStreamerMP public streamer_implementation;
|
||||
RewardsStreamerMP public streamer;
|
||||
|
||||
address admin = makeAddr("admin");
|
||||
@@ -23,7 +25,15 @@ contract RewardsStreamerMPTest is Test {
|
||||
function setUp() public virtual {
|
||||
rewardToken = new MockToken("Reward Token", "RT");
|
||||
stakingToken = new MockToken("Staking Token", "ST");
|
||||
streamer = new RewardsStreamerMP(address(this), address(stakingToken), address(rewardToken));
|
||||
streamer_implementation = new RewardsStreamerMP();
|
||||
streamer = RewardsStreamerMP(
|
||||
UnsafeUpgrades.deployUUPSProxy(
|
||||
address(streamer_implementation),
|
||||
abi.encodeCall(
|
||||
RewardsStreamerMP.initialize, (address(this), address(stakingToken), address(rewardToken))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
address[4] memory accounts = [alice, bob, charlie, dave];
|
||||
for (uint256 i = 0; i < accounts.length; i++) {
|
||||
|
||||
Reference in New Issue
Block a user