Skip to content

Commit

Permalink
✨ prettify
Browse files Browse the repository at this point in the history
  • Loading branch information
Flocqst committed Aug 20, 2024
1 parent a74ee63 commit ed00da4
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 86 deletions.
6 changes: 4 additions & 2 deletions contracts/StakingRewardsNotifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ contract StakingRewardsNotifier is Ownable2Step, IStakingRewardsNotifier {
/// @param _usdc: address of the USDC contract
/// @param _supplySchedule: address of the SupplySchedule contract
constructor(address _contractOwner, address _kwenta, address _usdc, address _supplySchedule) {
if (_contractOwner == address(0) || _kwenta == address(0) || _usdc == address(0) || _supplySchedule == address(0))
{
if (
_contractOwner == address(0) || _kwenta == address(0) || _usdc == address(0)
|| _supplySchedule == address(0)
) {
revert ZeroAddress();
}
kwenta = IKwenta(_kwenta);
Expand Down
6 changes: 3 additions & 3 deletions contracts/interfaces/IStakingRewardsV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ interface IStakingRewardsV2 {
/// @param _timestamp: timestamp to check
/// @return balance at given timestamp
/// @dev if called with a timestamp that equals the current block timestamp, then the function might return inconsistent
/// values as further transactions changing the balances can still occur within the same block.
/// values as further transactions changing the balances can still occur within the same block.
function balanceAtTime(address _account, uint256 _timestamp) external view returns (uint256);

/// @notice get a users escrowed balance at a given timestamp
/// @param _account: address of account to check
/// @param _timestamp: timestamp to check
/// @return escrowed balance at given timestamp
/// @dev if called with a timestamp that equals the current block timestamp, then the function might return inconsistent
/// values as further transactions changing the balances can still occur within the same block.
/// values as further transactions changing the balances can still occur within the same block.
function escrowedBalanceAtTime(address _account, uint256 _timestamp)
external
view
Expand All @@ -130,7 +130,7 @@ interface IStakingRewardsV2 {
/// @param _timestamp: timestamp to check
/// @return total supply at given timestamp
/// @dev if called with a timestamp that equals the current block timestamp, then the function might return inconsistent
/// values as further transactions changing the balances can still occur within the same block.
/// values as further transactions changing the balances can still occur within the same block.
function totalSupplyAtTime(uint256 _timestamp) external view returns (uint256);

/*//////////////////////////////////////////////////////////////
Expand Down
5 changes: 2 additions & 3 deletions test/foundry/integration/stakingV2.migration.fork.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ contract StakingV2MigrationForkTests is StakingTestHelpers {
// set owners address code to trick the test into allowing onlyOwner functions to be called via script
vm.etch(owner, address(new Migrate()).code);

(rewardEscrowV2, stakingRewardsV2, escrowMigrator, rewardsNotifier) = Migrate(
owner
).runCompleteMigrationProcess({
(rewardEscrowV2, stakingRewardsV2, escrowMigrator, rewardsNotifier) = Migrate(owner)
.runCompleteMigrationProcess({
_owner: owner,
_kwenta: address(kwenta),
_usdc: address(usdc),
Expand Down
3 changes: 1 addition & 2 deletions test/foundry/integration/stakingV2.upgrade.fork.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {StakingRewardsV2} from "../../../contracts/StakingRewardsV2.sol";
import "../utils/Constants.t.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";


contract StakingV2MigrationForkTests is StakingTestHelpers {
/*//////////////////////////////////////////////////////////////
SETUP
Expand Down Expand Up @@ -115,6 +114,6 @@ contract StakingV2MigrationForkTests is StakingTestHelpers {

// check some stake has been earned
assertGt(newV2Impl.earned(address(this)), earnedKwenta);
assertGt(newV2Impl.earnedUSDC(address(this)) , 0);
assertGt(newV2Impl.earnedUSDC(address(this)), 0);
}
}
5 changes: 1 addition & 4 deletions test/foundry/integration/stakingV2.upgrade.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,7 @@ contract StakingV2UpgradeTests is DefaultStakingV2Setup {
{
stakingRewardsV3Implementation = address(
new MockStakingRewardsV3(
address(kwenta),
address(usdc),
address(rewardEscrowV2),
address(rewardsNotifier)
address(kwenta), address(usdc), address(rewardEscrowV2), address(rewardsNotifier)
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,23 @@ contract StakingRewardsNotifierTest is DefaultStakingV2Setup {

function testCannotDeployWithZeroOwnerAddress() public {
vm.expectRevert(IStakingRewardsNotifier.ZeroAddress.selector);
new StakingRewardsNotifier(address(0), address(kwenta), address(usdc), address(supplySchedule));
new StakingRewardsNotifier(
address(0), address(kwenta), address(usdc), address(supplySchedule)
);
}

function testCannotDeployWithZeroKwentaAddress() public {
vm.expectRevert(IStakingRewardsNotifier.ZeroAddress.selector);
new StakingRewardsNotifier(address(this), address(0), address(usdc), address(supplySchedule));
new StakingRewardsNotifier(
address(this), address(0), address(usdc), address(supplySchedule)
);
}

function testCannotDeployWithZeroUsdcAddress() public {
vm.expectRevert(IStakingRewardsNotifier.ZeroAddress.selector);
new StakingRewardsNotifier(address(this), address(kwenta), address(0), address(supplySchedule));
new StakingRewardsNotifier(
address(this), address(kwenta), address(0), address(supplySchedule)
);
}

function testCannotDeployWithZeroSupplyScheduleAddress() public {
Expand Down Expand Up @@ -159,12 +165,11 @@ contract StakingRewardsNotifierTest is DefaultStakingV2Setup {
assertEq(kwenta.balanceOf(address(rewardEscrowV2)), 0);

// Mint and the RewardsNotifier should transfer amounts to the staking contract
uint256 mintAmount = 176268972686291953380981;
uint256 mintAmount = 176_268_972_686_291_953_380_981;
uint256 balanceBefore = kwenta.balanceOf(address(stakingRewardsV2));
supplySchedule.mint();
uint256 balanceAfter = kwenta.balanceOf(address(stakingRewardsV2));
assertGt(balanceAfter, balanceBefore);
assertEq(balanceAfter - balanceBefore, 225 ether + mintAmount);

}
}
86 changes: 27 additions & 59 deletions test/foundry/unit/StakingV2SetupTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ contract StakingV2SetupTests is StakingV1Setup {
function setUp() public virtual override {
super.setUp();

rewardEscrowV2Implementation =
address(new RewardEscrowV2(address(kwenta), address(0x1)));
rewardEscrowV2Implementation = address(new RewardEscrowV2(address(kwenta), address(0x1)));
}

/*//////////////////////////////////////////////////////////////
Expand All @@ -38,7 +37,9 @@ contract StakingV2SetupTests is StakingV1Setup {
(address rewardEscrowV2, address stakingRewardsV2) =
deployRewardEscrowV2AndStakingRewardsV2(address(this));

new EscrowMigrator(address(kwenta), address(rewardEscrowV1), rewardEscrowV2, stakingRewardsV2);
new EscrowMigrator(
address(kwenta), address(rewardEscrowV1), rewardEscrowV2, stakingRewardsV2
);
}

function test_Cannot_Setup_EscrowMigrator_With_Kwenta_Zero_Address() public {
Expand Down Expand Up @@ -76,37 +77,33 @@ contract StakingV2SetupTests is StakingV1Setup {
deployRewardEscrowV2AndStakingRewardsV2(address(this));

escrowMigratorImplementation = address(
new EscrowMigrator(address(kwenta), address(rewardEscrowV1), rewardEscrowV2, stakingRewardsV2)
new EscrowMigrator(
address(kwenta), address(rewardEscrowV1), rewardEscrowV2, stakingRewardsV2
)
);

vm.expectRevert(IEscrowMigrator.ZeroAddress.selector);
new ERC1967Proxy(
escrowMigratorImplementation,
abi.encodeWithSignature(
"initialize(address,address)",
address(0),
treasury
)
);
escrowMigratorImplementation,
abi.encodeWithSignature("initialize(address,address)", address(0), treasury)
);
}

function test_Cannot_Initialize_EscrowMigrator_Proxy_With_Treasury_Zero_Address() public {
(address rewardEscrowV2, address stakingRewardsV2) =
deployRewardEscrowV2AndStakingRewardsV2(address(this));

escrowMigratorImplementation = address(
new EscrowMigrator(address(kwenta), address(rewardEscrowV1), rewardEscrowV2, stakingRewardsV2)
new EscrowMigrator(
address(kwenta), address(rewardEscrowV1), rewardEscrowV2, stakingRewardsV2
)
);

vm.expectRevert(IEscrowMigrator.ZeroAddress.selector);
new ERC1967Proxy(
escrowMigratorImplementation,
abi.encodeWithSignature(
"initialize(address,address)",
address(0x1),
address(0)
)
);
escrowMigratorImplementation,
abi.encodeWithSignature("initialize(address,address)", address(0x1), address(0))
);
}

/*//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -136,12 +133,7 @@ contract StakingV2SetupTests is StakingV1Setup {
address rewardEscrowV2 = deployRewardEscrowV2(address(this));
vm.expectRevert(IStakingRewardsV2.ZeroAddress.selector);
stakingRewardsV2Implementation = address(
new StakingRewardsV2(
address(0),
address(usdc),
rewardEscrowV2,
address(supplySchedule)
)
new StakingRewardsV2(address(0), address(usdc), rewardEscrowV2, address(supplySchedule))
);
}

Expand All @@ -150,10 +142,7 @@ contract StakingV2SetupTests is StakingV1Setup {
vm.expectRevert(IStakingRewardsV2.ZeroAddress.selector);
stakingRewardsV2Implementation = address(
new StakingRewardsV2(
address(kwenta),
address(0),
rewardEscrowV2,
address(supplySchedule)
address(kwenta), address(0), rewardEscrowV2, address(supplySchedule)
)
);
}
Expand All @@ -162,10 +151,7 @@ contract StakingV2SetupTests is StakingV1Setup {
vm.expectRevert(IStakingRewardsV2.ZeroAddress.selector);
stakingRewardsV2Implementation = address(
new StakingRewardsV2(
address(kwenta),
address(usdc),
address(0),
address(supplySchedule)
address(kwenta), address(usdc), address(0), address(supplySchedule)
)
);
}
Expand All @@ -174,23 +160,15 @@ contract StakingV2SetupTests is StakingV1Setup {
address rewardEscrowV2 = deployRewardEscrowV2(address(this));
vm.expectRevert(IStakingRewardsV2.ZeroAddress.selector);
stakingRewardsV2Implementation = address(
new StakingRewardsV2(
address(kwenta),
address(usdc),
rewardEscrowV2,
address(0)
)
new StakingRewardsV2(address(kwenta), address(usdc), rewardEscrowV2, address(0))
);
}

function test_Cannot_Setup_StakingRewardsV2_With_Owner_Zero_Address() public {
address rewardEscrowV2 = deployRewardEscrowV2(address(this));
stakingRewardsV2Implementation = address(
new StakingRewardsV2(
address(kwenta),
address(usdc),
rewardEscrowV2,
address(supplySchedule)
address(kwenta), address(usdc), rewardEscrowV2, address(supplySchedule)
)
);
vm.expectRevert(IStakingRewardsV2.ZeroAddress.selector);
Expand All @@ -209,10 +187,7 @@ contract StakingV2SetupTests is StakingV1Setup {

stakingRewardsV2Implementation = address(
new StakingRewardsV2(
address(kwenta),
address(usdc),
rewardEscrowV2,
address(supplySchedule)
address(kwenta), address(usdc), rewardEscrowV2, address(supplySchedule)
)
);

Expand All @@ -224,24 +199,17 @@ contract StakingV2SetupTests is StakingV1Setup {
function deployRewardEscrowV2(address _owner) internal returns (address) {
return address(
new ERC1967Proxy(
rewardEscrowV2Implementation,
abi.encodeWithSignature(
"initialize(address)",
_owner
)
)
rewardEscrowV2Implementation, abi.encodeWithSignature("initialize(address)", _owner)
)
);
}

function deployStakingRewardsV2(address _owner) internal returns (address) {
return address(
new ERC1967Proxy(
stakingRewardsV2Implementation,
abi.encodeWithSignature(
"initialize(address)",
_owner
)
)
stakingRewardsV2Implementation,
abi.encodeWithSignature("initialize(address)", _owner)
)
);
}
}
9 changes: 7 additions & 2 deletions test/foundry/utils/mocks/MockERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MockERC20 is ERC20 {
constructor(string memory name, string memory symbol, uint256 _initialSupply, address _initialHolder) ERC20(name, symbol) {
constructor(
string memory name,
string memory symbol,
uint256 _initialSupply,
address _initialHolder
) ERC20(name, symbol) {
_mint(_initialHolder, _initialSupply);
}

Expand All @@ -15,4 +20,4 @@ contract MockERC20 is ERC20 {
function burn(address from, uint256 amount) external {
_burn(from, amount);
}
}
}
9 changes: 3 additions & 6 deletions test/foundry/utils/mocks/MockStakingRewardsV3.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ import {StakingRewardsV2} from "../../../../contracts/StakingRewardsV2.sol";
contract MockStakingRewardsV3 is StakingRewardsV2 {
uint256 public newNum;

constructor(
address _kwenta,
address _usdc,
address _rewardEscrow,
address _rewardNotifier
) StakingRewardsV2(_kwenta, _usdc, _rewardEscrow, _rewardNotifier) {}
constructor(address _kwenta, address _usdc, address _rewardEscrow, address _rewardNotifier)
StakingRewardsV2(_kwenta, _usdc, _rewardEscrow, _rewardNotifier)
{}

function setNewNum(uint256 _newNum) external {
newNum = _newNum;
Expand Down

0 comments on commit ed00da4

Please sign in to comment.