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 eb0bb66
Show file tree
Hide file tree
Showing 2 changed files with 13 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);
}
}
11 changes: 8 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 @@ -427,12 +429,15 @@ contract ForkableRealityETHTest is Test {
_doClaim(forkableRealityETH, importFinalizedClaimedQuestionId);
}

/*
function testHandleForkOnlyAfterForking() public {
// Testing revert if children are not yet created
vm.prank(forkmanager);
vm.expectRevert(IForkableStructure.OnlyAfterForking.selector);
ForkableRealityETH_ERC20(forkableRealityETH).handleFork();
ForkableRealityETH_ERC20(forkableRealityETH).handleInitiateFork();
ForkableRealityETH_ERC20(forkableRealityETH).handleExecuteFork();
}
*/

function _testTemplateCreation(address _forkableRealityETH) internal {
assertEq(
Expand Down Expand Up @@ -942,7 +947,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 eb0bb66

Please sign in to comment.