Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
hujw77 committed Jun 12, 2024
1 parent 102f113 commit 588e711
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 19 deletions.
2 changes: 1 addition & 1 deletion script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract DeployScript is Script {
address hub = Upgrades.deployTransparentProxy(
"CollatorStakingHub.sol:CollatorStakingHub",
timelock,
abi.encodeCall(CollatorStakingHub.initialize, (gRING, deposit, "RING"))
abi.encodeCall(CollatorStakingHub.initialize, (gRING, deposit))
);

// RingTimelockController(timelock).grantRole(RingTimelockController(timelock).PROPOSER_ROLE(), ringDAO);
Expand Down
7 changes: 3 additions & 4 deletions src/collator/CollatorStakingHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol
import "./interfaces/ICollatorStakingPool.sol";
import "./interfaces/IGRING.sol";
import "../deposit/interfaces/IDeposit.sol";
import "./CollatorStakingPool.sol";
import "./NominationPool.sol";
import "./CollatorSet.sol";

contract CollatorStakingHub is ReentrancyGuardUpgradeable, CollatorSet {
Expand All @@ -35,10 +35,9 @@ contract CollatorStakingHub is ReentrancyGuardUpgradeable, CollatorSet {
_;
}

function initialize(address gring, address dps, string memory symbol) public initializer {
function initialize(address gring, address dps) public initializer {
gRING = gring;
DEPOSIT = dps;
SYMBOL = symbol;
__ReentrancyGuard_init();
__CollatorSet_init();
}
Expand All @@ -57,7 +56,7 @@ contract CollatorStakingHub is ReentrancyGuardUpgradeable, CollatorSet {
require(poolOf[collator] == address(0), "created");

uint256 index = count;
bytes memory bytecode = type(CollatorStakingPool).creationCode;
bytes memory bytecode = type(NominationPool).creationCode;
bytes memory initCode = bytes.concat(bytecode, abi.encode(collator, index));
assembly {
pool := create2(0, add(initCode, 32), mload(initCode), 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity 0.8.20;
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";

contract CollatorStakingPool {
contract NominationPool {
using Address for address payable;

/* ========== STATE VARIABLES ========== */
Expand Down
12 changes: 6 additions & 6 deletions test/collator/CollatorSet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ contract CollatorSetTest is Test, CollatorSet {
__CollatorSet_init();
}

function invariant_check() public {
function invariant_check() public view {
assertTrue(collators[HEAD] != address(0));
assertTrue(collators[TAIL] == address(0));
}

function test_init() public {
function test_init() public view {
assertEq(collators[HEAD], TAIL);
assertEq(collators[TAIL], address(0));
assertEq(votesOf[HEAD], type(uint256).max);
Expand Down Expand Up @@ -120,20 +120,20 @@ contract CollatorSetTest is Test, CollatorSet {
_reduceVotes(cur, votes, oldPrev, newPrev);
}

function checkCount(uint256 cnt) public {
function checkCount(uint256 cnt) public view {
assertEq(cnt, count);
}

function checkIn(address cur) public {
function checkIn(address cur) public view {
assertTrue(collators[cur] != address(0) && cur != HEAD && cur != TAIL);
}

function checkOut(address cur) public {
function checkOut(address cur) public view {
assertTrue(collators[cur] == address(0) && cur != HEAD && cur != TAIL);
assertEq(votesOf[cur], 0);
}

function checkIndex(address prev, address cur, address next) public {
function checkIndex(address prev, address cur, address next) public view {
assertTrue(collators[prev] == cur);
assertTrue(collators[cur] == next);
assertTrue(votesOf[prev] >= votesOf[cur]);
Expand Down
37 changes: 37 additions & 0 deletions test/collator/CollatorStakingHub.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "forge-std/Test.sol";
import {Upgrades} from "openzeppelin-foundry-upgrades/Upgrades.sol";
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

import "../../src/collator/CollatorStakingHub.sol";
import "../../src/deposit/Deposit.sol";

contract CollatorStakingHubTest is Test {
address hub;

function setUp() public {
address gring = address(new GRINGMock());
address deposit = Upgrades.deployTransparentProxy(
"Deposit.sol:Deposit", msg.sender, abi.encodeCall(Deposit.initialize, ("RING Deposit", "RDPS"))
);
hub = Upgrades.deployTransparentProxy(
"CollatorStakingHub.sol:CollatorStakingHub",
msg.sender,
abi.encodeCall(CollatorStakingHub.initialize, (gring, deposit))
);
}
}

contract GRINGMock is ERC20 {
constructor() ERC20("Governance RINGMock", "gRINGM") {}

function mint(address account, uint256 amount) external {
_mint(account, amount);
}

function burn(address account, uint256 amount) external {
_burn(account, amount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ pragma solidity ^0.8.0;

import "forge-std/Test.sol";

import "../../src/collator/CollatorStakingPool.sol";
import "../../src/collator/NominationPool.sol";

contract CollatorStakingPoolTest is Test {
CollatorStakingPool pool;
contract NominationPoolTest is Test {
NominationPool pool;
uint256 startTime;
uint256 endTime;
uint256 reward = 100 ether;
Expand All @@ -16,7 +16,7 @@ contract CollatorStakingPoolTest is Test {
address bob = address(new Guy());

function setUp() public {
pool = new CollatorStakingPool(self, 0);
pool = new NominationPool(self, 0);
assertEq(pool.rewardsDuration(), REWARDS_DURATION);
}

Expand All @@ -27,11 +27,11 @@ contract CollatorStakingPoolTest is Test {
assertEq(endTime, startTime + REWARDS_DURATION);
}

function invariant_hub() public {
function invariant_hub() public view {
assertEq(pool.hub(), self);
}

function test_constructor() public {
function test_constructor() public view {
assertEq(pool.totalSupply(), 0);
}

Expand Down
2 changes: 1 addition & 1 deletion test/deposit/Deposit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ contract DepositTest is Test, ERC721Holder {
assertEq(IERC721Enumerable(deposit).totalSupply(), 0);
}

function test_computeInterest() public {
function test_computeInterest() public view {
uint256 UNIT = 1 ether;
for (uint256 m = 1; m < 37; m++) {
uint256 interest = Deposit(deposit).INTERESTS(m);
Expand Down

0 comments on commit 588e711

Please sign in to comment.