Skip to main content

SablierV2NFTDescriptor

Git Source

Inherits: ISablierV2NFTDescriptor

See the documentation in ISablierV2NFTDescriptor.

Functions

tokenURI

Produces the URI describing a particular stream NFT.

This is a data URI with the JSON contents directly inlined.

function tokenURI(IERC721Metadata sablier, uint256 streamId) external view override returns (string memory uri);

Parameters

NameTypeDescription
sablierIERC721MetadataThe address of the Sablier contract the stream was created in.
streamIduint256The ID of the stream for which to produce a description.

Returns

NameTypeDescription
uristringThe URI of the ERC721-compliant metadata.

abbreviateAmount

Creates an abbreviated representation of the provided amount, rounded down and prefixed with ">= ".

The abbreviation uses these suffixes:

  • "K" for thousands
  • "M" for millions
  • "B" for billions
  • "T" for trillions For example, if the input is 1,234,567, the output is ">= 1.23M".
function abbreviateAmount(uint256 amount, uint256 decimals) internal pure returns (string memory);

Parameters

NameTypeDescription
amountuint256The amount to abbreviate, denoted in units of decimals.
decimalsuint256The number of decimals to assume when abbreviating the amount.

Returns

NameTypeDescription
<none>stringabbreviation The abbreviated representation of the provided amount, as a string.

calculateDurationInDays

Calculates the stream's duration in days, rounding down.

function calculateDurationInDays(uint256 startTime, uint256 endTime) internal pure returns (string memory);

calculateStreamedPercentage

Calculates how much of the deposited amount has been streamed so far, as a percentage with 4 implied decimals.

function calculateStreamedPercentage(uint128 streamedAmount, uint128 depositedAmount) internal pure returns (uint256);

generateAccentColor

Generates a pseudo-random HSL color by hashing together the chainid, the sablier address, and the streamId. This will be used as the accent color for the SVG.

function generateAccentColor(address sablier, uint256 streamId) internal view returns (string memory);

generateAttributes

Generates an array of JSON objects that represent the NFT's attributes:

  • Asset symbol
  • Sender address
  • Status

These attributes are useful for filtering and sorting the NFTs.

function generateAttributes(
string memory assetSymbol,
string memory sender,
string memory status
)
internal
pure
returns (string memory);

generateDescription

Generates a string with the NFT's JSON metadata description, which provides a high-level overview.

function generateDescription(
string memory sablierModel,
string memory assetSymbol,
string memory sablierStringified,
string memory assetAddress,
string memory streamId,
bool isTransferable
)
internal
pure
returns (string memory);

generateName

Generates a string with the NFT's JSON metadata name, which is unique for each stream.

The streamId is equivalent to the ERC-721 tokenId.

function generateName(string memory sablierModel, string memory streamId) internal pure returns (string memory);

isAllowedCharacter

Checks whether the provided string contains only alphanumeric characters, spaces, and dashes.

Note that this returns true for empty strings.

function isAllowedCharacter(string memory str) internal pure returns (bool);

mapSymbol

Maps ERC-721 symbols to human-readable model names.

Reverts if the symbol is unknown.

function mapSymbol(IERC721Metadata sablier) internal view returns (string memory);

safeAssetDecimals

Retrieves the asset's decimals safely, defaulting to "0" if an error occurs.

Performs a low-level call to handle assets in which the decimals are not implemented.

function safeAssetDecimals(address asset) internal view returns (uint8);

safeAssetSymbol

Retrieves the asset's symbol safely, defaulting to a hard-coded value if an error occurs.

Performs a low-level call to handle assets in which the symbol is not implemented or it is a bytes32 instead of a string.

function safeAssetSymbol(address asset) internal view returns (string memory);

stringifyFractionalAmount

Converts the provided fractional amount to a string prefixed by a dot.

function stringifyFractionalAmount(uint256 fractionalAmount) internal pure returns (string memory);

Parameters

NameTypeDescription
fractionalAmountuint256A numerical value with 2 implied decimals.

stringifyPercentage

Converts the provided percentage to a string.

function stringifyPercentage(uint256 percentage) internal pure returns (string memory);

Parameters

NameTypeDescription
percentageuint256A numerical value with 4 implied decimals.

stringifyStatus

Retrieves the stream's status as a string.

function stringifyStatus(Lockup.Status status) internal pure returns (string memory);

Structs

TokenURIVars

Needed to avoid Stack Too Deep.

struct TokenURIVars {
address asset;
string assetSymbol;
uint128 depositedAmount;
bool isTransferable;
string json;
bytes returnData;
ISablierV2Lockup sablier;
string sablierModel;
string sablierStringified;
string status;
string svg;
uint256 streamedPercentage;
bool success;
}