Skip to content

Commit

Permalink
Simplify the atPhase modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
jummy123 authored and cryptofish7 committed Feb 1, 2022
1 parent a7f8996 commit 430312a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 29 deletions.
26 changes: 2 additions & 24 deletions contracts/LaunchEvent.sol
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@ contract LaunchEvent {
uint256 _issuerTimelock
) external atPhase(Phase.NotStarted) {
require(auctionStart == 0, "LaunchEvent: already initialized");
rocketJoeFactory = IRocketJoeFactory(msg.sender);
require(
_token != rocketJoeFactory.wavax(),
"LaunchEvent: token is wavax"
);

rocketJoeFactory = IRocketJoeFactory(msg.sender);
WAVAX = IWAVAX(rocketJoeFactory.wavax());
router = IJoeRouter02(rocketJoeFactory.router());
factory = IJoeFactory(rocketJoeFactory.factory());
Expand Down Expand Up @@ -639,29 +639,7 @@ contract LaunchEvent {
/// @dev Bytecode size optimization for the `atPhase` modifier
/// This works becuase internal functions are not in-lined in modifiers
function _atPhase(Phase _phase) internal view {
if (_phase == Phase.NotStarted) {
require(
currentPhase() == Phase.NotStarted,
"LaunchEvent: not in not started"
);
} else if (_phase == Phase.PhaseOne) {
require(
currentPhase() == Phase.PhaseOne,
"LaunchEvent: not in phase one"
);
} else if (_phase == Phase.PhaseTwo) {
require(
currentPhase() == Phase.PhaseTwo,
"LaunchEvent: not in phase two"
);
} else if (_phase == Phase.PhaseThree) {
require(
currentPhase() == Phase.PhaseThree,
"LaunchEvent: not in phase three"
);
} else {
revert("LaunchEvent: unknown state");
}
require(currentPhase() == _phase, "LaunchEvent: wrong phase");
}

/// @dev Bytecode size optimization for the `timelockElapsed` modifier
Expand Down
4 changes: 2 additions & 2 deletions test/LaunchEventPhaseOne.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe("launch event contract phase one", function () {
this.LaunchEvent.connect(this.participant).depositAVAX({
value: ethers.utils.parseEther("1.0"),
})
).to.be.revertedWith("LaunchEvent: not in phase one");
).to.be.revertedWith("LaunchEvent: wrong phase");
});

it("should allow burning of rJOE even if it's not approved", async function () {
Expand Down Expand Up @@ -275,7 +275,7 @@ describe("launch event contract phase one", function () {
await advanceTimeAndBlock(duration.seconds(120));
expect(
this.LaunchEvent.connect(this.dev).createPair()
).to.be.revertedWith("LaunchEvent: not in phase three");
).to.be.revertedWith("LaunchEvent: wrong phase");
});

it("should revert trying to send AVAX to the contract", async function () {
Expand Down
2 changes: 1 addition & 1 deletion test/LaunchEventPhaseThree.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe("launch event contract phase three", function () {
this.LaunchEvent.connect(this.participant).depositAVAX({
value: ethers.utils.parseEther("1"),
})
).to.be.revertedWith("LaunchEvent: not in phase one");
).to.be.revertedWith("LaunchEvent: wrong phase");
});

it("should revert when withdraw liquidity if pair not created", async function () {
Expand Down
4 changes: 2 additions & 2 deletions test/LaunchEventPhaseTwo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ describe("launch event contract phase two", function () {
this.LaunchEvent.connect(this.participant).depositAVAX({
value: ethers.utils.parseEther("1.0"),
})
).to.be.revertedWith("LaunchEvent: not in phase one");
).to.be.revertedWith("LaunchEvent: wrong phase");
});

it("should revert try to create pool", async function () {
expect(
this.LaunchEvent.connect(this.participant).createPair()
).to.be.revertedWith("LaunchEvent: not in phase three");
).to.be.revertedWith("LaunchEvent: wrong phase");
});

it("should charge a fixed withdraw penalty", async function () {
Expand Down

0 comments on commit 430312a

Please sign in to comment.