Skip to content

Commit

Permalink
Split into two steps, the freeze which should be called on fork initi…
Browse files Browse the repository at this point in the history
…ation and the actual forking which can be called after the fork
  • Loading branch information
edmundedgar committed Feb 27, 2024
1 parent c65c533 commit ea4eaec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
9 changes: 5 additions & 4 deletions contracts/ForkableRealityETH_ERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,14 @@ contract ForkableRealityETH_ERC20 is
IForkonomicToken(childToken).transfer(_childRealityETH, amount);
}

// TODO: Make sure this gets called on initiateFork, it can't wait until executeFork because we can't arbitrate anything else that happens
// It may be simpler to let anybody call it and have it check with the fork manager that we're forking
function handleFork() external onlyForkManger onlyAfterForking {
function handleInitiateFork() external onlyForkManger {
freezeTs = uint32(block.timestamp);
}

function handleExecuteFork() external onlyAfterForking {
uint256 balance = token.balanceOf(address(this));
IForkonomicToken(address(token)).splitTokensIntoChildTokens(balance);
_moveTokensToChild(children[0], balance);
_moveTokensToChild(children[1], balance);
freezeTs = uint32(block.timestamp);
}
}
9 changes: 6 additions & 3 deletions test/ForkableRealityETH.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,9 @@ contract ForkableRealityETHTest is Test {
);

vm.prank(parentForkmanager);
ForkableRealityETH_ERC20(_forkableRealityETH).handleFork();
ForkableRealityETH_ERC20(_forkableRealityETH).handleInitiateFork();

ForkableRealityETH_ERC20(_forkableRealityETH).handleExecuteFork();

return (forkableRealityETH1, forkableRealityETH2);
}
Expand Down Expand Up @@ -430,8 +432,9 @@ contract ForkableRealityETHTest is Test {
function testHandleForkOnlyAfterForking() public {
// Testing revert if children are not yet created
vm.prank(forkmanager);
ForkableRealityETH_ERC20(forkableRealityETH).handleInitiateFork();
vm.expectRevert(IForkableStructure.OnlyAfterForking.selector);
ForkableRealityETH_ERC20(forkableRealityETH).handleFork();
ForkableRealityETH_ERC20(forkableRealityETH).handleExecuteFork();
}

function _testTemplateCreation(address _forkableRealityETH) internal {
Expand Down Expand Up @@ -942,7 +945,7 @@ contract ForkableRealityETHTest is Test {
);

// This moves the internal record that we owe the user money.
// The actual tokens were already transferred in handleFork()
// The actual tokens were already transferred in handleExecuteFork()

// User 1 should have got his bond, then the same again as the takeover fee, minus the claim fee.
uint256 expectedBalanceYes1 = bond1 + bond1 - (bond1 / 40);
Expand Down

0 comments on commit ea4eaec

Please sign in to comment.