Skip to content

Commit

Permalink
leave 1 wei in GS
Browse files Browse the repository at this point in the history
  • Loading branch information
alex0207s committed Nov 30, 2023
1 parent 75449d1 commit c7cdde6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 6 additions & 3 deletions contracts/GenericSwap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,19 @@ contract GenericSwap is IGenericSwap, TokenCollector, EIP712 {

if (_inputToken.isETH()) {
if (msg.value != _swapData.takerTokenAmount) revert InvalidMsgValue();
}

if (!_inputToken.isETH()) {
} else {
if (msg.value != 0) revert InvalidMsgValue();
_collect(_inputToken, _authorizedUser, _swapData.maker, _swapData.takerTokenAmount, _takerTokenPermit);
}

IStrategy(_swapData.maker).executeStrategy{ value: msg.value }(_inputToken, _outputToken, _swapData.takerTokenAmount, _swapData.strategyData);

returnAmount = _outputToken.getBalance(address(this));
if (returnAmount > 1) {
unchecked {
--returnAmount;
}
}
if (returnAmount < _swapData.minMakerTokenAmount) revert InsufficientOutput();

_outputToken.transferTo(_swapData.recipient, returnAmount);
Expand Down
3 changes: 3 additions & 0 deletions test/forkMainnet/GenericSwap.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ contract GenericSwapTest is Test, Tokens, BalanceUtil, Permit2Helper, SigHelper
genericSwap = new GenericSwap(UNISWAP_PERMIT2_ADDRESS, address(allowanceTarget));
smartStrategy = new SmartOrderStrategy(strategyAdmin, address(genericSwap), WETH_ADDRESS);

// deposit 1 wei in SOR and GS
deal(DAI_ADDRESS, address(smartStrategy), 1 wei);
deal(DAI_ADDRESS, address(genericSwap), 1 wei);
deal(address(genericSwap), 1 wei);

mockStrategy = new MockStrategy();
vm.prank(strategyAdmin);
Expand Down

0 comments on commit c7cdde6

Please sign in to comment.