Skip to content

Commit

Permalink
use an efficiency lib fn
Browse files Browse the repository at this point in the history
  • Loading branch information
0age committed Oct 17, 2024
1 parent 240249f commit a373941
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/lib/EfficiencyLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ library EfficiencyLib {
}
}

function isNullAddress(address account) internal pure returns (bool isNull) {
assembly {
isNull := iszero(shl(96, account))
}
}

function asUint256(bool a) internal pure returns (uint256 b) {
assembly {
b := a
Expand Down
8 changes: 5 additions & 3 deletions src/lib/MetadataLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Lock } from "../types/Lock.sol";
import { ResetPeriod } from "../types/ResetPeriod.sol";
// TODO: add scope to metadata
import { IdLib } from "./IdLib.sol";
import { EfficiencyLib } from "./EfficiencyLib.sol";
import { LibString } from "solady/utils/LibString.sol";
import { MetadataReaderLib } from "solady/utils/MetadataReaderLib.sol";

Expand All @@ -13,13 +14,14 @@ library MetadataLib {
using MetadataLib for string;
using IdLib for Lock;
using IdLib for ResetPeriod;
using EfficiencyLib for address;
using LibString for uint256;
using LibString for address;
using MetadataReaderLib for address;

function toURI(Lock memory lock, uint256 id) internal view returns (string memory uri) {
string memory tokenAddress =
lock.token == address(0) ? "Native Token" : lock.token.toHexStringChecksummed();
lock.token.isNullAddress() ? "Native Token" : lock.token.toHexStringChecksummed();
string memory allocator = lock.allocator.toHexStringChecksummed();
string memory resetPeriod =
string.concat(lock.resetPeriod.toSeconds().toString(), " seconds"); // TODO: return minutes / hours / days
Expand Down Expand Up @@ -76,7 +78,7 @@ library MetadataLib {
returns (string memory symbol)
{
// NOTE: this will not take into account the correct symbol on many chains
if (token == address(0)) {
if (token.isNullAddress()) {
return "ETH";
}

Expand All @@ -91,7 +93,7 @@ library MetadataLib {
view
returns (string memory decimals)
{
if (token == address(0)) {
if (token.isNullAddress()) {
return "18";
}
return uint256(token.readDecimals()).toString();
Expand Down

0 comments on commit a373941

Please sign in to comment.