SablierV2NFTDescriptor
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
Name | Type | Description |
---|---|---|
sablier | IERC721Metadata | The address of the Sablier contract the stream was created in. |
streamId | uint256 | The id of the stream for which to produce a description. |
Returns
Name | Type | Description |
---|---|---|
uri | string | The 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
Name | Type | Description |
---|---|---|
amount | uint256 | The amount to abbreviate, denoted in units of decimals . |
decimals | uint256 | The number of decimals to assume when abbreviating the amount. |
Returns
Name | Type | Description |
---|---|---|
<none> | string | abbreviation 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 streamingModel,
string memory assetSymbol,
string memory streamId,
string memory sablierAddress,
string memory assetAddress
)
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 streamingModel, string memory streamId) internal pure returns (string memory);
mapSymbol
Maps ERC-721 symbols to human-readable streaming models.
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
Name | Type | Description |
---|---|---|
fractionalAmount | uint256 | A numerical value with 2 implied decimals. |
stringifyPercentage
Converts the provided percentage to a string.
function stringifyPercentage(uint256 percentage) internal pure returns (string memory);
Parameters
Name | Type | Description |
---|---|---|
percentage | uint256 | A 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;
string json;
ISablierV2Lockup sablier;
string sablierAddress;
string status;
string svg;
uint256 streamedPercentage;
string streamingModel;
}