Skip to content

Commit

Permalink
comments, selector, and reference
Browse files Browse the repository at this point in the history
  • Loading branch information
dianakocsis committed Sep 24, 2024
1 parent d0b81fe commit 4d53d2a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/PositionDescriptor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ contract PositionDescriptor is IPositionDescriptor {
(PoolKey memory poolKey, PositionInfo positionInfo) = positionManager.getPoolAndPositionInfo(tokenId);
(, int24 tick,,) = poolManager.getSlot0(poolKey.toId());

// If possible, flip currencies to get the larger currency as the base currency, so that the price (quote/base) is more readable
// flip if currency0 priority is greater than currency1 priority
bool _flipRatio = flipRatio(Currency.unwrap(poolKey.currency0), Currency.unwrap(poolKey.currency1));

Expand Down
1 change: 1 addition & 0 deletions src/libraries/AddressStringUtil.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.8.20;

/// @title AddressStringUtil
/// @notice provides utility functions for converting addresses to strings
/// @dev Reference: https://github.com/Uniswap/solidity-lib/blob/master/contracts/libraries/AddressStringUtil.sol
library AddressStringUtil {
/// @notice Converts an address to the uppercase hex string, extracting only len bytes (up to 20, multiple of 2)
/// @param addr the address to convert
Expand Down
7 changes: 4 additions & 3 deletions src/libraries/SafeERC20Namer.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "./AddressStringUtil.sol";

/// @title SafeERC20Namer
/// @notice produces token descriptors from inconsistent or absent ERC20 symbol implementations that can return string or bytes32
/// this library will always produce a string symbol to represent the token
/// @dev Reference: https://github.com/Uniswap/solidity-lib/blob/master/contracts/libraries/SafeERC20Namer.sol
library SafeERC20Namer {
function bytes32ToString(bytes32 x) private pure returns (string memory) {
bytes memory bytesString = new bytes(32);
Expand Down Expand Up @@ -37,7 +39,7 @@ library SafeERC20Namer {
/// @return the token symbol
function callAndParseStringReturn(address token, bytes4 selector) private view returns (string memory) {
(bool success, bytes memory data) = token.staticcall(abi.encodeWithSelector(selector));
// if not implemented, or returns empty data, return empty string
// if not implemented, return empty string
if (!success) {
return "";
}
Expand All @@ -55,8 +57,7 @@ library SafeERC20Namer {
/// @param token the token address
/// @return the token symbol
function tokenSymbol(address token) internal view returns (string memory) {
// 0x95d89b41 = bytes4(keccak256("symbol()"))
string memory symbol = callAndParseStringReturn(token, 0x95d89b41);
string memory symbol = callAndParseStringReturn(token, IERC20Metadata.symbol.selector);
if (bytes(symbol).length == 0) {
// fallback to 6 uppercase hex of address
return addressToSymbol(token);
Expand Down

0 comments on commit 4d53d2a

Please sign in to comment.