Skip to content

Commit

Permalink
⚡ Smol optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
z0r0z committed Feb 14, 2024
1 parent 2302c5f commit 91beaba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
6 changes: 3 additions & 3 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ IETest:testBalanceInETH() (gas: 40334)
IETest:testCommandSendERC0() (gas: 103038)
IETest:testCommandSendETH() (gas: 69510)
IETest:testCommandSendUSDC() (gas: 135746)
IETest:testCommandSwapDAI() (gas: 102032)
IETest:testCommandSwapUSDC() (gas: 156050)
IETest:testDeploy() (gas: 2589624)
IETest:testCommandSwapDAI() (gas: 102001)
IETest:testCommandSwapUSDC() (gas: 156019)
IETest:testDeploy() (gas: 2576590)
IETest:testENSNameOwnership() (gas: 84123)
IETest:testIENameSetting() (gas: 8187)
IETest:testPreviewCommandSendDecimals() (gas: 92044)
Expand Down
13 changes: 5 additions & 8 deletions src/IE.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ contract IE {

/// ======================= CUSTOM ERRORS ======================= ///

/// @dev Bad math.
error Overflow();

/// @dev Caller fails.
error Unauthorized();

Expand Down Expand Up @@ -302,11 +305,12 @@ contract IE {
WETH.safeTransferETH(msg.value);
}
uint256 _amountIn = _stringToUint(amountIn, isETH ? 18 : _tokenIn.readDecimals());
if (_amountIn >= 1 << 255) revert Overflow();
(address pool, bool zeroForOne) = _computePoolAddress(_tokenIn, _tokenOut, 3000);
ISwapRouter(pool).swap(
msg.sender,
zeroForOne,
_toInt256(_amountIn),
int256(_amountIn),
zeroForOne ? MIN_SQRT_RATIO_PLUS_ONE : MAX_SQRT_RATIO_MINUS_ONE,
abi.encodePacked(isETH, msg.sender, _tokenIn, _tokenOut)
);
Expand Down Expand Up @@ -483,13 +487,6 @@ contract IE {
emit NameSet(tokens[normalizedSymbol] = token, normalizedSymbol);
}

/// ====================== SAFECAST UTILITY ====================== ///

function _toInt256(uint256 x) internal pure virtual returns (int256) {
if (x >= 1 << 255) revert("Overflow");
return int256(x);
}

/// ===================== STRING OPERATIONS ===================== ///

/// @dev Returns copy of string in lowercase.
Expand Down

0 comments on commit 91beaba

Please sign in to comment.