Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVG representation for Linear Vesting #210

Merged
merged 15 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions script/salts/salts.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
"0xed4ba02077e70f78db70ce191509333d2dcccfff136d30dcb011f567305e88ad": "0x2b8bc588174d409692f1bd993942e3806c9a11344dbe674f46aed32a030aacf1"
},
"Test_AllocatedMerkleAllowlist": {
"0xb17794250569bcd64aae2ec1312399120db92167bf0a2602821e0ee953dd3d31": "0xa8a4fc4fb8d721bdce27342cdd381eb510362146f49e56698a8bcb6c639306ff",
"0xecbee26b3d0e662be84e4cef678b23166957f507ca68f32eaa49e60ceb567981": "0x1598e58155ab6f6f2d8b2813c5c763f04ab980c3e65dffe2b3a312e8ccba4ae7"
"0x8de6e7b0b1f6974167a896ad8d377c8c29ad0132dd3f7b26f3aae7d4bb348d2f": "0xbafe0e1369edea3d992723bf3ff6a352dafbbb9f4dd6b81d52da4b538c123bb5",
"0xce7f9e37dca3a16d5c26ba67c9eba2e889ff76c1d27a05ed9ebd75083d46e241": "0x9c9a73570423fffe4c11df49d5434528af493273cd7424ec18e474b7940627ed"
},
"Test_CappedMerkleAllowlist": {
"0xa0ed568f98efa2efd4e93f21a5445970919a333349a8f5369a28ae93271d9cca": "0x6fb3e2a45254801d17269019f8afcadbd132d417f4dde1bfc65dd8f440256a56",
"0xfd2c28cb6c38931a1f784078c41d21d7bf8fc3653231edca225a5fbbc50529dc": "0x88a482ab0eacd2d6c1fc7b3858bfba29aa92b8abfc6239e02e6952640c3ebdf7"
"0x5abd4cf6f12f56a1077d607918110659db02bbb5f419e4f4643c926e7c78d701": "0x7e5435b4313ad9ef6d831b39306df989156afac6ebeb1c4644cd7bd63088bfb7",
"0xe577ed57cc6c3ce09f0d1f66fbf3fcb30b35fde4c350c8d515d0f930603c41df": "0x97167e0f92b3e91d6e0fb8637c5ddfa224a3ec191528f46208663258c0cb95c3"
},
"Test_GUniFactory": {
"0xa8ee5069b769099da4dbc8c5d4c95cb74d416554203119678be4d0eba33f5962": "0x767e6faad4f8e62d6ab897930a0eb497cb71ebc75f90856dc13996fb00b907d3"
Expand Down Expand Up @@ -85,13 +85,13 @@
"0x78a7c23f669f5df656575693f45f928b7af2ed4bc981cf6dec77bef2c03bb081": "0xf0bc4482fcf2593df36fb9fb83ee5d273e7ee6a3caa9414d9c24eeee96567b6f"
},
"Test_UniswapV2DirectToLiquidity": {
"0x9c33aa54294ebd7a8909181ebd6aed2b967b0eb4b0fb95467495624e6c211a67": "0xba73f6582c497ae5c4d38c53ba8bfb98266aa3566aaafef6d00f65d327effd66"
"0xf108beb959acb1e7e41cab1e1a3039f077c572167a9dadf5c31b642d80bc8c3c": "0x776bb071737d0bd3c0c1096a8a9d83574280b883b2681dadffaf6fa94fc669fc"
},
"Test_UniswapV2Router": {
"0xe6204aa211921628df345ff0b909c863298684cd8ca65de5479af6b70662e622": "0xf5700f795856223d45b9e1b76fa0f23db9d770b25c44cae8f556ae6d1e7bee5e"
},
"Test_UniswapV3DirectToLiquidity": {
"0xca7cd77c52253f2e1eec58c25dbb3b89ccaa938974767ed31217819f71d2db06": "0xdb4b3fa1df0a6205daaeb852a4b456a86df10140fd1d479072f7c62ea9ba7a79"
"0x5aec331792b9b995051d0efd683176c0800e527130eb7514f415c4f1a9f09f43": "0x37c69f7eea77a282f753c9ae1505d0272745cd870612e78e4e962285eb0de2d3"
},
"Test_UniswapV3Factory": {
"0xbcd657c3390ecd2e1782b6473400c51fa124922eb98b69f1b5192eb0f8e3d3df": "0xfad08a6eaa7974f06cec79e15064de7f6fa17b22ecdb3764988b2c4b1571c613"
Expand Down
15 changes: 12 additions & 3 deletions src/interfaces/modules/IDerivative.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ interface IDerivative {
/// @notice Metadata for a derivative token
///
/// @param exists True if the token has been deployed
/// @param wrapped True if an ERC20-wrapped derivative has been deployed
/// @param wrapped Non-zero if an ERC20-wrapped derivative has been deployed
/// @param underlyingToken The address of the underlying token
/// @param supply The total supply of the derivative token
/// @param data Implementation-specific data
struct Token {
bool exists;
address wrapped;
address underlyingToken;
uint256 supply;
bytes data;
}

Expand All @@ -30,13 +32,20 @@ interface IDerivative {
///
/// @param tokenId The ID of the derivative token
/// @return exists True if the token has been deployed
/// @return wrapped True if an ERC20-wrapped derivative has been deployed
/// @return wrapped Non-zero if an ERC20-wrapped derivative has been deployed
/// @return underlyingToken The address of the underlying token
/// @return supply The total supply of the derivative token
/// @return data Implementation-specific data
function tokenMetadata(uint256 tokenId)
external
view
returns (bool exists, address wrapped, address underlyingToken, bytes memory data);
returns (
bool exists,
address wrapped,
address underlyingToken,
uint256 supply,
bytes memory data
);

// ========== DERIVATIVE MANAGEMENT ========== //

Expand Down
12 changes: 12 additions & 0 deletions src/lib/ERC6909Metadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,16 @@ abstract contract ERC6909Metadata {
/// @param tokenId_ The ID of the token
/// @return uint8 The number of decimals used by the token
function decimals(uint256 tokenId_) public view virtual returns (uint8);

/// @notice Returns the URI of the token
///
/// @param tokenId_ The ID of the token
/// @return string The URI of the token
function tokenURI(uint256 tokenId_) public view virtual returns (string memory);

/// @notice Returns the total supply of the token
///
/// @param tokenId_ The ID of the token
/// @return uint256 The total supply of the token
function totalSupply(uint256 tokenId_) public view virtual returns (uint256);
}
251 changes: 251 additions & 0 deletions src/lib/SVG.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;

// hot-chain-svg: https://github.com/w1nt3r-eth/hot-chain-svg

// Core utils used extensively to format CSS and numbers.
library utils {
// used to simulate empty strings
string internal constant NULL = "";

// formats a CSS variable line. includes a semicolon for formatting.
function setCssVar(
string memory _key,
string memory _val
) internal pure returns (string memory) {
return string.concat("--", _key, ":", _val, ";");
}

// formats getting a css variable
function getCssVar(string memory _key) internal pure returns (string memory) {
return string.concat("var(--", _key, ")");
}

// formats getting a def URL
function getDefURL(string memory _id) internal pure returns (string memory) {
return string.concat("url(#", _id, ")");
}

// formats rgba white with a specified opacity / alpha
function white_a(uint256 _a) internal pure returns (string memory) {
return rgba(255, 255, 255, _a);
}

// formats rgba black with a specified opacity / alpha
function black_a(uint256 _a) internal pure returns (string memory) {
return rgba(0, 0, 0, _a);
}

// formats generic rgba color in css
function rgba(
uint256 _r,
uint256 _g,
uint256 _b,
uint256 _a
) internal pure returns (string memory) {
string memory formattedA = _a < 100 ? string.concat("0.", utils.uint2str(_a)) : "1";
return string.concat(
"rgba(",
utils.uint2str(_r),
",",
utils.uint2str(_g),
",",
utils.uint2str(_b),
",",
formattedA,
")"
);
}

// checks if two strings are equal
function stringsEqual(string memory _a, string memory _b) internal pure returns (bool) {
return keccak256(abi.encodePacked(_a)) == keccak256(abi.encodePacked(_b));
}

// returns the length of a string in characters
function utfStringLength(string memory _str) internal pure returns (uint256 length) {
uint256 i = 0;
bytes memory string_rep = bytes(_str);

while (i < string_rep.length) {
if (string_rep[i] >> 7 == 0) {
i += 1;
} else if (string_rep[i] >> 5 == bytes1(uint8(0x6))) {
i += 2;
} else if (string_rep[i] >> 4 == bytes1(uint8(0xE))) {
i += 3;
} else if (string_rep[i] >> 3 == bytes1(uint8(0x1E))) {
i += 4;
}
//For safety
else {
i += 1;
}

length++;
}
}

// converts an unsigned integer to a string
function uint2str(uint256 _i) internal pure returns (string memory _uintAsString) {
if (_i == 0) {
return "0";
}
uint256 j = _i;
uint256 len;
while (j != 0) {
len++;
j /= 10;
}
bytes memory bstr = new bytes(len);
uint256 k = len;
while (_i != 0) {
k = k - 1;
uint8 temp = (48 + uint8(_i - (_i / 10) * 10));
bytes1 b1 = bytes1(temp);
bstr[k] = b1;
_i /= 10;
}
return string(bstr);
}
}

// Core SVG utilitiy library which helps us construct
// onchain SVG's with a simple, web-like API.
library svg {
/* MAIN ELEMENTS */
function g(
string memory _props,
string memory _children
) internal pure returns (string memory) {
return el("g", _props, _children);
}

function path(
string memory _props,
string memory _children
) internal pure returns (string memory) {
return el("path", _props, _children);
}

function text(
string memory _props,
string memory _children
) internal pure returns (string memory) {
return el("text", _props, _children);
}

function line(
string memory _props,
string memory _children
) internal pure returns (string memory) {
return el("line", _props, _children);
}

function circle(
string memory _props,
string memory _children
) internal pure returns (string memory) {
return el("circle", _props, _children);
}

function circle(string memory _props) internal pure returns (string memory) {
return el("circle", _props);
}

function ellipse(
string memory _props,
string memory _children
) internal pure returns (string memory) {
return el("ellipse", _props, _children);
}

function ellipse(string memory _props) internal pure returns (string memory) {
return el("ellipse", _props);
}

function rect(
string memory _props,
string memory _children
) internal pure returns (string memory) {
return el("rect", _props, _children);
}

function rect(string memory _props) internal pure returns (string memory) {
return el("rect", _props);
}

function filter(
string memory _props,
string memory _children
) internal pure returns (string memory) {
return el("filter", _props, _children);
}

function cdata(string memory _content) internal pure returns (string memory) {
return string.concat("<![CDATA[", _content, "]]>");
}

/* GRADIENTS */
function radialGradient(
string memory _props,
string memory _children
) internal pure returns (string memory) {
return el("radialGradient", _props, _children);
}

function linearGradient(
string memory _props,
string memory _children
) internal pure returns (string memory) {
return el("linearGradient", _props, _children);
}

function gradientStop(
uint256 offset,
string memory stopColor,
string memory _props
) internal pure returns (string memory) {
return el(
"stop",
string.concat(
prop("stop-color", stopColor),
" ",
prop("offset", string.concat(utils.uint2str(offset), "%")),
" ",
_props
)
);
}

function animateTransform(string memory _props) internal pure returns (string memory) {
return el("animateTransform", _props);
}

function image(
string memory _href,
string memory _props
) internal pure returns (string memory) {
return el("image", string.concat(prop("href", _href), " ", _props));
}

/* COMMON */
// A generic element, can be used to construct any SVG (or HTML) element
function el(
string memory _tag,
string memory _props,
string memory _children
) internal pure returns (string memory) {
return string.concat("<", _tag, " ", _props, ">", _children, "</", _tag, ">");
}

// A generic element, can be used to construct any SVG (or HTML) element without children
function el(string memory _tag, string memory _props) internal pure returns (string memory) {
return string.concat("<", _tag, " ", _props, "/>");
}

// an SVG attribute
function prop(string memory _key, string memory _val) internal pure returns (string memory) {
return string.concat(_key, "=", '"', _val, '" ');
}
}
7 changes: 7 additions & 0 deletions src/modules/Derivative.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@ abstract contract DerivativeModule is IDerivative, ERC6909, ERC6909Metadata, Mod
function getTokenMetadata(uint256 tokenId) external view virtual returns (Token memory) {
return tokenMetadata[tokenId];
}

// ========== ERC6909 TOKEN SUPPLY EXTENSION ========== //

/// @inheritdoc ERC6909Metadata
function totalSupply(uint256 tokenId) public view virtual override returns (uint256) {
return tokenMetadata[tokenId].supply;
}
}
Loading
Loading