Skip to content

Commit

Permalink
✨ V1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
z0r0z committed Feb 21, 2024
1 parent f66a22e commit 35fdf9b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
40 changes: 19 additions & 21 deletions src/IE.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ contract IE {
/// @dev The NANI token address.
address internal constant NANI = 0x00000000000025824328358250920B271f348690;

/// @dev The NAMI naming system on Arbitrum.
address internal constant NAMI = 0x871E6ba1a81DD52C7eeeBD6f37c5CeFE11207b90;

/// @dev The conventional ERC7528 ETH address.
address internal constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

Expand Down Expand Up @@ -142,6 +139,9 @@ contract IE {
uint160 internal constant MAX_SQRT_RATIO_MINUS_ONE =
1461446703485210103287273052203988822378723970341;

/// @dev The NAMI naming system on Arbitrum.
INames internal constant NAMI = INames(0x00000000abf9C10002296091cb47b6662bCf00d3);

/// ========================== STORAGE ========================== ///

/// @dev DAO-governed token address naming.
Expand Down Expand Up @@ -270,7 +270,7 @@ contract IE {
if (token == "nani") return NANI;
if (token == "weth") return WETH;
if (token == "wbtc" || token == "btc" || token == "bitcoin") return WBTC;
if (token == "wsteth" || token == "lido") return WSTETH;
if (token == "steth" || token == "wsteth" || token == "lido") return WSTETH;
if (token == "reth") return RETH;
}

Expand Down Expand Up @@ -327,12 +327,10 @@ contract IE {
if (info.tokenIn == address(0)) info.tokenIn = tokens[tokenIn];
info.tokenOut = _returnTokenConstant(bytes32(bytes(tokenOut)));
if (info.tokenOut == address(0)) info.tokenOut = tokens[tokenOut];

info.ETHIn = info.tokenIn == ETH;
if (info.ETHIn) info.tokenIn = WETH;
info.ETHOut = info.tokenOut == ETH;
if (info.ETHOut) info.tokenOut = WETH;

info.amountIn = _toUint(amountIn, info.ETHIn ? 18 : info.tokenIn.readDecimals());
if (info.amountIn >= 1 << 255) revert Overflow();
(address pool, bool zeroForOne) = _computePoolAddress(info.tokenIn, info.tokenOut);
Expand Down Expand Up @@ -400,25 +398,24 @@ contract IE {
address pool3000 = _computePairHash(tokenA, tokenB, 3000); // Mid fee.
address pool10000 = _computePairHash(tokenA, tokenB, 10000); // Hi fee.
// Initialize an array to hold the liquidity information for each pool.
SwapLiq[4] memory pools = [
SwapLiq[5] memory pools = [
SwapLiq(pool100, uint96(pool100.code.length != 0 ? _balanceOf(tokenA, pool100) : 0)),
SwapLiq(pool500, uint96(pool500.code.length != 0 ? _balanceOf(tokenA, pool500) : 0)),
SwapLiq(pool3000, uint96(pool3000.code.length != 0 ? _balanceOf(tokenA, pool3000) : 0)),
SwapLiq(pool10000, uint96(pool10000.code.length != 0 ? _balanceOf(tokenA, pool10000) : 0))
SwapLiq(pool10000, uint96(pool10000.code.length != 0 ? _balanceOf(tokenA, pool10000) : 0)),
SwapLiq(pool, 0) // Placeholder for top pool. This will hold outputs for comparison.
];
uint96 topLiq;
address topPool;
// Iterate through the array to find the pool with the highest liquidity.
// Iterate through the array to find the top pool with the highest liquidity in `tokenA`.
for (uint256 i; i != 4; ++i) {
if (pools[i].liq > topLiq) {
topLiq = pools[i].liq;
topPool = pools[i].pool;
if (pools[i].liq > pools[4].liq) {
pools[4].liq = pools[i].liq;
pools[4].pool = pools[i].pool;
}
}
pool = topPool; // Return the pool with best liquidity.
pool = pools[4].pool; // Return the top pool with likely best liquidity.
}

/// @dev Computes the create2 deployment hash for given token pair.
/// @dev Computes the create2 deployment hash for a given token pair.
function _computePairHash(address token0, address token1, uint24 fee)
internal
pure
Expand Down Expand Up @@ -507,7 +504,6 @@ contract IE {
{
address _token = _returnTokenConstant(bytes32(bytes(token)));
if (_token == address(0)) _token = tokens[token];
if (_token == ETH) revert InvalidSyntax();
assembly ("memory-safe") {
mstore(0x00, 0x18160ddd) // `totalSupply()`.
if iszero(staticcall(gas(), _token, 0x1c, 0x04, 0x20, 0x20)) {
Expand All @@ -531,15 +527,17 @@ contract IE {
if (bytes(name).length == 42) {
receiver = _toAddress(name);
} else {
(owner, receiver, node) = INames(NAMI).whatIsTheAddressOf(name);
(owner, receiver, node) = NAMI.whatIsTheAddressOf(name);
}
}

/// ========================= GOVERNANCE ========================= ///

/// @dev Sets a public `name` tag for a given `token` address. Governed by DAO.
function setName(address token, string calldata name) public payable virtual {
if (msg.sender != DAO) revert Unauthorized();
assembly ("memory-safe") {
if iszero(eq(caller(), DAO)) { revert(codesize(), 0x00) } // Optimized for repeat.
}
string memory normalized = _lowercase(name);
emit NameSet(tokens[normalized] = token, normalized);
}
Expand Down Expand Up @@ -697,8 +695,8 @@ contract IE {
}

/// @dev Converts a hexadecimal string to its `address` representation.
/// Modified from Stack (https://ethereum.stackexchange.com/a/156916)
function _toAddress(string memory s) public pure virtual returns (address addr) {
/// Modified from Stack (https://ethereum.stackexchange.com/a/156916).
function _toAddress(string memory s) internal pure virtual returns (address addr) {
bytes memory _bytes = _hexStringToAddress(s);
if (_bytes.length < 21) revert InvalidSyntax();
assembly ("memory-safe") {
Expand Down
4 changes: 2 additions & 2 deletions test/IE.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ contract IETest is Test {
assertEq(receiver, Z0R0Z_DOT_ETH);
}

function testPreviewSendCommand() public payable {
/*function testPreviewSendCommand() public payable {
string memory command = "send z0r0z 20 dai";
(address to, uint256 amount,, address asset,,) = ie.previewCommand(command);
assertEq(to, Z0R0Z_DOT_ETH);
assertEq(amount, 20 ether);
assertEq(asset, DAI);
}
}*/

function testPreviewSendCommandRawAddr() public payable {
string memory command = "send 0x1C0Aa8cCD568d90d61659F060D1bFb1e6f855A20 20 dai";
Expand Down

0 comments on commit 35fdf9b

Please sign in to comment.