Skip to content

Commit

Permalink
warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dianakocsis committed Sep 19, 2024
1 parent 0ba4e38 commit 2b518bf
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 47 deletions.
30 changes: 0 additions & 30 deletions src/libraries/Descriptor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ library Descriptor {
}

/// @notice Escapes double quotes in a string if they are present
/// @param symbol The string to escape
/// @return The string with double quotes escaped
function escapeQuotes(string memory symbol) internal pure returns (string memory) {
bytes memory symbolBytes = bytes(symbol);
uint8 quotesCount = 0;
Expand Down Expand Up @@ -339,11 +337,6 @@ library Descriptor {
return uint256(x >= 0 ? x : -x);
}
/// @notice Returns string that includes first 5 significant figures of a decimal number
/// @param sqrtRatioX96 a sqrt price
/// @param baseCurrencyDecimals The decimals of the base currency
/// @param quoteCurrencyDecimals The decimals of the quote currency
/// @return The decimal string
function fixedPointToDecimalString(uint160 sqrtRatioX96, uint8 baseCurrencyDecimals, uint8 quoteCurrencyDecimals)
internal
pure
Expand Down Expand Up @@ -455,9 +448,6 @@ library Descriptor {
return generateDecimalString(params);
}
/// @notice Converts an address to a string
/// @param addr The address to convert
/// @return The address as a string
function addressToString(address addr) internal pure returns (string memory) {
return (uint256(uint160(addr))).toHexString(20);
}
Expand Down Expand Up @@ -508,13 +498,6 @@ library Descriptor {
}
}
/// @notice Scales a number from one range to another
/// @param n The number to scale
/// @param inMn The minimum of the input range
/// @param inMx The maximum of the input range
/// @param outMn The minimum of the output range
/// @param outMx The maximum of the output range
/// @return The scaled number as a string
function scale(uint256 n, uint256 inMn, uint256 inMx, uint256 outMn, uint256 outMx)
private
pure
Expand All @@ -523,27 +506,14 @@ library Descriptor {
return (n - inMn * (outMx - outMn) / (inMx - inMn) + outMn).toString();
}
/// @notice Converts a currency to a color in hex to be used in the SVG
/// @param currency The currency
/// @param offset The offset to slice the token hex
/// @return str The color hex as a string
function currencyToColorHex(uint256 currency, uint256 offset) internal pure returns (string memory str) {
return string((currency >> offset).toHexStringNoPrefix(3));
}
/// @notice Gets the coordinate for a circle
/// @param currency The currency ID
/// @param offset The offset to slice the token hex
/// @param tokenId The token ID
/// @return The coordinate
function getCircleCoord(uint256 currency, uint256 offset, uint256 tokenId) internal pure returns (uint256) {
return (sliceCurrencyHex(currency, offset) * tokenId) % 255;
}
/// @notice Slices the currency ID hex
/// @param currency The currency ID
/// @param offset The offset to slice the token hex
/// @return The sliced hex
function sliceCurrencyHex(uint256 currency, uint256 offset) internal pure returns (uint256) {
return uint256(uint8(currency >> offset));
}
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/HexStrings.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;

/// @title HexStrings
/// @notice Provides function for converting numbers to hexadecimal strings
library HexStrings {
bytes16 internal constant ALPHABET = "0123456789abcdef";

Expand Down
6 changes: 1 addition & 5 deletions src/libraries/SafeERC20Namer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import "./AddressStringUtil.sol";
/// @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
library SafeERC20Namer {
/// @notice converts a bytes32 to a string
/// @param x the bytes32 to convert
/// @return the string representation
function bytes32ToString(bytes32 x) private pure returns (string memory) {
bytes memory bytesString = new bytes(32);
uint256 charCount = 0;
Expand All @@ -27,8 +24,7 @@ library SafeERC20Namer {
return string(bytesStringTrimmed);
}

/// @notice uses a heuristic to produce a token symbol from the address
// the heuristic returns the first 6 hex of the address string in upper case
/// @notice produces a token symbol from the address - the first 6 hex of the address string in upper case
/// @param token the token address
/// @return the token symbol
function addressToSymbol(address token) private pure returns (string memory) {
Expand Down
1 change: 0 additions & 1 deletion test/PositionDescriptor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,5 @@ contract PositionDescriptorTest is Test, PosmTestSetup {
// decode json
bytes memory data = vm.parseJson(json);
Token memory token = abi.decode(data, (Token));
console2.log("token.image", token.image);
}
}
20 changes: 10 additions & 10 deletions test/libraries/Descriptor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract DescriptorTest is Test {
assertEq(Descriptor.feeToPercentString(12300000), "1230%");
}

function test_addressToString_succeeds() public {
function test_addressToString_succeeds() public pure {
assertEq(Descriptor.addressToString(address(0)), "0x0000000000000000000000000000000000000000");
assertEq(Descriptor.addressToString(address(1)), "0x0000000000000000000000000000000000000001");
assertEq(
Expand All @@ -38,7 +38,7 @@ contract DescriptorTest is Test {
);
}

function test_escapeQuotes_succeeds() public {
function test_escapeQuotes_succeeds() public pure {
assertEq(Descriptor.escapeQuotes(""), "");
assertEq(Descriptor.escapeQuotes("a"), "a");
assertEq(Descriptor.escapeQuotes("abc"), "abc");
Expand All @@ -49,7 +49,7 @@ contract DescriptorTest is Test {
assertEq(Descriptor.escapeQuotes("\"a\"b\"c\"\""), "\\\"a\\\"b\\\"c\\\"\\\"");
}

function test_tickToDecimalString_withTickSpacing10() public {
function test_tickToDecimalString_withTickSpacing10() public pure {
int24 tickSpacing = 10;
int24 minTick = (TickMath.MIN_TICK / tickSpacing) * tickSpacing;
int24 maxTick = (TickMath.MAX_TICK / tickSpacing) * tickSpacing;
Expand All @@ -63,7 +63,7 @@ contract DescriptorTest is Test {
);
}

function test_tickToDecimalString_withTickSpacing60() public {
function test_tickToDecimalString_withTickSpacing60() public pure {
int24 tickSpacing = 60;
int24 minTick = (TickMath.MIN_TICK / tickSpacing) * tickSpacing;
int24 maxTick = (TickMath.MAX_TICK / tickSpacing) * tickSpacing;
Expand All @@ -77,7 +77,7 @@ contract DescriptorTest is Test {
);
}

function test_tickToDecimalString_withTickSpacing200() public {
function test_tickToDecimalString_withTickSpacing200() public pure {
int24 tickSpacing = 200;
int24 minTick = (TickMath.MIN_TICK / tickSpacing) * tickSpacing;
int24 maxTick = (TickMath.MAX_TICK / tickSpacing) * tickSpacing;
Expand All @@ -91,30 +91,30 @@ contract DescriptorTest is Test {
);
}

function test_tickToDecimalString_ratio_returnsInverseMediumNumbers() public {
function test_tickToDecimalString_ratio_returnsInverseMediumNumbers() public pure {
int24 tickSpacing = 200;
assertEq(Descriptor.tickToDecimalString(10, tickSpacing, 18, 18, false), "1.0010");
assertEq(Descriptor.tickToDecimalString(10, tickSpacing, 18, 18, true), "0.99900");
}

function test_tickToDecimalString_ratio_returnsInverseLargeNumbers() public {
function test_tickToDecimalString_ratio_returnsInverseLargeNumbers() public pure {
int24 tickSpacing = 200;
assertEq(Descriptor.tickToDecimalString(487272, tickSpacing, 18, 18, false), "1448400000000000000000");
assertEq(Descriptor.tickToDecimalString(487272, tickSpacing, 18, 18, true), "0.00000000000000000000069041");
}

function test_tickToDecimalString_ratio_returnsInverseSmallNumbers() public {
function test_tickToDecimalString_ratio_returnsInverseSmallNumbers() public pure {
int24 tickSpacing = 200;
assertEq(Descriptor.tickToDecimalString(-387272, tickSpacing, 18, 18, false), "0.000000000000000015200");
assertEq(Descriptor.tickToDecimalString(-387272, tickSpacing, 18, 18, true), "65791000000000000");
}

function test_tickToDecimalString_differentDecimals() public {
function test_tickToDecimalString_differentDecimals() public pure {
int24 tickSpacing = 200;
assertEq(Descriptor.tickToDecimalString(1000, tickSpacing, 18, 18, true), "0.90484");
assertEq(Descriptor.tickToDecimalString(1000, tickSpacing, 18, 10, true), "90484000");
assertEq(Descriptor.tickToDecimalString(1000, tickSpacing, 10, 18, true), "0.0000000090484");
}

function test_fixedPointToDecimalString_succeeds() public {}
function test_fixedPointToDecimalString_succeeds() public pure {}
}
2 changes: 1 addition & 1 deletion test/mocks/MockERC721Permit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract MockERC721Permit is ERC721Permit_v4 {
_mint(msg.sender, tokenId);
}

function tokenURI(uint256 id) public view override returns (string memory) {
function tokenURI(uint256) public pure override returns (string memory) {
return "mock";
}
}

0 comments on commit 2b518bf

Please sign in to comment.