From 34812465f9db6269ee961e417ff26e91e36e6194 Mon Sep 17 00:00:00 2001 From: 0age <37939117+0age@users.noreply.github.com> Date: Sat, 19 Oct 2024 12:30:49 -0700 Subject: [PATCH] move some metadata logic over to MetadataRenderer --- src/TheCompact.sol | 6 ++---- src/lib/MetadataRenderer.sol | 13 +++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/TheCompact.sol b/src/TheCompact.sol index 80b97b1..7f686d0 100644 --- a/src/TheCompact.sol +++ b/src/TheCompact.sol @@ -10,7 +10,6 @@ import { IdLib } from "./lib/IdLib.sol"; import { EfficiencyLib } from "./lib/EfficiencyLib.sol"; import { FunctionCastLib } from "./lib/FunctionCastLib.sol"; import { HashLib } from "./lib/HashLib.sol"; -import { MetadataLib } from "./lib/MetadataLib.sol"; import { ValidityLib } from "./lib/ValidityLib.sol"; import { Extsload } from "./lib/Extsload.sol"; import { ERC6909 } from "solady/tokens/ERC6909.sol"; @@ -175,7 +174,6 @@ contract TheCompact is ITheCompact, ERC6909, Extsload { using IdLib for address; using IdLib for Lock; using IdLib for ResetPeriod; - using MetadataLib for address; using SafeTransferLib for address; using FixedPointMathLib for uint256; using EfficiencyLib for bool; @@ -741,12 +739,12 @@ contract TheCompact is ITheCompact, ERC6909, Extsload { /// @dev Returns the symbol for token `id`. function name(uint256 id) public view virtual override returns (string memory) { - return string.concat("Compact ", id.toToken().readNameWithDefaultValue()); + return _METADATA_RENDERER.name(id); } /// @dev Returns the symbol for token `id`. function symbol(uint256 id) public view virtual override returns (string memory) { - return string.concat(unicode"🤝-", id.toToken().readSymbolWithDefaultValue()); + return _METADATA_RENDERER.symbol(id); } /// @dev Returns the Uniform Resource Identifier (URI) for token `id`. diff --git a/src/lib/MetadataRenderer.sol b/src/lib/MetadataRenderer.sol index 1a945f2..2484f34 100644 --- a/src/lib/MetadataRenderer.sol +++ b/src/lib/MetadataRenderer.sol @@ -1,13 +1,26 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.27; +import { EfficiencyLib } from "./EfficiencyLib.sol"; import { MetadataLib } from "./MetadataLib.sol"; import { Lock } from "../types/Lock.sol"; contract MetadataRenderer { + using EfficiencyLib for uint256; using MetadataLib for Lock; + using MetadataLib for address; function uri(Lock memory lock, uint256 id) external view returns (string memory) { return lock.toURI(id); } + + /// @dev Returns the symbol for token `id`. + function name(uint256 id) public view returns (string memory) { + return string.concat("Compact ", id.asSanitizedAddress().readNameWithDefaultValue()); + } + + /// @dev Returns the symbol for token `id`. + function symbol(uint256 id) public view returns (string memory) { + return string.concat(unicode"🤝-", id.asSanitizedAddress().readSymbolWithDefaultValue()); + } }