Skip to content

Commit

Permalink
more reversions
Browse files Browse the repository at this point in the history
  • Loading branch information
dianakocsis committed Oct 31, 2024
1 parent d7cb3ee commit 81ab148
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/positionDescriptor bytecode size.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
31690
31728
38 changes: 19 additions & 19 deletions src/PositionDescriptor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
20 changes: 10 additions & 10 deletions src/libraries/Descriptor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."
)
);
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
}
}
2 changes: 1 addition & 1 deletion src/libraries/SVG.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/libraries/SafeCurrencyMetadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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 "";
Expand Down
4 changes: 2 additions & 2 deletions test/PositionDescriptor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)
)
);
Expand Down Expand Up @@ -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."
)
)
);
Expand Down

0 comments on commit 81ab148

Please sign in to comment.