Skip to content

Commit

Permalink
callFromDAO now wrapped in a try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
othernet-global committed Feb 18, 2024
1 parent f94310e commit 5f1a520
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/dao/DAO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,15 @@ contract DAO is IDAO, Parameters, ReentrancyGuard

else if ( ballot.ballotType == BallotType.CALL_CONTRACT )
{
ICalledContract(ballot.address1).callFromDAO( ballot.number1 );
try ICalledContract(ballot.address1).callFromDAO(ballot.number1)
{
}
catch (bytes memory)
{
}

emit ContractCalled(ballot.address1, ballot.number1);
}
}

else if ( ballot.ballotType == BallotType.INCLUDE_COUNTRY )
{
Expand Down
14 changes: 14 additions & 0 deletions src/dao/tests/DAO.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1049,5 +1049,19 @@ contract TestDAO is Deployment

assertFalse( poolsConfig.tokenHasBeenWhitelisted(token, wbtc, weth), "Token should not have been whitelisted" );
}



function testCallContractApproveRevertHandled() public {
// Arrange
vm.startPrank(alice);
staking.stakeSALT(1000000 ether);

TestERC20 brokenReceiver = new TestERC20( "TEST", 18 );

uint256 ballotID = proposals.proposeCallContract(address(brokenReceiver), 123, "description" );

_voteForAndFinalizeBallot(ballotID, Vote.YES);
}
}

6 changes: 3 additions & 3 deletions src/pools/tests/Pools.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1831,20 +1831,20 @@ function testAdjustReservesForSwap_Overflow_Bug_Audit() public {
vm.stopPrank();

// get pool reserves before swap
(uint256 reserves0Before, uint256 reserves1Before) = pools.getPoolReserves(tokenIn, tokenOut);
pools.getPoolReserves(tokenIn, tokenOut);

uint256 tokenAmountToSwap = 1500;
uint256 minAmountOut = 1;

vm.prank(alice);
tokenIn.transfer(bob, tokenAmountToSwap + 100);

uint256 tokenOutBalanceBeforeSwap = tokenOut.balanceOf(bob);
tokenOut.balanceOf(bob);
vm.startPrank(bob);
tokenIn.approve(address(pools), type(uint256).max);

vm.expectRevert( "Reserves overflow after swap" );
uint256 amountOut = pools.depositSwapWithdraw(
pools.depositSwapWithdraw(
tokenIn,
tokenOut,
tokenAmountToSwap,
Expand Down

0 comments on commit 5f1a520

Please sign in to comment.