Skip to content

Commit

Permalink
chore: use LibString from solmate
Browse files Browse the repository at this point in the history
  • Loading branch information
jpgonzalezra committed Jan 21, 2024
1 parent fd7eeab commit 7606454
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 101 deletions.
1 change: 0 additions & 1 deletion lib/ERC721A
Submodule ERC721A deleted from 184359
7 changes: 3 additions & 4 deletions packages/contracts/src/LucidOrigins.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@ import { Face } from "./layers/Face.sol";
import { Body } from "./layers/Body.sol";
import { Head } from "./layers/Head.sol";
import { Blush } from "./layers/Blush.sol";
import { String } from "./utils/String.sol";
import { LibString } from "solmate/utils/LibString.sol";
import { Constants } from "./utils/constants.sol";

contract LucidOrigins is Owned, ERC721A, Background, Face, Body, Head, Blush {
using Encoder for string;
using String for string;
using String for uint256;
using LibString for uint256;

constructor() Owned(msg.sender) ERC721A("LucidOrigins", "LucidOrigins") { }

function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
uint16[] memory dna = getDna(uint256(keccak256(abi.encodePacked(tokenId))));

string memory name = string(abi.encodePacked("LucidOrigins #", tokenId.uint2str()));
string memory name = string(abi.encodePacked("LucidOrigins #", tokenId.toString()));
string memory header = '<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" width="400" height="400">';

uint256 r = normalizeToRange(dna[Constants.R_INDEX], 1, 255);
Expand Down
19 changes: 9 additions & 10 deletions packages/contracts/src/layers/Body.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
pragma solidity 0.8.21;

// import { console2 } from "forge-std/console2.sol";
import { String } from "../utils/String.sol";
import { LibString } from "solmate/utils/LibString.sol";

contract Body {
using String for uint256;
using String for int256;
using LibString for uint256;

function body(
uint256 r,
Expand Down Expand Up @@ -49,27 +48,27 @@ contract Body {
'<linearGradient id="linear-grad">',
'<stop offset="0" stop-color="',
"rgb(",
r.uint2str(),
r.toString(),
",",
g.uint2str(),
g.toString(),
",",
b.uint2str(),
b.toString(),
')"/>',
'<stop offset="1" stop-color="',
"rgb(",
r2.uint2str(),
r2.toString(),
",",
g2.uint2str(),
g2.toString(),
",",
b2.uint2str(),
b2.toString(),
')"/>',
"</linearGradient>",
"</defs>"
)
);

string memory fillColor = isPlain
? string(abi.encodePacked("rgb(", r.uint2str(), ",", g.uint2str(), ",", b.uint2str(), ")"))
? string(abi.encodePacked("rgb(", r.toString(), ",", g.toString(), ",", b.toString(), ")"))
: "url(#linear-grad)";

return (colorDefs, fillColor);
Expand Down
65 changes: 32 additions & 33 deletions packages/contracts/src/layers/Face.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
pragma solidity 0.8.21;

// import { console2 } from "forge-std/console2.sol";
import { String } from "../utils/String.sol";
import { LibString } from "solmate/utils/LibString.sol";

contract Face {
using String for uint256;
using String for int256;
using LibString for uint256;

function face(
uint256 eyeRadius,
Expand Down Expand Up @@ -44,26 +43,26 @@ contract Face {
abi.encodePacked(
'<g id="face">',
'<circle cx="',
(50 - eyeSeparation / 2).uint2str(),
(50 - eyeSeparation / 2).toString(),
'" cy="40" r="',
eyeRadius.uint2str(),
eyeRadius.toString(),
'" fill="',
linesColor,
'" transform="rotate(',
eyebrowRotation.uint2str(),
eyebrowRotation.toString(),
" ",
(50 - eyeSeparation / 2).uint2str(),
(50 - eyeSeparation / 2).toString(),
' 40)"/>',
'<circle cx="',
(50 + eyeSeparation / 2).uint2str(),
(50 + eyeSeparation / 2).toString(),
'" cy="40" r="',
eyeRadius.uint2str(),
eyeRadius.toString(),
'" fill="',
linesColor,
'" transform="rotate(',
eyebrowRotation.uint2str(),
eyebrowRotation.toString(),
" ",
(50 + eyeSeparation / 2).uint2str(),
(50 + eyeSeparation / 2).toString(),
' 40)"/>',
"</g>"
)
Expand All @@ -87,38 +86,38 @@ contract Face {
abi.encodePacked(
'<g id="eyebrows">',
'<line x1="',
(35 - eyebrowSize).uint2str(),
(35 - eyebrowSize).toString(),
'" y1="',
(30 - eyebrowLength).uint2str(),
(30 - eyebrowLength).toString(),
'" x2="',
(45 + eyebrowSize).uint2str(),
(45 + eyebrowSize).toString(),
'" y2="',
(30 - eyebrowLength).uint2str(),
(30 - eyebrowLength).toString(),
'" stroke="',
linesColor,
'" stroke-width="4" stroke-linecap="round" transform="rotate(',
eyebrowRotation.uint2str(),
eyebrowRotation.toString(),
" 35 ",
(30 - eyebrowLength).uint2str(),
(30 - eyebrowLength).toString(),
") scale(",
leftEyebrowScale.uint2str(),
leftEyebrowScale.toString(),
')"/>',
'<line x1="',
(60 - eyebrowSize).uint2str(),
(60 - eyebrowSize).toString(),
'" y1="',
(30 - eyebrowLength).uint2str(),
(30 - eyebrowLength).toString(),
'" x2="',
(65 + eyebrowSize).uint2str(),
(65 + eyebrowSize).toString(),
'" y2="',
(30 - eyebrowLength).uint2str(),
(30 - eyebrowLength).toString(),
'" stroke="',
linesColor,
'" stroke-width="4" stroke-linecap="round" transform="rotate(',
eyebrowRotation.uint2str(),
eyebrowRotation.toString(),
" 65 ",
(30 - eyebrowLength).uint2str(),
(30 - eyebrowLength).toString(),
") scale(",
rightEyebrowScale.uint2str(),
rightEyebrowScale.toString(),
')"/>',
"</g>"
)
Expand Down Expand Up @@ -150,23 +149,23 @@ contract Face {
abi.encodePacked(
'<g id="mouth">',
'<path d="M',
x1.uint2str(),
x1.toString(),
" ",
y1.uint2str(),
y1.toString(),
" Q",
x2.uint2str(),
x2.toString(),
" ",
y2.uint2str(),
y2.toString(),
" ",
x3.uint2str(),
x3.toString(),
" ",
y3.uint2str(),
y3.toString(),
'" stroke="',
linesColor,
'" stroke-width="4" fill="transparent" stroke-linecap="round" transform="rotate(',
mouthRotation.uint2str(),
mouthRotation.toString(),
" 50 ",
(50 + controlY).uint2str(),
(50 + controlY).toString(),
')"/>',
"</g>"
)
Expand Down
15 changes: 7 additions & 8 deletions packages/contracts/src/layers/Head.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity 0.8.21;

// import { console2 } from "forge-std/console2.sol";
import { String } from "../utils/String.sol";
import { LibString } from "solmate/utils/LibString.sol";
import { Trigonometry } from "solidity-trigonometry/Trigonometry.sol";

contract Head {
Expand All @@ -11,8 +11,7 @@ contract Head {
int256 y;
}

using String for int256;
using String for uint256;
using LibString for int256;
using Trigonometry for uint256;

function head(
Expand Down Expand Up @@ -69,7 +68,7 @@ contract Head {
string memory svgPath;
Point memory mid = Point({ x: (points[0].x + points[1].x) / 2, y: (points[0].y + points[1].y) / 2 });

svgPath = string(abi.encodePacked("M", mid.x.int2str(), ",", mid.y.int2str()));
svgPath = string(abi.encodePacked("M", mid.x.toString(), ",", mid.y.toString()));

for (uint256 i = 0; i < points.length; i++) {
Point memory p1 = points[(i + 1) % points.length];
Expand All @@ -80,13 +79,13 @@ contract Head {
abi.encodePacked(
svgPath,
"Q",
p1.x.int2str(),
p1.x.toString(),
",",
p1.y.int2str(),
p1.y.toString(),
",",
midPoint.x.int2str(),
midPoint.x.toString(),
",",
midPoint.y.int2str()
midPoint.y.toString()
)
);
}
Expand Down
45 changes: 0 additions & 45 deletions packages/contracts/src/utils/String.sol

This file was deleted.

0 comments on commit 7606454

Please sign in to comment.