Skip to content

Commit

Permalink
𓊍 Fee step
Browse files Browse the repository at this point in the history
  • Loading branch information
z0r0z committed Feb 13, 2024
1 parent 5ccf694 commit bb09ff0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 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: 53716)
IETest:testCommandSendERC0() (gas: 114314)
IETest:testCommandSendETH() (gas: 80786)
IETest:testCommandSendUSDC() (gas: 147022)
IETest:testCommandSwapDAI() (gas: 101220)
IETest:testCommandSwapUSDC() (gas: 156282)
IETest:testDeploy() (gas: 2094014)
IETest:testCommandSwapDAI() (gas: 101295)
IETest:testCommandSwapUSDC() (gas: 156369)
IETest:testDeploy() (gas: 2105248)
IETest:testENSNameFromENSHelper() (gas: 29103)
IETest:testENSNameOwnership() (gas: 109286)
IETest:testIENameSetting() (gas: 8187)
Expand Down
12 changes: 7 additions & 5 deletions src/IE.sol
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ contract IE {
}
bool zeroForOne = _tokenIn < _tokenOut;
uint256 _amountIn = _stringToUint(amountIn, isETH ? 18 : _tokenIn.readDecimals());
address pool = _computePoolAddress(_tokenIn, _tokenOut);
address pool = _computePoolAddress(_tokenIn, _tokenOut, 3000);
ISwapRouter(pool).swap(
msg.sender,
zeroForOne,
Expand All @@ -294,24 +294,26 @@ contract IE {
);
}

/// @dev Computes the create2 address for given token pair.
function _computePoolAddress(address tokenA, address tokenB)
/// @dev Computes the create2 address for given token pair. Starts mid fee.
function _computePoolAddress(address tokenA, address tokenB, uint24 fee)
internal
view
virtual
returns (address pool)
{
if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA);
bytes32 salt = keccak256(abi.encode(tokenA, tokenB, 3000));
bytes32 salt = keccak256(abi.encode(tokenA, tokenB, fee));
assembly ("memory-safe") {
// Compute and store the bytecode hash.
mstore8(0x00, 0xff) // Write the prefix.
mstore(0x35, UNISWAP_V3_POOL_INIT_CODE_HASH)
mstore(0x01, shl(96, UNISWAP_V3_FACTORY))
mstore(0x15, salt)
pool := keccak256(0x00, 0x55)
mstore(0x35, 0) // Restore the overwritten part of the free memory pointer.
mstore(0x35, 0) // Restore the overwritten
}
if (pool.code.length != 0) return pool;
else return _computePoolAddress(tokenA, tokenB, 500);
}

/// @dev Fallback `uniswapV3SwapCallback`.
Expand Down

0 comments on commit bb09ff0

Please sign in to comment.