From eb0bb669d229c51c4a18d2dc16522749d44620b6 Mon Sep 17 00:00:00 2001 From: Edmund Edgar Date: Tue, 27 Feb 2024 06:07:31 +0000 Subject: [PATCH] Split into two steps, the freeze which should be called on fork initiation and the actual forking which can be called after the fork --- contracts/ForkableRealityETH_ERC20.sol | 9 +++++---- test/ForkableRealityETH.t.sol | 11 ++++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/contracts/ForkableRealityETH_ERC20.sol b/contracts/ForkableRealityETH_ERC20.sol index 9fd8372f..61edb3f5 100644 --- a/contracts/ForkableRealityETH_ERC20.sol +++ b/contracts/ForkableRealityETH_ERC20.sol @@ -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); } } diff --git a/test/ForkableRealityETH.t.sol b/test/ForkableRealityETH.t.sol index 04c77a1c..ab6db6db 100644 --- a/test/ForkableRealityETH.t.sol +++ b/test/ForkableRealityETH.t.sol @@ -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); } @@ -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( @@ -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);