Skip to content

Commit

Permalink
move some metadata logic over to MetadataRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
0age committed Oct 19, 2024
1 parent cfadafd commit 3481246
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/TheCompact.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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`.
Expand Down
13 changes: 13 additions & 0 deletions src/lib/MetadataRenderer.sol
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit 3481246

Please sign in to comment.