From 81ab148c1a69ed978cb1fe3dfd12ff0d91963ce2 Mon Sep 17 00:00:00 2001 From: dianakocsis Date: Thu, 31 Oct 2024 12:29:40 -0400 Subject: [PATCH] more reversions --- .../positionDescriptor bytecode size.snap | 2 +- src/PositionDescriptor.sol | 38 +++++++++---------- src/libraries/Descriptor.sol | 20 +++++----- src/libraries/SVG.sol | 2 +- src/libraries/SafeCurrencyMetadata.sol | 16 ++++---- test/PositionDescriptor.t.sol | 4 +- 6 files changed, 41 insertions(+), 41 deletions(-) diff --git a/.forge-snapshots/positionDescriptor bytecode size.snap b/.forge-snapshots/positionDescriptor bytecode size.snap index 361cdd47..4babbfb1 100644 --- a/.forge-snapshots/positionDescriptor bytecode size.snap +++ b/.forge-snapshots/positionDescriptor bytecode size.snap @@ -1 +1 @@ -31690 \ No newline at end of file +31728 \ No newline at end of file diff --git a/src/PositionDescriptor.sol b/src/PositionDescriptor.sol index 40a0313f..06e164e6 100644 --- a/src/PositionDescriptor.sol +++ b/src/PositionDescriptor.sol @@ -57,7 +57,7 @@ contract PositionDescriptor is IPositionDescriptor { address currency0 = Currency.unwrap(poolKey.currency0); address currency1 = Currency.unwrap(poolKey.currency1); - // If possible, flip currencies to get the larger one as the base, so that the price (quote/base) is more readable + // If possible, flip currencies to get the larger currency as the base, so that the price (quote/base) is more readable // flip if currency0 priority is greater than currency1 priority bool _flipRatio = flipRatio(currency0, currency1); @@ -87,36 +87,36 @@ contract PositionDescriptor is IPositionDescriptor { ); } - /// @notice Returns true if address0 has higher priority than address1 - /// @param address0 The first address - /// @param address1 The second address - /// @return flipRatio True if address0 has higher priority than address1 - function flipRatio(address address0, address address1) public view returns (bool) { - return currencyRatioPriority(address0) > currencyRatioPriority(address1); + /// @notice Returns true if currency0 has higher priority than currency1 + /// @param currency0 The first currency address + /// @param currency1 The second currency address + /// @return flipRatio True if currency0 has higher priority than currency1 + function flipRatio(address currency0, address currency1) public view returns (bool) { + return currencyRatioPriority(currency0) > currencyRatioPriority(currency1); } - /// @notice Returns the priority of an address. - /// For certain addresses on mainnet, the smaller the address, the higher the priority - /// @param addr The address - /// @return priority The priority of the address - function currencyRatioPriority(address addr) public view returns (int256) { - // Addresses in order of priority on mainnet: USDC, USDT, DAI, (ETH, WETH), TBTC, WBTC + /// @notice Returns the priority of a currency. + /// For certain currencies on mainnet, the smaller the currency, the higher the priority + /// @param currency The currency address + /// @return priority The priority of the currency + function currencyRatioPriority(address currency) public view returns (int256) { + // Currencies in order of priority on mainnet: USDC, USDT, DAI, (ETH, WETH), TBTC, WBTC // wrapped native is different address on different chains. passed in constructor // native address - if (addr == address(0) || addr == wrappedNative) { + if (currency == address(0) || currency == wrappedNative) { return CurrencyRatioSortOrder.DENOMINATOR; } if (block.chainid == 1) { - if (addr == USDC) { + if (currency == USDC) { return CurrencyRatioSortOrder.NUMERATOR_MOST; - } else if (addr == USDT) { + } else if (currency == USDT) { return CurrencyRatioSortOrder.NUMERATOR_MORE; - } else if (addr == DAI) { + } else if (currency == DAI) { return CurrencyRatioSortOrder.NUMERATOR; - } else if (addr == TBTC) { + } else if (currency == TBTC) { return CurrencyRatioSortOrder.DENOMINATOR_MORE; - } else if (addr == WBTC) { + } else if (currency == WBTC) { return CurrencyRatioSortOrder.DENOMINATOR_MOST; } else { return 0; diff --git a/src/libraries/Descriptor.sol b/src/libraries/Descriptor.sol index 76176a4c..ba261f85 100644 --- a/src/libraries/Descriptor.sol +++ b/src/libraries/Descriptor.sol @@ -136,7 +136,7 @@ library Descriptor { /// @notice Generates the second part of the description for a Uniswap v4 NFTs /// @param tokenId The token ID - /// @param baseCurrencySymbol The symbol of the base address + /// @param baseCurrencySymbol The symbol of the base currency /// @param quoteCurrency The address of the quote currency /// @param baseCurrency The address of the base currency /// @param hooks The address of the hooks contract @@ -165,7 +165,7 @@ library Descriptor { "\\nToken ID: ", tokenId, "\\n\\n", - unicode"⚠️ DISCLAIMER: Due diligence is imperative when assessing this NFT. Make sure currencies match the expected currencies, as currency symbols may be imitated." + unicode"⚠️ DISCLAIMER: Due diligence is imperative when assessing this NFT. Make sure currency addresses match the expected currencies, as currency symbols may be imitated." ) ); } @@ -261,8 +261,8 @@ library Descriptor { /// MIN or MAX are returned if tick is at the bottom or top of the price curve /// @param tick The tick (either tickLower or tickUpper) /// @param tickSpacing The tick spacing of the pool - /// @param baseCurrencyDecimals The decimals of the base address - /// @param quoteCurrencyDecimals The decimals of the quote address + /// @param baseCurrencyDecimals The decimals of the base currency + /// @param quoteCurrencyDecimals The decimals of the quote currency /// @param flipRatio True if the ratio was flipped /// @return The ratio value as a string function tickToDecimalString( @@ -305,8 +305,8 @@ library Descriptor { /// @notice Adjusts the sqrt price for different currencies with different decimals /// @param sqrtRatioX96 The sqrt price at a specific tick - /// @param baseCurrencyDecimals The decimals of the base address - /// @param quoteCurrencyDecimals The decimals of the quote address + /// @param baseCurrencyDecimals The decimals of the base currency + /// @param quoteCurrencyDecimals The decimals of the quote currency /// @return adjustedSqrtRatioX96 The adjusted sqrt price function adjustForDecimalPrecision(uint160 sqrtRatioX96, uint8 baseCurrencyDecimals, uint8 quoteCurrencyDecimals) private @@ -518,11 +518,11 @@ library Descriptor { return string((currency >> offset).toHexStringNoPrefix(3)); } - function getCircleCoord(uint256 addr, uint256 offset, uint256 tokenId) internal pure returns (uint256) { - return (sliceAddressHex(addr, offset) * tokenId) % 255; + function getCircleCoord(uint256 currency, uint256 offset, uint256 tokenId) internal pure returns (uint256) { + return (sliceCurrencyHex(currency, offset) * tokenId) % 255; } - function sliceAddressHex(uint256 addr, uint256 offset) internal pure returns (uint256) { - return uint256(uint8(addr >> offset)); + function sliceCurrencyHex(uint256 currency, uint256 offset) internal pure returns (uint256) { + return uint256(uint8(currency >> offset)); } } diff --git a/src/libraries/SVG.sol b/src/libraries/SVG.sol index 89360e07..2731a6ca 100644 --- a/src/libraries/SVG.sol +++ b/src/libraries/SVG.sol @@ -157,7 +157,7 @@ library SVG { ); } - /// @notice Generate the SVG for the moving border text displaying the quote and base currencies with their symbols + /// @notice Generate the SVG for the moving border text displaying the quote and base currency addresses with their symbols /// @param quoteCurrency The quote currency /// @param baseCurrency The base currency /// @param quoteCurrencySymbol The quote currency symbol diff --git a/src/libraries/SafeCurrencyMetadata.sol b/src/libraries/SafeCurrencyMetadata.sol index b9115d55..cc88ab84 100644 --- a/src/libraries/SafeCurrencyMetadata.sol +++ b/src/libraries/SafeCurrencyMetadata.sol @@ -10,7 +10,7 @@ import {AddressStringUtil} from "./AddressStringUtil.sol"; library SafeCurrencyMetadata { uint8 constant MAX_SYMBOL_LENGTH = 12; - /// @notice attempts to extract the token symbol. if it does not implement symbol, returns a symbol derived from the currency address + /// @notice attempts to extract the currency symbol. if it does not implement symbol, returns a symbol derived from the address /// @param currency The currency address /// @param nativeLabel The native label /// @return the currency symbol @@ -21,7 +21,7 @@ library SafeCurrencyMetadata { string memory symbol = callAndParseStringReturn(currency, IERC20Metadata.symbol.selector); if (bytes(symbol).length == 0) { // fallback to 6 uppercase hex of address - return currencyToSymbol(currency); + return addressToSymbol(currency); } if (bytes(symbol).length > MAX_SYMBOL_LENGTH) { return truncateSymbol(symbol); @@ -67,18 +67,18 @@ library SafeCurrencyMetadata { } /// @notice produces a symbol from the address - the first 6 hex of the address string in upper case - /// @param currency The currency address + /// @param currencyAddress the address of the currency /// @return the symbol - function currencyToSymbol(address currency) private pure returns (string memory) { - return AddressStringUtil.toAsciiString(currency, 6); + function addressToSymbol(address currencyAddress) private pure returns (string memory) { + return AddressStringUtil.toAsciiString(currencyAddress, 6); } /// @notice calls an external view contract method that returns a symbol, and parses the output into a string - /// @param currency The currency address + /// @param currencyAddress the address of the currency /// @param selector the selector of the symbol method /// @return the symbol - function callAndParseStringReturn(address currency, bytes4 selector) private view returns (string memory) { - (bool success, bytes memory data) = currency.staticcall(abi.encodeWithSelector(selector)); + function callAndParseStringReturn(address currencyAddress, bytes4 selector) private view returns (string memory) { + (bool success, bytes memory data) = currencyAddress.staticcall(abi.encodeWithSelector(selector)); // if not implemented, return empty string if (!success) { return ""; diff --git a/test/PositionDescriptor.t.sol b/test/PositionDescriptor.t.sol index be3c909c..4b326814 100644 --- a/test/PositionDescriptor.t.sol +++ b/test/PositionDescriptor.t.sol @@ -185,7 +185,7 @@ contract PositionDescriptorTest is Test, PosmTestSetup, GasSnapshot { "\nToken ID: ", id, "\n\n", - unicode"⚠️ DISCLAIMER: Due diligence is imperative when assessing this NFT. Make sure currencies match the expected currencies, as currency symbols may be imitated." + unicode"⚠️ DISCLAIMER: Due diligence is imperative when assessing this NFT. Make sure currency addresses match the expected currencies, as currency symbols may be imitated." ) ) ); @@ -300,7 +300,7 @@ contract PositionDescriptorTest is Test, PosmTestSetup, GasSnapshot { "\nToken ID: ", id, "\n\n", - unicode"⚠️ DISCLAIMER: Due diligence is imperative when assessing this NFT. Make sure currencies match the expected currencies, as currency symbols may be imitated." + unicode"⚠️ DISCLAIMER: Due diligence is imperative when assessing this NFT. Make sure currency addresses match the expected currencies, as currency symbols may be imitated." ) ) );