Source Code
Overview
ETH Balance
0 ETH
ETH Value
$0.00| Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
Latest 1 internal transaction
| Parent Transaction Hash | Block | From | To | |||
|---|---|---|---|---|---|---|
| 110814779 | 855 days ago | Contract Creation | 0 ETH |
Cross-Chain Transactions
Loading...
Loading
Contract Name:
SablierV2NFTDescriptor
Compiler Version
v0.8.19+commit.7dd6d404
Optimization Enabled:
Yes with 1000 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-3.0-or-later
// solhint-disable max-line-length,quotes
pragma solidity >=0.8.19;
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import { IERC721Metadata } from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
import { Base64 } from "@openzeppelin/contracts/utils/Base64.sol";
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
import { ISablierV2Lockup } from "./interfaces/ISablierV2Lockup.sol";
import { ISablierV2NFTDescriptor } from "./interfaces/ISablierV2NFTDescriptor.sol";
import { Lockup } from "./types/DataTypes.sol";
import { Errors } from "./libraries/Errors.sol";
import { NFTSVG } from "./libraries/NFTSVG.sol";
import { SVGElements } from "./libraries/SVGElements.sol";
/// @title SablierV2NFTDescriptor
/// @notice See the documentation in {ISablierV2NFTDescriptor}.
contract SablierV2NFTDescriptor is ISablierV2NFTDescriptor {
using Strings for address;
using Strings for string;
using Strings for uint256;
/*//////////////////////////////////////////////////////////////////////////
USER-FACING CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @dev Needed to avoid Stack Too Deep.
struct TokenURIVars {
address asset;
string assetSymbol;
string json;
ISablierV2Lockup sablier;
string sablierAddress;
string status;
string svg;
uint128 streamedAmount;
uint256 streamedPercentage;
string streamingModel;
}
/// @inheritdoc ISablierV2NFTDescriptor
function tokenURI(IERC721Metadata sablier, uint256 streamId) external view override returns (string memory uri) {
TokenURIVars memory vars;
// Load the contracts.
vars.sablier = ISablierV2Lockup(address(sablier));
vars.sablierAddress = address(sablier).toHexString();
vars.asset = address(vars.sablier.getAsset(streamId));
vars.assetSymbol = safeAssetSymbol(vars.asset);
// Load the stream's data.
vars.status = stringifyStatus(vars.sablier.statusOf(streamId));
vars.streamedAmount = vars.sablier.streamedAmountOf(streamId);
vars.streamedPercentage = calculateStreamedPercentage({
streamedAmount: vars.streamedAmount,
depositedAmount: vars.sablier.getDepositedAmount(streamId)
});
vars.streamingModel = mapSymbol(sablier);
// Generate the SVG.
vars.svg = NFTSVG.generateSVG(
NFTSVG.SVGParams({
accentColor: generateAccentColor(address(sablier), streamId),
assetAddress: vars.asset.toHexString(),
assetSymbol: vars.assetSymbol,
duration: calculateDurationInDays({
startTime: vars.sablier.getStartTime(streamId),
endTime: vars.sablier.getEndTime(streamId)
}),
sablierAddress: vars.sablierAddress,
progress: stringifyPercentage(vars.streamedPercentage),
progressNumerical: vars.streamedPercentage,
status: vars.status,
streamed: abbreviateAmount({ amount: vars.streamedAmount, decimals: safeAssetDecimals(vars.asset) }),
streamingModel: vars.streamingModel
})
);
// Generate the JSON metadata.
vars.json = string.concat(
'{"attributes":',
generateAttributes({
assetSymbol: vars.assetSymbol,
sender: vars.sablier.getSender(streamId).toHexString(),
status: vars.status
}),
',"description":"',
generateDescription({
streamingModel: vars.streamingModel,
assetSymbol: vars.assetSymbol,
streamId: streamId.toString(),
sablierAddress: vars.sablierAddress,
assetAddress: vars.asset.toHexString()
}),
'","external_url":"https://sablier.com","name":"',
generateName({ streamingModel: vars.streamingModel, streamId: streamId.toString() }),
'","image":"data:image/svg+xml;base64,',
Base64.encode(bytes(vars.svg)),
'"}'
);
// Encode the JSON metadata in Base64.
uri = string.concat("data:application/json;base64,", Base64.encode(bytes(vars.json)));
}
/*//////////////////////////////////////////////////////////////////////////
INTERNAL CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Creates an abbreviated representation of the provided amount, rounded down and prefixed with ">= ".
/// @dev 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".
/// @param amount The amount to abbreviate, denoted in units of `decimals`.
/// @param decimals The number of decimals to assume when abbreviating the amount.
/// @return abbreviation The abbreviated representation of the provided amount, as a string.
function abbreviateAmount(uint256 amount, uint256 decimals) internal pure returns (string memory) {
if (amount == 0) {
return "0";
}
uint256 truncatedAmount;
unchecked {
truncatedAmount = decimals == 0 ? amount : amount / 10 ** decimals;
}
// Return dummy values when the truncated amount is either very small or very big.
if (truncatedAmount < 1) {
return string.concat(SVGElements.SIGN_LT, " 1");
} else if (truncatedAmount >= 1e15) {
return string.concat(SVGElements.SIGN_GT, " 999.99T");
}
string[5] memory suffixes = ["", "K", "M", "B", "T"];
uint256 fractionalAmount;
uint256 suffixIndex = 0;
// Truncate repeatedly until the amount is less than 1000.
unchecked {
while (truncatedAmount >= 1000) {
fractionalAmount = (truncatedAmount / 10) % 100; // keep the first two digits after the decimal point
truncatedAmount /= 1000;
suffixIndex += 1;
}
}
// Concatenate the calculated parts to form the final string.
string memory prefix = string.concat(SVGElements.SIGN_GE, " ");
string memory wholePart = truncatedAmount.toString();
string memory fractionalPart = stringifyFractionalAmount(fractionalAmount);
return string.concat(prefix, wholePart, fractionalPart, suffixes[suffixIndex]);
}
/// @notice Calculates the stream's duration in days, rounding down.
function calculateDurationInDays(uint256 startTime, uint256 endTime) internal pure returns (string memory) {
uint256 durationInDays;
unchecked {
durationInDays = (endTime - startTime) / 1 days;
}
// Return dummy values when the duration is either very small or very big.
if (durationInDays == 0) {
return string.concat(SVGElements.SIGN_LT, " 1 Day");
} else if (durationInDays > 9999) {
return string.concat(SVGElements.SIGN_GT, " 9999 Days");
}
string memory suffix = durationInDays == 1 ? " Day" : " Days";
return string.concat(durationInDays.toString(), suffix);
}
/// @notice 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)
{
// This cannot overflow because both inputs are uint128s, and zero deposit amounts are not allowed in Sablier.
unchecked {
return streamedAmount * 10_000 / depositedAmount;
}
}
/// @notice 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) {
// The chain id is part of the hash so that the generated color is different across chains.
uint256 chainId = block.chainid;
// Hash the parameters to generate a pseudo-random bit field, which will be used as entropy.
// | Hue | Saturation | Lightness | -> Roles
// | [31:16] | [15:8] | [7:0] | -> Bit positions
uint32 bitField = uint32(uint256(keccak256(abi.encodePacked(chainId, sablier, streamId))));
unchecked {
// The hue is a degree on a color wheel, so its range is [0, 360).
// Shifting 16 bits to the right means using the bits at positions [31:16].
uint256 hue = (bitField >> 16) % 360;
// The saturation is a percentage where 0% is grayscale and 100%, but here the range is bounded to [20,100]
// to make the colors more lively.
// Shifting 8 bits to the right and applying an 8-bit mask means using the bits at positions [15:8].
uint256 saturation = ((bitField >> 8) & 0xFF) % 80 + 20;
// The lightness is typically a percentage between 0% (black) and 100% (white), but here the range
// is bounded to [30,100] to avoid dark colors.
// Applying an 8-bit mask means using the bits at positions [7:0].
uint256 lightness = (bitField & 0xFF) % 70 + 30;
// Finally, concatenate the HSL values to form an SVG color string.
return string.concat("hsl(", hue.toString(), ",", saturation.toString(), "%,", lightness.toString(), "%)");
}
}
/// @notice Generates an array of JSON objects that represent the NFT's attributes:
/// - Asset symbol
/// - Sender address
/// - Status
/// @dev 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)
{
return string.concat(
'[{"trait_type":"Asset","value":"',
assetSymbol,
'"},{"trait_type":"Sender","value":"',
sender,
'"},{"trait_type":"Status","value":"',
status,
'"}]'
);
}
/// @notice 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)
{
return string.concat(
"This NFT represents a payment stream in a Sablier V2 ",
streamingModel,
" contract. The owner of this NFT can withdraw the streamed assets, which are denominated in ",
assetSymbol,
".\\n\\n- Stream ID: ",
streamId,
"\\n- ",
streamingModel,
" Address: ",
sablierAddress,
"\\n- ",
assetSymbol,
" Address: ",
assetAddress,
"\\n\\n",
unicode"⚠️ WARNING: Transferring the NFT makes the new owner the recipient of the stream. The funds are not automatically withdrawn for the previous recipient."
);
}
/// @notice Generates a string with the NFT's JSON metadata name, which is unique for each stream.
/// @dev The `streamId` is equivalent to the ERC-721 `tokenId`.
function generateName(string memory streamingModel, string memory streamId) internal pure returns (string memory) {
return string.concat("Sablier V2 ", streamingModel, " #", streamId);
}
/// @notice Maps ERC-721 symbols to human-readable streaming models.
/// @dev Reverts if the symbol is unknown.
function mapSymbol(IERC721Metadata sablier) internal view returns (string memory) {
string memory symbol = sablier.symbol();
if (symbol.equal("SAB-V2-LOCKUP-LIN")) {
return "Lockup Linear";
} else if (symbol.equal("SAB-V2-LOCKUP-DYN")) {
return "Lockup Dynamic";
} else {
revert Errors.SablierV2NFTDescriptor_UnknownNFT(sablier, symbol);
}
}
/// @notice Retrieves the asset's decimals safely, defaulting to "0" if an error occurs.
/// @dev Performs a low-level call to handle assets in which the decimals are not implemented.
function safeAssetDecimals(address asset) internal view returns (uint8) {
(bool success, bytes memory returnData) = asset.staticcall(abi.encodeCall(IERC20Metadata.decimals, ()));
if (success && returnData.length == 32) {
return abi.decode(returnData, (uint8));
} else {
return 0;
}
}
/// @notice Retrieves the asset's symbol safely, defaulting to a hard-coded value if an error occurs.
/// @dev 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) {
(bool success, bytes memory returnData) = asset.staticcall(abi.encodeCall(IERC20Metadata.symbol, ()));
// Non-empty strings have a length greater than 64, and bytes32 has length 32.
if (!success || returnData.length <= 64) {
return "ERC20";
}
string memory symbol = abi.decode(returnData, (string));
// The length check is a precautionary measure to help mitigate potential security threats from malicious assets
// injecting scripts in the symbol string.
if (bytes(symbol).length > 30) {
return "Long Symbol";
} else {
return symbol;
}
}
/// @notice Converts the provided fractional amount to a string prefixed by a dot.
/// @param fractionalAmount A numerical value with 2 implied decimals.
function stringifyFractionalAmount(uint256 fractionalAmount) internal pure returns (string memory) {
// Return the empty string if the fractional amount is zero.
if (fractionalAmount == 0) {
return "";
}
// Add a leading zero if the fractional part is less than 10, e.g. for "1", this function returns ".01%".
else if (fractionalAmount < 10) {
return string.concat(".0", fractionalAmount.toString());
}
// Otherwise, stringify the fractional amount simply.
else {
return string.concat(".", fractionalAmount.toString());
}
}
/// @notice Converts the provided percentage to a string.
/// @param percentage A numerical value with 4 implied decimals.
function stringifyPercentage(uint256 percentage) internal pure returns (string memory) {
// Extract the last two decimals.
string memory fractionalPart = stringifyFractionalAmount(percentage % 100);
// Remove the last two decimals.
string memory wholePart = (percentage / 100).toString();
// Concatenate the whole and fractional parts.
return string.concat(wholePart, fractionalPart, "%");
}
/// @notice Retrieves the stream's status as a string.
function stringifyStatus(Lockup.Status status) internal pure returns (string memory) {
if (status == Lockup.Status.DEPLETED) {
return "Depleted";
} else if (status == Lockup.Status.CANCELED) {
return "Canceled";
} else if (status == Lockup.Status.STREAMING) {
return "Streaming";
} else if (status == Lockup.Status.SETTLED) {
return "Settled";
} else {
return "Pending";
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Base64.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides a set of functions to operate with Base64 strings.
*
* _Available since v4.5._
*/
library Base64 {
/**
* @dev Base64 Encoding/Decoding Table
*/
string internal constant _TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/**
* @dev Converts a `bytes` to its Bytes64 `string` representation.
*/
function encode(bytes memory data) internal pure returns (string memory) {
/**
* Inspired by Brecht Devos (Brechtpd) implementation - MIT licence
* https://github.com/Brechtpd/base64/blob/e78d9fd951e7b0977ddca77d92dc85183770daf4/base64.sol
*/
if (data.length == 0) return "";
// Loads the table into memory
string memory table = _TABLE;
// Encoding takes 3 bytes chunks of binary data from `bytes` data parameter
// and split into 4 numbers of 6 bits.
// The final Base64 length should be `bytes` data length multiplied by 4/3 rounded up
// - `data.length + 2` -> Round up
// - `/ 3` -> Number of 3-bytes chunks
// - `4 *` -> 4 characters for each chunk
string memory result = new string(4 * ((data.length + 2) / 3));
/// @solidity memory-safe-assembly
assembly {
// Prepare the lookup table (skip the first "length" byte)
let tablePtr := add(table, 1)
// Prepare result pointer, jump over length
let resultPtr := add(result, 32)
// Run over the input, 3 bytes at a time
for {
let dataPtr := data
let endPtr := add(data, mload(data))
} lt(dataPtr, endPtr) {
} {
// Advance 3 bytes
dataPtr := add(dataPtr, 3)
let input := mload(dataPtr)
// To write each character, shift the 3 bytes (18 bits) chunk
// 4 times in blocks of 6 bits for each character (18, 12, 6, 0)
// and apply logical AND with 0x3F which is the number of
// the previous character in the ASCII table prior to the Base64 Table
// The result is then added to the table to get the character to write,
// and finally write it in the result pointer but with a left shift
// of 256 (1 byte) - 8 (1 ASCII char) = 248 bits
mstore8(resultPtr, mload(add(tablePtr, and(shr(18, input), 0x3F))))
resultPtr := add(resultPtr, 1) // Advance
mstore8(resultPtr, mload(add(tablePtr, and(shr(12, input), 0x3F))))
resultPtr := add(resultPtr, 1) // Advance
mstore8(resultPtr, mload(add(tablePtr, and(shr(6, input), 0x3F))))
resultPtr := add(resultPtr, 1) // Advance
mstore8(resultPtr, mload(add(tablePtr, and(input, 0x3F))))
resultPtr := add(resultPtr, 1) // Advance
}
// When data `bytes` is not exactly 3 bytes long
// it is padded with `=` characters at the end
switch mod(mload(data), 3)
case 1 {
mstore8(sub(resultPtr, 1), 0x3d)
mstore8(sub(resultPtr, 2), 0x3d)
}
case 2 {
mstore8(sub(resultPtr, 1), 0x3d)
}
}
return result;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/Math.sol";
import "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toString(int256 value) internal pure returns (string memory) {
return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return keccak256(bytes(a)) == keccak256(bytes(b));
}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.19;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IERC721Metadata } from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
import { Lockup } from "../types/DataTypes.sol";
import { ISablierV2Base } from "./ISablierV2Base.sol";
import { ISablierV2NFTDescriptor } from "./ISablierV2NFTDescriptor.sol";
/// @title ISablierV2Lockup
/// @notice Common logic between all Sablier V2 lockup streaming contracts.
interface ISablierV2Lockup is
ISablierV2Base, // 1 inherited component
IERC721Metadata // 2 inherited components
{
/*//////////////////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Emitted when a stream is canceled.
/// @param streamId The id of the stream.
/// @param sender The address of the stream's sender.
/// @param recipient The address of the stream's recipient.
/// @param senderAmount The amount of assets refunded to the stream's sender, denoted in units of the asset's
/// decimals.
/// @param recipientAmount The amount of assets left for the stream's recipient to withdraw, denoted in units of the
/// asset's decimals.
event CancelLockupStream(
uint256 indexed streamId,
address indexed sender,
address indexed recipient,
uint128 senderAmount,
uint128 recipientAmount
);
/// @notice Emitted when a sender gives up the right to cancel a stream.
/// @param streamId The id of the stream.
event RenounceLockupStream(uint256 indexed streamId);
/// @notice Emitted when the admin sets a new NFT descriptor contract.
/// @param admin The address of the current contract admin.
/// @param oldNFTDescriptor The address of the old NFT descriptor contract.
/// @param newNFTDescriptor The address of the new NFT descriptor contract.
event SetNFTDescriptor(
address indexed admin, ISablierV2NFTDescriptor oldNFTDescriptor, ISablierV2NFTDescriptor newNFTDescriptor
);
/// @notice Emitted when assets are withdrawn from a stream.
/// @param streamId The id of the stream.
/// @param to The address that has received the withdrawn assets.
/// @param amount The amount of assets withdrawn, denoted in units of the asset's decimals.
event WithdrawFromLockupStream(uint256 indexed streamId, address indexed to, uint128 amount);
/*//////////////////////////////////////////////////////////////////////////
CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Retrieves the address of the ERC-20 asset used for streaming.
/// @dev Reverts if `streamId` references a null stream.
/// @param streamId The stream id for the query.
function getAsset(uint256 streamId) external view returns (IERC20 asset);
/// @notice Retrieves the amount deposited in the stream, denoted in units of the asset's decimals.
/// @dev Reverts if `streamId` references a null stream.
/// @param streamId The stream id for the query.
function getDepositedAmount(uint256 streamId) external view returns (uint128 depositedAmount);
/// @notice Retrieves the stream's end time, which is a Unix timestamp.
/// @dev Reverts if `streamId` references a null stream.
/// @param streamId The stream id for the query.
function getEndTime(uint256 streamId) external view returns (uint40 endTime);
/// @notice Retrieves the stream's recipient.
/// @dev Reverts if the NFT has been burned.
/// @param streamId The stream id for the query.
function getRecipient(uint256 streamId) external view returns (address recipient);
/// @notice Retrieves the amount refunded to the sender after a cancellation, denoted in units of the asset's
/// decimals. This amount is always zero unless the stream was canceled.
/// @dev Reverts if `streamId` references a null stream.
/// @param streamId The stream id for the query.
function getRefundedAmount(uint256 streamId) external view returns (uint128 refundedAmount);
/// @notice Retrieves the stream's sender.
/// @dev Reverts if `streamId` references a null stream.
/// @param streamId The stream id for the query.
function getSender(uint256 streamId) external view returns (address sender);
/// @notice Retrieves the stream's start time, which is a Unix timestamp.
/// @dev Reverts if `streamId` references a null stream.
/// @param streamId The stream id for the query.
function getStartTime(uint256 streamId) external view returns (uint40 startTime);
/// @notice Retrieves the amount withdrawn from the stream, denoted in units of the asset's decimals.
/// @dev Reverts if `streamId` references a null stream.
/// @param streamId The stream id for the query.
function getWithdrawnAmount(uint256 streamId) external view returns (uint128 withdrawnAmount);
/// @notice Retrieves a flag indicating whether the stream can be canceled. When the stream is cold, this
/// flag is always `false`.
/// @dev Reverts if `streamId` references a null stream.
/// @param streamId The stream id for the query.
function isCancelable(uint256 streamId) external view returns (bool result);
/// @notice Retrieves a flag indicating whether the stream is cold, i.e. settled, canceled, or depleted.
/// @dev Reverts if `streamId` references a null stream.
/// @param streamId The stream id for the query.
function isCold(uint256 streamId) external view returns (bool result);
/// @notice Retrieves a flag indicating whether the stream is depleted.
/// @dev Reverts if `streamId` references a null stream.
/// @param streamId The stream id for the query.
function isDepleted(uint256 streamId) external view returns (bool result);
/// @notice Retrieves a flag indicating whether the stream exists.
/// @dev Does not revert if `streamId` references a null stream.
/// @param streamId The stream id for the query.
function isStream(uint256 streamId) external view returns (bool result);
/// @notice Retrieves a flag indicating whether the stream is warm, i.e. either pending or streaming.
/// @dev Reverts if `streamId` references a null stream.
/// @param streamId The stream id for the query.
function isWarm(uint256 streamId) external view returns (bool result);
/// @notice Counter for stream ids, used in the create functions.
function nextStreamId() external view returns (uint256);
/// @notice Calculates the amount that the sender would be refunded if the stream were canceled, denoted in units
/// of the asset's decimals.
/// @dev Reverts if `streamId` references a null stream.
/// @param streamId The stream id for the query.
function refundableAmountOf(uint256 streamId) external view returns (uint128 refundableAmount);
/// @notice Retrieves the stream's status.
/// @param streamId The stream id for the query.
function statusOf(uint256 streamId) external view returns (Lockup.Status status);
/// @notice Calculates the amount streamed to the recipient, denoted in units of the asset's decimals.
/// @dev Reverts if `streamId` references a null stream.
/// @param streamId The stream id for the query.
function streamedAmountOf(uint256 streamId) external view returns (uint128 streamedAmount);
/// @notice Retrieves a flag indicating whether the stream was canceled.
/// @dev Reverts if `streamId` references a null stream.
/// @param streamId The stream id for the query.
function wasCanceled(uint256 streamId) external view returns (bool result);
/// @notice Calculates the amount that the recipient can withdraw from the stream, denoted in units of the asset's
/// decimals.
/// @dev Reverts if `streamId` references a null stream.
/// @param streamId The stream id for the query.
function withdrawableAmountOf(uint256 streamId) external view returns (uint128 withdrawableAmount);
/*//////////////////////////////////////////////////////////////////////////
NON-CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Burns the NFT associated with the stream.
///
/// @dev Emits a {Transfer} event.
///
/// Requirements:
/// - Must not be delegate called.
/// - `streamId` must reference a depleted stream.
/// - The NFT must exist.
/// - `msg.sender` must be either the NFT owner or an approved third party.
///
/// @param streamId The id of the stream NFT to burn.
function burn(uint256 streamId) external;
/// @notice Cancels the stream and refunds any remaining assets to the sender.
///
/// @dev Emits a {Transfer}, {CancelLockupStream}, and {MetadataUpdate} event.
///
/// Notes:
/// - If there any assets left for the recipient to withdraw, the stream is marked as canceled. Otherwise, the
/// stream is marked as depleted.
/// - This function attempts to invoke a hook on either the sender or the recipient, depending on who `msg.sender`
/// is, and if the resolved address is a contract.
///
/// Requirements:
/// - Must not be delegate called.
/// - The stream must be warm and cancelable.
/// - `msg.sender` must be either the stream's sender or the stream's recipient (i.e. the NFT owner).
///
/// @param streamId The id of the stream to cancel.
function cancel(uint256 streamId) external;
/// @notice Cancels multiple streams and refunds any remaining assets to the sender.
///
/// @dev Emits multiple {Transfer}, {CancelLockupStream}, and {MetadataUpdate} events.
///
/// Notes:
/// - Refer to the notes in {cancel}.
///
/// Requirements:
/// - All requirements from {cancel} must be met for each stream.
///
/// @param streamIds The ids of the streams to cancel.
function cancelMultiple(uint256[] calldata streamIds) external;
/// @notice Removes the right of the stream's sender to cancel the stream.
///
/// @dev Emits a {RenounceLockupStream} and {MetadataUpdate} event.
///
/// Notes:
/// - This is an irreversible operation.
/// - This function attempts to invoke a hook on the stream's recipient, provided that the recipient is a contract.
///
/// Requirements:
/// - Must not be delegate called.
/// - `streamId` must reference a warm stream.
/// - `msg.sender` must be the stream's sender.
/// - The stream must be cancelable.
///
/// @param streamId The id of the stream to renounce.
function renounce(uint256 streamId) external;
/// @notice Sets a new NFT descriptor contract, which produces the URI describing the Sablier stream NFTs.
///
/// @dev Emits a {SetNFTDescriptor} and {BatchMetadataUpdate} event.
///
/// Notes:
/// - Does not revert if the NFT descriptor is the same.
///
/// Requirements:
/// - `msg.sender` must be the contract admin.
///
/// @param newNFTDescriptor The address of the new NFT descriptor contract.
function setNFTDescriptor(ISablierV2NFTDescriptor newNFTDescriptor) external;
/// @notice Withdraws the provided amount of assets from the stream to the `to` address.
///
/// @dev Emits a {Transfer}, {WithdrawFromLockupStream}, and {MetadataUpdate} event.
///
/// Notes:
/// - This function attempts to invoke a hook on the stream's recipient, provided that the recipient is a contract
/// and `msg.sender` is either the sender or an approved operator.
///
/// Requirements:
/// - Must not be delegate called.
/// - `streamId` must not reference a null or depleted stream.
/// - `msg.sender` must be the stream's sender, the stream's recipient or an approved third party.
/// - `to` must be the recipient if `msg.sender` is the stream's sender.
/// - `to` must not be the zero address.
/// - `amount` must be greater than zero and must not exceed the withdrawable amount.
///
/// @param streamId The id of the stream to withdraw from.
/// @param to The address receiving the withdrawn assets.
/// @param amount The amount to withdraw, denoted in units of the asset's decimals.
function withdraw(uint256 streamId, address to, uint128 amount) external;
/// @notice Withdraws the maximum withdrawable amount from the stream to the provided address `to`.
///
/// @dev Emits a {Transfer}, {WithdrawFromLockupStream}, and {MetadataUpdate} event.
///
/// Notes:
/// - Refer to the notes in {withdraw}.
///
/// Requirements:
/// - Refer to the requirements in {withdraw}.
///
/// @param streamId The id of the stream to withdraw from.
/// @param to The address receiving the withdrawn assets.
function withdrawMax(uint256 streamId, address to) external;
/// @notice Withdraws the maximum withdrawable amount from the stream to the current recipient, and transfers the
/// NFT to `newRecipient`.
///
/// @dev Emits a {WithdrawFromLockupStream} and a {Transfer} event.
///
/// Notes:
/// - If the withdrawable amount is zero, the withdrawal is skipped.
/// - Refer to the notes in {withdraw}.
///
/// Requirements:
/// - `msg.sender` must be the stream's recipient.
/// - Refer to the requirements in {withdraw}.
/// - Refer to the requirements in {IERC721.transferFrom}.
///
/// @param streamId The id of the stream NFT to transfer.
/// @param newRecipient The address of the new owner of the stream NFT.
function withdrawMaxAndTransfer(uint256 streamId, address newRecipient) external;
/// @notice Withdraws assets from streams to the provided address `to`.
///
/// @dev Emits multiple {Transfer}, {WithdrawFromLockupStream}, and {MetadataUpdate} events.
///
/// Notes:
/// - This function attempts to call a hook on the recipient of each stream, unless `msg.sender` is the recipient.
///
/// Requirements:
/// - All requirements from {withdraw} must be met for each stream.
/// - There must be an equal number of `streamIds` and `amounts`.
///
/// @param streamIds The ids of the streams to withdraw from.
/// @param to The address receiving the withdrawn assets.
/// @param amounts The amounts to withdraw, denoted in units of the asset's decimals.
function withdrawMultiple(uint256[] calldata streamIds, address to, uint128[] calldata amounts) external;
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.19;
import { IERC721Metadata } from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
/// @title ISablierV2NFTDescriptor
/// @notice This contract generates the URI describing the Sablier V2 stream NFTs.
/// @dev Inspired by Uniswap V3 Positions NFTs.
interface ISablierV2NFTDescriptor {
/// @notice Produces the URI describing a particular stream NFT.
/// @dev This is a data URI with the JSON contents directly inlined.
/// @param sablier The address of the Sablier contract the stream was created in.
/// @param streamId The id of the stream for which to produce a description.
/// @return uri The URI of the ERC721-compliant metadata.
function tokenURI(IERC721Metadata sablier, uint256 streamId) external view returns (string memory uri);
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.19;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { UD2x18 } from "@prb/math/UD2x18.sol";
import { UD60x18 } from "@prb/math/UD60x18.sol";
// DataTypes.sol
//
// This file defines all structs used in V2 Core, most of which are organized under three namespaces:
//
// - Lockup
// - LockupDynamic
// - LockupLinear
//
// You will notice that some structs contain "slot" annotations - they are used to indicate the
// storage layout of the struct. It is more gas efficient to group small data types together so
// that they fit in a single 32-byte slot.
/// @notice Struct encapsulating the broker parameters passed to the create functions. Both can be set to zero.
/// @param account The address receiving the broker's fee.
/// @param fee The broker's percentage fee from the total amount, denoted as a fixed-point number where 1e18 is 100%.
struct Broker {
address account;
UD60x18 fee;
}
/// @notice Namespace for the structs used in both {SablierV2LockupLinear} and {SablierV2LockupDynamic}.
library Lockup {
/// @notice Struct encapsulating the deposit, withdrawn, and refunded amounts, all denoted in units
/// of the asset's decimals.
/// @dev Because the deposited and the withdrawn amount are often read together, declaring them in
/// the same slot saves gas.
/// @param deposited The initial amount deposited in the stream, net of fees.
/// @param withdrawn The cumulative amount withdrawn from the stream.
/// @param refunded The amount refunded to the sender. Unless the stream was canceled, this is always zero.
struct Amounts {
// slot 0
uint128 deposited;
uint128 withdrawn;
// slot 1
uint128 refunded;
}
/// @notice Struct encapsulating the deposit amount, the protocol fee amount, and the broker fee amount,
/// all denoted in units of the asset's decimals.
/// @param deposit The amount to deposit in the stream.
/// @param protocolFee The protocol fee amount.
/// @param brokerFee The broker fee amount.
struct CreateAmounts {
uint128 deposit;
uint128 protocolFee;
uint128 brokerFee;
}
/// @notice Enum representing the different statuses of a stream.
/// @custom:value PENDING Stream created but not started; assets are in a pending state.
/// @custom:value STREAMING Active stream where assets are currently being streamed.
/// @custom:value SETTLED All assets have been streamed; recipient is due to withdraw them.
/// @custom:value CANCELED Canceled stream; remaining assets await recipient's withdrawal.
/// @custom:value DEPLETED Depleted stream; all assets have been withdrawn and/or refunded.
enum Status {
PENDING, // value 0
STREAMING, // value 1
SETTLED, // value 2
CANCELED, // value 3
DEPLETED // value 4
}
}
/// @notice Namespace for the structs used in {SablierV2LockupDynamic}.
library LockupDynamic {
/// @notice Struct encapsulating the parameters for the {SablierV2LockupDynamic.createWithDeltas} function.
/// @param sender The address streaming the assets, with the ability to cancel the stream. It doesn't have to be the
/// same as `msg.sender`.
/// @param recipient The address receiving the assets.
/// @param totalAmount The total amount of ERC-20 assets to be paid, including the stream deposit and any potential
/// fees, all denoted in units of the asset's decimals.
/// @param asset The contract address of the ERC-20 asset used for streaming.
/// @param cancelable Indicates if the stream is cancelable.
/// @param broker Struct containing (i) the address of the broker assisting in creating the stream, and (ii) the
/// percentage fee paid to the broker from `totalAmount`, denoted as a fixed-point number. Both can be set to zero.
/// @param segments Segments with deltas used to compose the custom streaming curve. Milestones are calculated by
/// starting from `block.timestamp` and adding each delta to the previous milestone.
struct CreateWithDeltas {
address sender;
bool cancelable;
address recipient;
uint128 totalAmount;
IERC20 asset;
Broker broker;
SegmentWithDelta[] segments;
}
/// @notice Struct encapsulating the parameters for the {SablierV2LockupDynamic.createWithMilestones}
/// function.
/// @param sender The address streaming the assets, with the ability to cancel the stream. It doesn't have to be the
/// same as `msg.sender`.
/// @param startTime The Unix timestamp indicating the stream's start.
/// @param cancelable Indicates if the stream is cancelable.
/// @param recipient The address receiving the assets.
/// @param totalAmount The total amount of ERC-20 assets to be paid, including the stream deposit and any potential
/// fees, all denoted in units of the asset's decimals.
/// @param asset The contract address of the ERC-20 asset used for streaming.
/// @param broker Struct containing (i) the address of the broker assisting in creating the stream, and (ii) the
/// percentage fee paid to the broker from `totalAmount`, denoted as a fixed-point number. Both can be set to zero.
/// @param segments Segments used to compose the custom streaming curve.
struct CreateWithMilestones {
address sender;
uint40 startTime;
bool cancelable;
address recipient;
uint128 totalAmount;
IERC20 asset;
Broker broker;
Segment[] segments;
}
/// @notice Struct encapsulating the time range.
/// @param start The Unix timestamp indicating the stream's start.
/// @param end The Unix timestamp indicating the stream's end.
struct Range {
uint40 start;
uint40 end;
}
/// @notice Segment struct used in the Lockup Dynamic stream.
/// @param amount The amount of assets to be streamed in this segment, denoted in units of the asset's decimals.
/// @param exponent The exponent of this segment, denoted as a fixed-point number.
/// @param milestone The Unix timestamp indicating this segment's end.
struct Segment {
// slot 0
uint128 amount;
UD2x18 exponent;
uint40 milestone;
}
/// @notice Segment struct used at runtime in {SablierV2LockupDynamic.createWithDeltas}.
/// @param amount The amount of assets to be streamed in this segment, denoted in units of the asset's decimals.
/// @param exponent The exponent of this segment, denoted as a fixed-point number.
/// @param delta The time difference in seconds between this segment and the previous one.
struct SegmentWithDelta {
uint128 amount;
UD2x18 exponent;
uint40 delta;
}
/// @notice Lockup Dynamic stream.
/// @dev The fields are arranged like this to save gas via tight variable packing.
/// @param sender The address streaming the assets, with the ability to cancel the stream.
/// @param startTime The Unix timestamp indicating the stream's start.
/// @param endTime The Unix timestamp indicating the stream's end.
/// @param isCancelable Boolean indicating if the stream is cancelable.
/// @param wasCanceled Boolean indicating if the stream was canceled.
/// @param asset The contract address of the ERC-20 asset used for streaming.
/// @param isDepleted Boolean indicating if the stream is depleted.
/// @param isStream Boolean indicating if the struct entity exists.
/// @param amounts Struct containing the deposit, withdrawn, and refunded amounts, all denoted in units of the
/// asset's decimals.
/// @param segments Segments used to compose the custom streaming curve.
struct Stream {
// slot 0
address sender;
uint40 startTime;
uint40 endTime;
bool isCancelable;
bool wasCanceled;
// slot 1
IERC20 asset;
bool isDepleted;
bool isStream;
// slot 2 and 3
Lockup.Amounts amounts;
// slots [4..n]
Segment[] segments;
}
}
/// @notice Namespace for the structs used in {SablierV2LockupLinear}.
library LockupLinear {
/// @notice Struct encapsulating the parameters for the {SablierV2LockupLinear.createWithDurations} function.
/// @param sender The address streaming the assets, with the ability to cancel the stream. It doesn't have to be the
/// same as `msg.sender`.
/// @param recipient The address receiving the assets.
/// @param totalAmount The total amount of ERC-20 assets to be paid, including the stream deposit and any potential
/// fees, all denoted in units of the asset's decimals.
/// @param asset The contract address of the ERC-20 asset used for streaming.
/// @param cancelable Indicates if the stream is cancelable.
/// @param durations Struct containing (i) cliff period duration and (ii) total stream duration, both in seconds.
/// @param broker Struct containing (i) the address of the broker assisting in creating the stream, and (ii) the
/// percentage fee paid to the broker from `totalAmount`, denoted as a fixed-point number. Both can be set to zero.
struct CreateWithDurations {
address sender;
address recipient;
uint128 totalAmount;
IERC20 asset;
bool cancelable;
Durations durations;
Broker broker;
}
/// @notice Struct encapsulating the parameters for the {SablierV2LockupLinear.createWithRange} function.
/// @param sender The address streaming the assets, with the ability to cancel the stream. It doesn't have to be the
/// same as `msg.sender`.
/// @param recipient The address receiving the assets.
/// @param totalAmount The total amount of ERC-20 assets to be paid, including the stream deposit and any potential
/// fees, all denoted in units of the asset's decimals.
/// @param asset The contract address of the ERC-20 asset used for streaming.
/// @param cancelable Indicates if the stream is cancelable.
/// @param range Struct containing (i) the stream's start time, (ii) cliff time, and (iii) end time, all as Unix
/// timestamps.
/// @param broker Struct containing (i) the address of the broker assisting in creating the stream, and (ii) the
/// percentage fee paid to the broker from `totalAmount`, denoted as a fixed-point number. Both can be set to zero.
struct CreateWithRange {
address sender;
address recipient;
uint128 totalAmount;
IERC20 asset;
bool cancelable;
Range range;
Broker broker;
}
/// @notice Struct encapsulating the cliff duration and the total duration.
/// @param cliff The cliff duration in seconds.
/// @param total The total duration in seconds.
struct Durations {
uint40 cliff;
uint40 total;
}
/// @notice Struct encapsulating the time range.
/// @param start The Unix timestamp for the stream's start.
/// @param cliff The Unix timestamp for the cliff period's end.
/// @param end The Unix timestamp for the stream's end.
struct Range {
uint40 start;
uint40 cliff;
uint40 end;
}
/// @notice Lockup Linear stream.
/// @dev The fields are arranged like this to save gas via tight variable packing.
/// @param sender The address streaming the assets, with the ability to cancel the stream.
/// @param startTime The Unix timestamp indicating the stream's start.
/// @param cliffTime The Unix timestamp indicating the cliff period's end.
/// @param isCancelable Boolean indicating if the stream is cancelable.
/// @param wasCanceled Boolean indicating if the stream was canceled.
/// @param asset The contract address of the ERC-20 asset used for streaming.
/// @param endTime The Unix timestamp indicating the stream's end.
/// @param isDepleted Boolean indicating if the stream is depleted.
/// @param isStream Boolean indicating if the struct entity exists.
/// @param amounts Struct containing the deposit, withdrawn, and refunded amounts, all denoted in units of the
/// asset's decimals.
struct Stream {
// slot 0
address sender;
uint40 startTime;
uint40 cliffTime;
bool isCancelable;
bool wasCanceled;
// slot 1
IERC20 asset;
uint40 endTime;
bool isDepleted;
bool isStream;
// slot 2 and 3
Lockup.Amounts amounts;
}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.19;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IERC721Metadata } from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
import { UD60x18 } from "@prb/math/UD60x18.sol";
/// @title Errors
/// @notice Library containing all custom errors the protocol may revert with.
library Errors {
/*//////////////////////////////////////////////////////////////////////////
GENERICS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Thrown when `msg.sender` is not the admin.
error CallerNotAdmin(address admin, address caller);
/// @notice Thrown when trying to delegate call to a function that disallows delegate calls.
error DelegateCall();
/*//////////////////////////////////////////////////////////////////////////
SABLIER-V2-BASE
//////////////////////////////////////////////////////////////////////////*/
/// @notice Thrown when trying to claim protocol revenues for an asset with no accrued revenues.
error SablierV2Base_NoProtocolRevenues(IERC20 asset);
/*//////////////////////////////////////////////////////////////////////////
SABLIER-V2-FLASH-LOAN
//////////////////////////////////////////////////////////////////////////*/
/// @notice Thrown when trying to flash loan an unsupported asset.
error SablierV2FlashLoan_AssetNotFlashLoanable(IERC20 asset);
/// @notice Thrown when trying to flash loan an amount greater than or equal to 2^128.
error SablierV2FlashLoan_AmountTooHigh(uint256 amount);
/// @notice Thrown when the calculated fee during a flash loan is greater than or equal to 2^128.
error SablierV2FlashLoan_CalculatedFeeTooHigh(uint256 amount);
/// @notice Thrown when the callback to the flash borrower fails.
error SablierV2FlashLoan_FlashBorrowFail();
/*//////////////////////////////////////////////////////////////////////////
SABLIER-V2-LOCKUP
//////////////////////////////////////////////////////////////////////////*/
/// @notice Thrown when the broker fee exceeds the maximum allowed fee.
error SablierV2Lockup_BrokerFeeTooHigh(UD60x18 brokerFee, UD60x18 maxFee);
/// @notice Thrown when trying to create a stream with a zero deposit amount.
error SablierV2Lockup_DepositAmountZero();
/// @notice Thrown when trying to create a stream with an end time not in the future.
error SablierV2Lockup_EndTimeNotInTheFuture(uint40 currentTime, uint40 endTime);
/// @notice Thrown when the stream's sender tries to withdraw to an address other than the recipient's.
error SablierV2Lockup_InvalidSenderWithdrawal(uint256 streamId, address sender, address to);
/// @notice Thrown when the id references a null stream.
error SablierV2Lockup_Null(uint256 streamId);
/// @notice Thrown when trying to withdraw an amount greater than the withdrawable amount.
error SablierV2Lockup_Overdraw(uint256 streamId, uint128 amount, uint128 withdrawableAmount);
/// @notice Thrown when the protocol fee exceeds the maximum allowed fee.
error SablierV2Lockup_ProtocolFeeTooHigh(UD60x18 protocolFee, UD60x18 maxFee);
/// @notice Thrown when trying to cancel or renounce a canceled stream.
error SablierV2Lockup_StreamCanceled(uint256 streamId);
/// @notice Thrown when trying to cancel, renounce, or withdraw from a depleted stream.
error SablierV2Lockup_StreamDepleted(uint256 streamId);
/// @notice Thrown when trying to cancel or renounce a stream that is not cancelable.
error SablierV2Lockup_StreamNotCancelable(uint256 streamId);
/// @notice Thrown when trying to burn a stream that is not depleted.
error SablierV2Lockup_StreamNotDepleted(uint256 streamId);
/// @notice Thrown when trying to cancel or renounce a settled stream.
error SablierV2Lockup_StreamSettled(uint256 streamId);
/// @notice Thrown when `msg.sender` lacks authorization to perform an action.
error SablierV2Lockup_Unauthorized(uint256 streamId, address caller);
/// @notice Thrown when trying to withdraw zero assets from a stream.
error SablierV2Lockup_WithdrawAmountZero(uint256 streamId);
/// @notice Thrown when trying to withdraw from multiple streams and the number of stream ids does
/// not match the number of withdraw amounts.
error SablierV2Lockup_WithdrawArrayCountsNotEqual(uint256 streamIdsCount, uint256 amountsCount);
/// @notice Thrown when trying to withdraw to the zero address.
error SablierV2Lockup_WithdrawToZeroAddress();
/*//////////////////////////////////////////////////////////////////////////
SABLIER-V2-LOCKUP-DYNAMIC
//////////////////////////////////////////////////////////////////////////*/
/// @notice Thrown when trying to create a stream with a deposit amount not equal to the sum of the
/// segment amounts.
error SablierV2LockupDynamic_DepositAmountNotEqualToSegmentAmountsSum(
uint128 depositAmount, uint128 segmentAmountsSum
);
/// @notice Thrown when trying to create a stream with more segments than the maximum allowed.
error SablierV2LockupDynamic_SegmentCountTooHigh(uint256 count);
/// @notice Thrown when trying to create a stream with no segments.
error SablierV2LockupDynamic_SegmentCountZero();
/// @notice Thrown when trying to create a stream with unordered segment milestones.
error SablierV2LockupDynamic_SegmentMilestonesNotOrdered(
uint256 index, uint40 previousMilestone, uint40 currentMilestone
);
/// @notice Thrown when trying to create a stream with a start time not strictly less than the first
/// segment milestone.
error SablierV2LockupDynamic_StartTimeNotLessThanFirstSegmentMilestone(
uint40 startTime, uint40 firstSegmentMilestone
);
/*//////////////////////////////////////////////////////////////////////////
SABLIER-V2-LOCKUP-LINEAR
//////////////////////////////////////////////////////////////////////////*/
/// @notice Thrown when trying to create a stream with a cliff time not strictly less than the end time.
error SablierV2LockupLinear_CliffTimeNotLessThanEndTime(uint40 cliffTime, uint40 endTime);
/// @notice Thrown when trying to create a stream with a start time greater than the cliff time.
error SablierV2LockupLinear_StartTimeGreaterThanCliffTime(uint40 startTime, uint40 cliffTime);
/*//////////////////////////////////////////////////////////////////////////
SABLIER-V2-NFT-DESCRIPTOR
//////////////////////////////////////////////////////////////////////////*/
/// @notice Thrown when trying to generate the token URI for an unknown ERC-721 NFT contract.
error SablierV2NFTDescriptor_UnknownNFT(IERC721Metadata nft, string symbol);
}// SPDX-License-Identifier: GPL-3.0-or-later
// solhint-disable quotes
pragma solidity >=0.8.19;
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
import { SVGElements } from "./SVGElements.sol";
library NFTSVG {
using Strings for uint256;
uint256 internal constant CARD_MARGIN = 16;
struct SVGParams {
string accentColor;
string assetAddress;
string assetSymbol;
string duration;
string progress;
uint256 progressNumerical;
string sablierAddress;
string status;
string streamed;
string streamingModel;
}
struct SVGVars {
string cards;
uint256 cardsWidth;
string durationCard;
uint256 durationWidth;
uint256 durationXPosition;
string progressCard;
uint256 progressWidth;
uint256 progressXPosition;
string statusCard;
uint256 statusWidth;
uint256 statusXPosition;
string streamedCard;
uint256 streamedWidth;
uint256 streamedXPosition;
}
function generateSVG(SVGParams memory params) internal pure returns (string memory) {
SVGVars memory vars;
// Generate the progress card.
(vars.progressWidth, vars.progressCard) = SVGElements.card({
cardType: SVGElements.CardType.PROGRESS,
content: params.progress,
circle: SVGElements.progressCircle({
progressNumerical: params.progressNumerical,
accentColor: params.accentColor
})
});
// Generate the status card.
(vars.statusWidth, vars.statusCard) =
SVGElements.card({ cardType: SVGElements.CardType.STATUS, content: params.status });
// Generate the streamed card.
(vars.streamedWidth, vars.streamedCard) =
SVGElements.card({ cardType: SVGElements.CardType.STREAMED, content: params.streamed });
// Generate the duration card.
(vars.durationWidth, vars.durationCard) =
SVGElements.card({ cardType: SVGElements.CardType.DURATION, content: params.duration });
unchecked {
// Calculate the width of the row containing the cards and the margins between them.
vars.cardsWidth =
vars.streamedWidth + vars.durationWidth + vars.progressWidth + vars.statusWidth + CARD_MARGIN * 3;
// Calculate the positions on the X axis based on the following layout:
//
// ___________________________ SVG Width (1000px) _____________________________
// | | | | | | | | | |
// | <-> | Progress | 16px | Status | 16px | Streamed | 16px | Duration | <-> |
vars.progressXPosition = (1000 - vars.cardsWidth) / 2;
vars.statusXPosition = vars.progressXPosition + vars.progressWidth + CARD_MARGIN;
vars.streamedXPosition = vars.statusXPosition + vars.statusWidth + CARD_MARGIN;
vars.durationXPosition = vars.streamedXPosition + vars.streamedWidth + CARD_MARGIN;
}
// Concatenate all cards.
vars.cards = string.concat(vars.progressCard, vars.statusCard, vars.streamedCard, vars.durationCard);
return string.concat(
'<svg xmlns="http://www.w3.org/2000/svg" width="1000" height="1000" viewBox="0 0 1000 1000">',
SVGElements.BACKGROUND,
generateDefs(params.accentColor, params.status, vars.cards),
generateFloatingText(params.sablierAddress, params.streamingModel, params.assetAddress, params.assetSymbol),
generateHrefs(vars.progressXPosition, vars.statusXPosition, vars.streamedXPosition, vars.durationXPosition),
"</svg>"
);
}
function generateDefs(
string memory accentColor,
string memory status,
string memory cards
)
internal
pure
returns (string memory)
{
return string.concat(
"<defs>",
SVGElements.GLOW,
SVGElements.NOISE,
SVGElements.LOGO,
SVGElements.FLOATING_TEXT,
SVGElements.gradients(accentColor),
SVGElements.hourglass(status),
cards,
"</defs>"
);
}
function generateFloatingText(
string memory sablierAddress,
string memory streamingModel,
string memory assetAddress,
string memory assetSymbol
)
internal
pure
returns (string memory)
{
return string.concat(
'<text text-rendering="optimizeSpeed">',
SVGElements.floatingText({
offset: "-100%",
text: string.concat(sablierAddress, unicode" • ", "Sablier V2 ", streamingModel)
}),
SVGElements.floatingText({
offset: "0%",
text: string.concat(sablierAddress, unicode" • ", "Sablier V2 ", streamingModel)
}),
SVGElements.floatingText({ offset: "-50%", text: string.concat(assetAddress, unicode" • ", assetSymbol) }),
SVGElements.floatingText({ offset: "50%", text: string.concat(assetAddress, unicode" • ", assetSymbol) }),
"</text>"
);
}
function generateHrefs(
uint256 progressXPosition,
uint256 statusXPosition,
uint256 streamedXPosition,
uint256 durationXPosition
)
internal
pure
returns (string memory)
{
return string.concat(
'<use href="#Glow" fill-opacity=".9"/>',
'<use href="#Glow" x="1000" y="1000" fill-opacity=".9"/>',
'<use href="#Logo" x="170" y="170" transform="scale(.6)"/>'
'<use href="#Hourglass" x="150" y="90" transform="rotate(10)" transform-origin="500 500"/>',
'<use href="#Progress" x="',
progressXPosition.toString(),
'" y="790"/>',
'<use href="#Status" x="',
statusXPosition.toString(),
'" y="790"/>',
'<use href="#Streamed" x="',
streamedXPosition.toString(),
'" y="790"/>',
'<use href="#Duration" x="',
durationXPosition.toString(),
'" y="790"/>'
);
}
}// SPDX-License-Identifier: GPL-3.0-or-later
// solhint-disable max-line-length,quotes
pragma solidity >=0.8.19;
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
library SVGElements {
using Strings for string;
using Strings for uint256;
/*//////////////////////////////////////////////////////////////////////////
CONSTANTS
//////////////////////////////////////////////////////////////////////////*/
string internal constant BACKGROUND =
'<rect width="100%" height="100%" filter="url(#Noise)"/><rect x="70" y="70" width="860" height="860" fill="#fff" fill-opacity=".03" rx="45" ry="45" stroke="#fff" stroke-opacity=".1" stroke-width="4"/>';
string internal constant BACKGROUND_COLOR = "hsl(230,21%,11%)";
string internal constant FLOATING_TEXT =
'<path id="FloatingText" fill="none" d="M125 45h750s80 0 80 80v750s0 80 -80 80h-750s-80 0 -80 -80v-750s0 -80 80 -80"/>';
string internal constant GLOW = '<circle id="Glow" r="500" fill="url(#RadialGlow)"/>';
string internal constant LOGO =
'<path id="Logo" fill="#fff" fill-opacity=".1" d="m133.559,124.034c-.013,2.412-1.059,4.848-2.923,6.402-2.558,1.819-5.168,3.439-7.888,4.996-14.44,8.262-31.047,12.565-47.674,12.569-8.858.036-17.838-1.272-26.328-3.663-9.806-2.766-19.087-7.113-27.562-12.778-13.842-8.025,9.468-28.606,16.153-35.265h0c2.035-1.838,4.252-3.546,6.463-5.224h0c6.429-5.655,16.218-2.835,20.358,4.17,4.143,5.057,8.816,9.649,13.92,13.734h.037c5.736,6.461,15.357-2.253,9.38-8.48,0,0-3.515-3.515-3.515-3.515-11.49-11.478-52.656-52.664-64.837-64.837l.049-.037c-1.725-1.606-2.719-3.847-2.751-6.204h0c-.046-2.375,1.062-4.582,2.726-6.229h0l.185-.148h0c.099-.062,.222-.148,.37-.259h0c2.06-1.362,3.951-2.621,6.044-3.842C57.763-3.473,97.76-2.341,128.637,18.332c16.671,9.946-26.344,54.813-38.651,40.199-6.299-6.096-18.063-17.743-19.668-18.811-6.016-4.047-13.061,4.776-7.752,9.751l68.254,68.371c1.724,1.601,2.714,3.84,2.738,6.192Z"/>';
string internal constant HOURGLASS_BACKGROUND_CIRCLE =
'<path d="M 50,360 a 300,300 0 1,1 600,0 a 300,300 0 1,1 -600,0" fill="#fff" fill-opacity=".02" stroke="url(#HourglassStroke)" stroke-width="4"/>';
string internal constant HOURGLASS_FILL =
'<path d="m566,161.201v-53.924c0-19.382-22.513-37.563-63.398-51.198-40.756-13.592-94.946-21.079-152.587-21.079s-111.838,7.487-152.602,21.079c-40.893,13.636-63.413,31.816-63.413,51.198v53.924c0,17.181,17.704,33.427,50.223,46.394v284.809c-32.519,12.96-50.223,29.206-50.223,46.394v53.924c0,19.382,22.52,37.563,63.413,51.198,40.763,13.592,94.954,21.079,152.602,21.079s111.831-7.487,152.587-21.079c40.886-13.636,63.398-31.816,63.398-51.198v-53.924c0-17.196-17.704-33.435-50.223-46.401V207.603c32.519-12.967,50.223-29.206,50.223-46.401Zm-347.462,57.793l130.959,131.027-130.959,131.013V218.994Zm262.924.022v262.018l-130.937-131.006,130.937-131.013Z" fill="#161822"></path>';
string internal constant HOURGLASS_STROKE =
'<g fill="none" stroke="url(#HourglassStroke)" stroke-linecap="round" stroke-miterlimit="10" stroke-width="4"><path d="m565.641,107.28c0,9.537-5.56,18.629-15.676,26.973h-.023c-9.204,7.596-22.194,14.562-38.197,20.592-39.504,14.936-97.325,24.355-161.733,24.355-90.48,0-167.948-18.582-199.953-44.948h-.023c-10.115-8.344-15.676-17.437-15.676-26.973,0-39.735,96.554-71.921,215.652-71.921s215.629,32.185,215.629,71.921Z"/><path d="m134.36,161.203c0,39.735,96.554,71.921,215.652,71.921s215.629-32.186,215.629-71.921"/><line x1="134.36" y1="161.203" x2="134.36" y2="107.28"/><line x1="565.64" y1="161.203" x2="565.64" y2="107.28"/><line x1="184.584" y1="206.823" x2="184.585" y2="537.579"/><line x1="218.181" y1="218.118" x2="218.181" y2="562.537"/><line x1="481.818" y1="218.142" x2="481.819" y2="562.428"/><line x1="515.415" y1="207.352" x2="515.416" y2="537.579"/><path d="m184.58,537.58c0,5.45,4.27,10.65,12.03,15.42h.02c5.51,3.39,12.79,6.55,21.55,9.42,30.21,9.9,78.02,16.28,131.83,16.28,49.41,0,93.76-5.38,124.06-13.92,2.7-.76,5.29-1.54,7.75-2.35,8.77-2.87,16.05-6.04,21.56-9.43h0c7.76-4.77,12.04-9.97,12.04-15.42"/><path d="m184.582,492.656c-31.354,12.485-50.223,28.58-50.223,46.142,0,9.536,5.564,18.627,15.677,26.969h.022c8.503,7.005,20.213,13.463,34.524,19.159,9.999,3.991,21.269,7.609,33.597,10.788,36.45,9.407,82.181,15.002,131.835,15.002s95.363-5.595,131.807-15.002c10.847-2.79,20.867-5.926,29.924-9.349,1.244-.467,2.473-.942,3.673-1.424,14.326-5.696,26.035-12.161,34.524-19.173h.022c10.114-8.342,15.677-17.433,15.677-26.969,0-17.562-18.869-33.665-50.223-46.15"/><path d="m134.36,592.72c0,39.735,96.554,71.921,215.652,71.921s215.629-32.186,215.629-71.921"/><line x1="134.36" y1="592.72" x2="134.36" y2="538.797"/><line x1="565.64" y1="592.72" x2="565.64" y2="538.797"/><polyline points="481.822 481.901 481.798 481.877 481.775 481.854 350.015 350.026 218.185 218.129"/><polyline points="218.185 481.901 218.231 481.854 350.015 350.026 481.822 218.152"/></g>';
string internal constant HOURGLASS_LOWER_BULB_LARGE =
'<path d="m481.46,481.54v81.01c-2.35.77-4.82,1.51-7.39,2.23-30.3,8.54-74.65,13.92-124.06,13.92-53.6,0-101.24-6.33-131.47-16.16v-81l46.3-46.31h170.33l46.29,46.31Z" fill="url(#SandBottom)"/><path d="m435.17,435.23c0,1.17-.46,2.32-1.33,3.44-7.11,9.08-41.93,15.98-83.81,15.98s-76.7-6.9-83.82-15.98c-.87-1.12-1.33-2.27-1.33-3.44v-.04l8.34-8.35.01-.01c13.72-6.51,42.95-11.02,76.8-11.02s62.97,4.49,76.72,11l8.42,8.42Z" fill="url(#SandTop)"/>';
string internal constant HOURGLASS_LOWER_BULB_SMALL =
'<path d="m481.46,504.101v58.449c-2.35.77-4.82,1.51-7.39,2.23-30.3,8.54-74.65,13.92-124.06,13.92-53.6,0-101.24-6.33-131.47-16.16v-58.439h262.92Z" fill="url(#SandBottom)"/><ellipse cx="350" cy="504.101" rx="131.462" ry="28.108" fill="url(#SandTop)"/>';
string internal constant HOURGLASS_UPPER_BULB =
'<polygon points="350 350.026 415.03 284.978 285 284.978 350 350.026" fill="url(#SandBottom)"/><path d="m416.341,281.975c0,.914-.354,1.809-1.035,2.68-5.542,7.076-32.661,12.45-65.28,12.45-32.624,0-59.738-5.374-65.28-12.45-.681-.872-1.035-1.767-1.035-2.68,0-.914.354-1.808,1.035-2.676,5.542-7.076,32.656-12.45,65.28-12.45,32.619,0,59.738,5.374,65.28,12.45.681.867,1.035,1.762,1.035,2.676Z" fill="url(#SandTop)"/>';
string internal constant NOISE =
'<filter id="Noise"><feFlood x="0" y="0" width="100%" height="100%" flood-color="hsl(230,21%,11%)" flood-opacity="1" result="floodFill"/><feTurbulence baseFrequency=".4" numOctaves="3" result="Noise" type="fractalNoise"/><feBlend in="Noise" in2="floodFill" mode="soft-light"/></filter>';
/// @dev Escape character for "≥".
string internal constant SIGN_GE = "≥";
/// @dev Escape character for ">".
string internal constant SIGN_GT = ">";
/// @dev Escape character for "<".
string internal constant SIGN_LT = "<";
/*//////////////////////////////////////////////////////////////////////////
DATA TYPES
//////////////////////////////////////////////////////////////////////////*/
enum CardType {
PROGRESS,
STATUS,
STREAMED,
DURATION
}
/*//////////////////////////////////////////////////////////////////////////
COMPONENTS
//////////////////////////////////////////////////////////////////////////*/
function card(CardType cardType, string memory content) internal pure returns (uint256, string memory) {
return card({ cardType: cardType, content: content, circle: "" });
}
function card(
CardType cardType,
string memory content,
string memory circle
)
internal
pure
returns (uint256 width, string memory card_)
{
string memory caption = stringifyCardType(cardType);
// The progress card can have a fixed width because the content is never longer than the caption. The former
// has 6 characters (at most, e.g. "42.09%"), whereas the latter has 8 characters ("Progress").
if (cardType == CardType.PROGRESS) {
// The progress can be 0%, in which case the circle is not rendered.
if (circle.equal("")) {
width = 144; // 2 * 20 (margins) + 8 * 13 (charWidth)
} else {
width = 208; // 3 * 20 (margins) + 8 * 13 (charWidth) + 44 (diameter)
}
}
// For the other cards, the width is calculated dynamically based on the number of characters.
else {
uint256 captionWidth = calculatePixelWidth({ text: caption, largeFont: false });
uint256 contentWidth = calculatePixelWidth({ text: content, largeFont: true });
// Use the greater of the two widths, and add the left and the right margin.
unchecked {
width = Math.max(captionWidth, contentWidth) + 40;
}
}
card_ = string.concat(
'<g id="',
caption,
'" fill="#fff">',
'<rect width="',
width.toString(),
'" height="100" fill-opacity=".03" rx="15" ry="15" stroke="#fff" stroke-opacity=".1" stroke-width="4"/>',
'<text x="20" y="34" font-family="\'Courier New\',Arial,monospace" font-size="22px">',
caption,
"</text>",
'<text x="20" y="72" font-family="\'Courier New\',Arial,monospace" font-size="26px">',
content,
"</text>",
circle,
"</g>"
);
}
function floatingText(string memory offset, string memory text) internal pure returns (string memory) {
return string.concat(
'<textPath startOffset="',
offset,
'" href="#FloatingText" fill="#fff" font-family="\'Courier New\',Arial,monospace" fill-opacity=".8" font-size="26px">',
'<animate additive="sum" attributeName="startOffset" begin="0s" dur="50s" from="0%" repeatCount="indefinite" to="100%"/>',
text,
"</textPath>"
);
}
function gradients(string memory accentColor) internal pure returns (string memory) {
string memory radialGlow = string.concat(
'<radialGradient id="RadialGlow">',
'<stop offset="0%" stop-color="',
accentColor,
'" stop-opacity=".6"/>',
'<stop offset="100%" stop-color="',
BACKGROUND_COLOR,
'" stop-opacity="0"/>',
"</radialGradient>"
);
string memory sandTop = string.concat(
'<linearGradient id="SandTop" x1="0%" y1="0%">',
'<stop offset="0%" stop-color="',
accentColor,
'"/>',
'<stop offset="100%" stop-color="',
BACKGROUND_COLOR,
'"/>',
"</linearGradient>"
);
string memory sandBottom = string.concat(
'<linearGradient id="SandBottom" x1="100%" y1="100%">',
'<stop offset="10%" stop-color="',
BACKGROUND_COLOR,
'"/>',
'<stop offset="100%" stop-color="',
accentColor,
'"/>',
'<animate attributeName="x1" dur="6s" repeatCount="indefinite" values="30%;60%;120%;60%;30%;"/>',
"</linearGradient>"
);
// Needs to be declared last so that the stroke is painted on top of the sand.
string memory hourglassStroke = string.concat(
'<linearGradient id="HourglassStroke" gradientTransform="rotate(90)" gradientUnits="userSpaceOnUse">',
'<stop offset="50%" stop-color="',
accentColor,
'"/>',
'<stop offset="80%" stop-color="',
BACKGROUND_COLOR,
'"/>',
"</linearGradient>"
);
return string.concat(radialGlow, sandTop, sandBottom, hourglassStroke);
}
function hourglass(string memory status) internal pure returns (string memory) {
bool settledOrDepleted = status.equal("Settled") || status.equal("Depleted");
return string.concat(
'<g id="Hourglass">',
HOURGLASS_BACKGROUND_CIRCLE,
HOURGLASS_FILL,
settledOrDepleted ? "" : HOURGLASS_UPPER_BULB, // empty or filled
settledOrDepleted ? HOURGLASS_LOWER_BULB_LARGE : HOURGLASS_LOWER_BULB_SMALL,
HOURGLASS_STROKE, // needs to be declared last so that the stroke is painted on top of the sand
"</g>"
);
}
function progressCircle(
uint256 progressNumerical,
string memory accentColor
)
internal
pure
returns (string memory)
{
if (progressNumerical == 0) {
return "";
}
return string.concat(
'<g fill="none">',
'<circle cx="166" cy="50" r="22" stroke="',
BACKGROUND_COLOR,
'" stroke-width="10"/>',
'<circle cx="166" cy="50" pathLength="10000" r="22" stroke="',
accentColor,
'" stroke-dasharray="10000" stroke-dashoffset="',
(10_000 - progressNumerical).toString(),
'" stroke-linecap="round" stroke-width="5" transform="rotate(-90)" transform-origin="166 50"/>',
"</g>"
);
}
/*//////////////////////////////////////////////////////////////////////////
HELPERS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Calculates the pixel width of the provided string.
/// @dev Notes:
/// - A factor of ~0.6 is applied to the two font sizes used in the SVG (26px and 22px) to approximate the average
/// character width.
/// - It is assumed that escaped characters are placed at the beginning of `text`.
/// - It is further assumed that there is no other semicolon in `text`.
function calculatePixelWidth(string memory text, bool largeFont) internal pure returns (uint256 width) {
uint256 length = bytes(text).length;
if (length == 0) {
return 0;
}
unchecked {
uint256 charWidth = largeFont ? 16 : 13;
uint256 semicolonIndex;
for (uint256 i = 0; i < length;) {
if (bytes(text)[i] == ";") {
semicolonIndex = i;
}
width += charWidth;
i += 1;
}
// Account for escaped characters (such as ≥).
width -= charWidth * semicolonIndex;
}
}
/// @notice Retrieves the card type as a string.
function stringifyCardType(CardType cardType) internal pure returns (string memory) {
if (cardType == CardType.PROGRESS) {
return "Progress";
} else if (cardType == CardType.STATUS) {
return "Status";
} else if (cardType == CardType.STREAMED) {
return "Streamed";
} else {
return "Duration";
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1, "Math: mulDiv overflow");
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.19;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { UD60x18 } from "@prb/math/UD60x18.sol";
import { IAdminable } from "./IAdminable.sol";
import { ISablierV2Comptroller } from "./ISablierV2Comptroller.sol";
/// @title ISablierV2Base
/// @notice Base logic for all Sablier V2 streaming contracts.
interface ISablierV2Base is IAdminable {
/*//////////////////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Emitted when the admin claims all protocol revenues accrued for a particular ERC-20 asset.
/// @param admin The address of the contract admin.
/// @param asset The contract address of the ERC-20 asset the protocol revenues have been claimed for.
/// @param protocolRevenues The amount of protocol revenues claimed, denoted in units of the asset's decimals.
event ClaimProtocolRevenues(address indexed admin, IERC20 indexed asset, uint128 protocolRevenues);
/// @notice Emitted when the admin sets a new comptroller contract.
/// @param admin The address of the contract admin.
/// @param oldComptroller The address of the old comptroller contract.
/// @param newComptroller The address of the new comptroller contract.
event SetComptroller(
address indexed admin, ISablierV2Comptroller oldComptroller, ISablierV2Comptroller newComptroller
);
/*//////////////////////////////////////////////////////////////////////////
CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Retrieves the maximum fee that can be charged by the protocol or a broker, denoted as a fixed-point
/// number where 1e18 is 100%.
/// @dev This value is hard coded as a constant.
function MAX_FEE() external view returns (UD60x18);
/// @notice Retrieves the address of the comptroller contract, responsible for the Sablier V2 protocol
/// configuration.
function comptroller() external view returns (ISablierV2Comptroller);
/// @notice Retrieves the protocol revenues accrued for the provided ERC-20 asset, in units of the asset's
/// decimals.
/// @param asset The contract address of the ERC-20 asset to query.
function protocolRevenues(IERC20 asset) external view returns (uint128 revenues);
/*//////////////////////////////////////////////////////////////////////////
NON-CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Claims all accumulated protocol revenues for the provided ERC-20 asset.
///
/// @dev Emits a {ClaimProtocolRevenues} event.
///
/// Requirements:
/// - `msg.sender` must be the contract admin.
///
/// @param asset The contract address of the ERC-20 asset for which to claim protocol revenues.
function claimProtocolRevenues(IERC20 asset) external;
/// @notice Assigns a new comptroller contract responsible for the protocol configuration.
///
/// @dev Emits a {SetComptroller} event.
///
/// Notes:
/// - Does not revert if the comptroller is the same.
///
/// Requirements:
/// - `msg.sender` must be the contract admin.
///
/// @param newComptroller The address of the new comptroller contract.
function setComptroller(ISablierV2Comptroller newComptroller) external;
}// SPDX-License-Identifier: MIT pragma solidity >=0.8.19; /* ██████╗ ██████╗ ██████╗ ███╗ ███╗ █████╗ ████████╗██╗ ██╗ ██╔══██╗██╔══██╗██╔══██╗████╗ ████║██╔══██╗╚══██╔══╝██║ ██║ ██████╔╝██████╔╝██████╔╝██╔████╔██║███████║ ██║ ███████║ ██╔═══╝ ██╔══██╗██╔══██╗██║╚██╔╝██║██╔══██║ ██║ ██╔══██║ ██║ ██║ ██║██████╔╝██║ ╚═╝ ██║██║ ██║ ██║ ██║ ██║ ╚═╝ ╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ██╗ ██╗██████╗ ██████╗ ██╗ ██╗ ██╗ █████╗ ██║ ██║██╔══██╗╚════██╗╚██╗██╔╝███║██╔══██╗ ██║ ██║██║ ██║ █████╔╝ ╚███╔╝ ╚██║╚█████╔╝ ██║ ██║██║ ██║██╔═══╝ ██╔██╗ ██║██╔══██╗ ╚██████╔╝██████╔╝███████╗██╔╝ ██╗ ██║╚█████╔╝ ╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚════╝ */ import "./ud2x18/Casting.sol"; import "./ud2x18/Constants.sol"; import "./ud2x18/Errors.sol"; import "./ud2x18/ValueType.sol";
// SPDX-License-Identifier: MIT pragma solidity >=0.8.19; /* ██████╗ ██████╗ ██████╗ ███╗ ███╗ █████╗ ████████╗██╗ ██╗ ██╔══██╗██╔══██╗██╔══██╗████╗ ████║██╔══██╗╚══██╔══╝██║ ██║ ██████╔╝██████╔╝██████╔╝██╔████╔██║███████║ ██║ ███████║ ██╔═══╝ ██╔══██╗██╔══██╗██║╚██╔╝██║██╔══██║ ██║ ██╔══██║ ██║ ██║ ██║██████╔╝██║ ╚═╝ ██║██║ ██║ ██║ ██║ ██║ ╚═╝ ╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ██╗ ██╗██████╗ ██████╗ ██████╗ ██╗ ██╗ ██╗ █████╗ ██║ ██║██╔══██╗██╔════╝ ██╔═████╗╚██╗██╔╝███║██╔══██╗ ██║ ██║██║ ██║███████╗ ██║██╔██║ ╚███╔╝ ╚██║╚█████╔╝ ██║ ██║██║ ██║██╔═══██╗████╔╝██║ ██╔██╗ ██║██╔══██╗ ╚██████╔╝██████╔╝╚██████╔╝╚██████╔╝██╔╝ ██╗ ██║╚█████╔╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚════╝ */ import "./ud60x18/Casting.sol"; import "./ud60x18/Constants.sol"; import "./ud60x18/Conversions.sol"; import "./ud60x18/Errors.sol"; import "./ud60x18/Helpers.sol"; import "./ud60x18/Math.sol"; import "./ud60x18/ValueType.sol";
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.19;
/// @title IAdminable
/// @notice Contract module that provides a basic access control mechanism, with an admin that can be
/// granted exclusive access to specific functions. The inheriting contract must set the initial admin
/// in the constructor.
interface IAdminable {
/*//////////////////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Emitted when the admin is transferred.
/// @param oldAdmin The address of the old admin.
/// @param newAdmin The address of the new admin.
event TransferAdmin(address indexed oldAdmin, address indexed newAdmin);
/*//////////////////////////////////////////////////////////////////////////
CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @notice The address of the admin account or contract.
function admin() external view returns (address);
/*//////////////////////////////////////////////////////////////////////////
NON-CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Transfers the contract admin to a new address.
///
/// @dev Notes:
/// - Does not revert if the admin is the same.
/// - This function can potentially leave the contract without an admin, thereby removing any
/// functionality that is only available to the admin.
///
/// Requirements:
/// - `msg.sender` must be the contract admin.
///
/// @param newAdmin The address of the new admin.
function transferAdmin(address newAdmin) external;
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.19;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { UD60x18 } from "@prb/math/UD60x18.sol";
import { IAdminable } from "./IAdminable.sol";
/// @title ISablierV2Controller
/// @notice This contract is in charge of the Sablier V2 protocol configuration, handling such values as the
/// protocol fees.
interface ISablierV2Comptroller is IAdminable {
/*//////////////////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Emitted when the admin sets a new flash fee.
/// @param admin The address of the contract admin.
/// @param oldFlashFee The old flash fee, denoted as a fixed-point number.
/// @param newFlashFee The new flash fee, denoted as a fixed-point number.
event SetFlashFee(address indexed admin, UD60x18 oldFlashFee, UD60x18 newFlashFee);
/// @notice Emitted when the admin sets a new protocol fee for the provided ERC-20 asset.
/// @param admin The address of the contract admin.
/// @param asset The contract address of the ERC-20 asset the new protocol fee has been set for.
/// @param oldProtocolFee The old protocol fee, denoted as a fixed-point number.
/// @param newProtocolFee The new protocol fee, denoted as a fixed-point number.
event SetProtocolFee(address indexed admin, IERC20 indexed asset, UD60x18 oldProtocolFee, UD60x18 newProtocolFee);
/// @notice Emitted when the admin enables or disables an ERC-20 asset for flash loaning.
/// @param admin The address of the contract admin.
/// @param asset The contract address of the ERC-20 asset to toggle.
/// @param newFlag Whether the ERC-20 asset can be flash loaned.
event ToggleFlashAsset(address indexed admin, IERC20 indexed asset, bool newFlag);
/*//////////////////////////////////////////////////////////////////////////
CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Retrieves the global flash fee, denoted as a fixed-point number where 1e18 is 100%.
///
/// @dev Notes:
/// - This fee represents a percentage, not an amount. Do not confuse it with {IERC3156FlashLender.flashFee},
/// which calculates the fee amount for a specified flash loan amount.
/// - Unlike the protocol fee, this is a global fee applied to all flash loans, not a per-asset fee.
function flashFee() external view returns (UD60x18 fee);
/// @notice Retrieves a flag indicating whether the provided ERC-20 asset can be flash loaned.
/// @param token The contract address of the ERC-20 asset to check.
function isFlashAsset(IERC20 token) external view returns (bool result);
/// @notice Retrieves the protocol fee for all streams created with the provided ERC-20 asset.
/// @param asset The contract address of the ERC-20 asset to query.
/// @return fee The protocol fee denoted as a fixed-point number where 1e18 is 100%.
function protocolFees(IERC20 asset) external view returns (UD60x18 fee);
/*//////////////////////////////////////////////////////////////////////////
NON-CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Updates the flash fee charged on all flash loans made with any ERC-20 asset.
///
/// @dev Emits a {SetFlashFee} event.
///
/// Notes:
/// - Does not revert if the fee is the same.
///
/// Requirements:
/// - `msg.sender` must be the contract admin.
///
/// @param newFlashFee The new flash fee to set, denoted as a fixed-point number where 1e18 is 100%.
function setFlashFee(UD60x18 newFlashFee) external;
/// @notice Sets a new protocol fee that will be charged on all streams created with the provided ERC-20 asset.
///
/// @dev Emits a {SetProtocolFee} event.
///
/// Notes:
/// - The fee is not denoted in units of the asset's decimals; it is a fixed-point number. Refer to the
/// PRBMath documentation for more detail on the logic of UD60x18.
/// - Does not revert if the fee is the same.
///
/// Requirements:
/// - `msg.sender` must be the contract admin.
///
/// @param asset The contract address of the ERC-20 asset to update the fee for.
/// @param newProtocolFee The new protocol fee, denoted as a fixed-point number where 1e18 is 100%.
function setProtocolFee(IERC20 asset, UD60x18 newProtocolFee) external;
/// @notice Toggles the flash loanability of an ERC-20 asset.
///
/// @dev Emits a {ToggleFlashAsset} event.
///
/// Requirements:
/// - `msg.sender` must be the admin.
///
/// @param asset The address of the ERC-20 asset to toggle.
function toggleFlashAsset(IERC20 asset) external;
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "../Common.sol" as Common;
import "./Errors.sol" as Errors;
import { uMAX_SD1x18 } from "../sd1x18/Constants.sol";
import { SD1x18 } from "../sd1x18/ValueType.sol";
import { SD59x18 } from "../sd59x18/ValueType.sol";
import { UD2x18 } from "../ud2x18/ValueType.sol";
import { UD60x18 } from "../ud60x18/ValueType.sol";
import { UD2x18 } from "./ValueType.sol";
/// @notice Casts a UD2x18 number into SD1x18.
/// - x must be less than or equal to `uMAX_SD1x18`.
function intoSD1x18(UD2x18 x) pure returns (SD1x18 result) {
uint64 xUint = UD2x18.unwrap(x);
if (xUint > uint64(uMAX_SD1x18)) {
revert Errors.PRBMath_UD2x18_IntoSD1x18_Overflow(x);
}
result = SD1x18.wrap(int64(xUint));
}
/// @notice Casts a UD2x18 number into SD59x18.
/// @dev There is no overflow check because the domain of UD2x18 is a subset of SD59x18.
function intoSD59x18(UD2x18 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(int256(uint256(UD2x18.unwrap(x))));
}
/// @notice Casts a UD2x18 number into UD60x18.
/// @dev There is no overflow check because the domain of UD2x18 is a subset of UD60x18.
function intoUD60x18(UD2x18 x) pure returns (UD60x18 result) {
result = UD60x18.wrap(UD2x18.unwrap(x));
}
/// @notice Casts a UD2x18 number into uint128.
/// @dev There is no overflow check because the domain of UD2x18 is a subset of uint128.
function intoUint128(UD2x18 x) pure returns (uint128 result) {
result = uint128(UD2x18.unwrap(x));
}
/// @notice Casts a UD2x18 number into uint256.
/// @dev There is no overflow check because the domain of UD2x18 is a subset of uint256.
function intoUint256(UD2x18 x) pure returns (uint256 result) {
result = uint256(UD2x18.unwrap(x));
}
/// @notice Casts a UD2x18 number into uint40.
/// @dev Requirements:
/// - x must be less than or equal to `MAX_UINT40`.
function intoUint40(UD2x18 x) pure returns (uint40 result) {
uint64 xUint = UD2x18.unwrap(x);
if (xUint > uint64(Common.MAX_UINT40)) {
revert Errors.PRBMath_UD2x18_IntoUint40_Overflow(x);
}
result = uint40(xUint);
}
/// @notice Alias for {wrap}.
function ud2x18(uint64 x) pure returns (UD2x18 result) {
result = UD2x18.wrap(x);
}
/// @notice Unwrap a UD2x18 number into uint64.
function unwrap(UD2x18 x) pure returns (uint64 result) {
result = UD2x18.unwrap(x);
}
/// @notice Wraps a uint64 number into UD2x18.
function wrap(uint64 x) pure returns (UD2x18 result) {
result = UD2x18.wrap(x);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { UD2x18 } from "./ValueType.sol";
/// @dev Euler's number as a UD2x18 number.
UD2x18 constant E = UD2x18.wrap(2_718281828459045235);
/// @dev The maximum value a UD2x18 number can have.
uint64 constant uMAX_UD2x18 = 18_446744073709551615;
UD2x18 constant MAX_UD2x18 = UD2x18.wrap(uMAX_UD2x18);
/// @dev PI as a UD2x18 number.
UD2x18 constant PI = UD2x18.wrap(3_141592653589793238);
/// @dev The unit number, which gives the decimal precision of UD2x18.
uint256 constant uUNIT = 1e18;
UD2x18 constant UNIT = UD2x18.wrap(1e18);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { UD2x18 } from "./ValueType.sol";
/// @notice Thrown when trying to cast a UD2x18 number that doesn't fit in SD1x18.
error PRBMath_UD2x18_IntoSD1x18_Overflow(UD2x18 x);
/// @notice Thrown when trying to cast a UD2x18 number that doesn't fit in uint40.
error PRBMath_UD2x18_IntoUint40_Overflow(UD2x18 x);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Casting.sol" as Casting;
/// @notice The unsigned 2.18-decimal fixed-point number representation, which can have up to 2 digits and up to 18
/// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
/// type uint64. This is useful when end users want to use uint64 to save gas, e.g. with tight variable packing in contract
/// storage.
type UD2x18 is uint64;
/*//////////////////////////////////////////////////////////////////////////
CASTING
//////////////////////////////////////////////////////////////////////////*/
using {
Casting.intoSD1x18,
Casting.intoSD59x18,
Casting.intoUD60x18,
Casting.intoUint256,
Casting.intoUint128,
Casting.intoUint40,
Casting.unwrap
} for UD2x18 global;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Errors.sol" as CastingErrors;
import { MAX_UINT128, MAX_UINT40 } from "../Common.sol";
import { uMAX_SD1x18 } from "../sd1x18/Constants.sol";
import { SD1x18 } from "../sd1x18/ValueType.sol";
import { uMAX_SD59x18 } from "../sd59x18/Constants.sol";
import { SD59x18 } from "../sd59x18/ValueType.sol";
import { uMAX_UD2x18 } from "../ud2x18/Constants.sol";
import { UD2x18 } from "../ud2x18/ValueType.sol";
import { UD60x18 } from "./ValueType.sol";
/// @notice Casts a UD60x18 number into SD1x18.
/// @dev Requirements:
/// - x must be less than or equal to `uMAX_SD1x18`.
function intoSD1x18(UD60x18 x) pure returns (SD1x18 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > uint256(int256(uMAX_SD1x18))) {
revert CastingErrors.PRBMath_UD60x18_IntoSD1x18_Overflow(x);
}
result = SD1x18.wrap(int64(uint64(xUint)));
}
/// @notice Casts a UD60x18 number into UD2x18.
/// @dev Requirements:
/// - x must be less than or equal to `uMAX_UD2x18`.
function intoUD2x18(UD60x18 x) pure returns (UD2x18 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > uMAX_UD2x18) {
revert CastingErrors.PRBMath_UD60x18_IntoUD2x18_Overflow(x);
}
result = UD2x18.wrap(uint64(xUint));
}
/// @notice Casts a UD60x18 number into SD59x18.
/// @dev Requirements:
/// - x must be less than or equal to `uMAX_SD59x18`.
function intoSD59x18(UD60x18 x) pure returns (SD59x18 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > uint256(uMAX_SD59x18)) {
revert CastingErrors.PRBMath_UD60x18_IntoSD59x18_Overflow(x);
}
result = SD59x18.wrap(int256(xUint));
}
/// @notice Casts a UD60x18 number into uint128.
/// @dev This is basically an alias for {unwrap}.
function intoUint256(UD60x18 x) pure returns (uint256 result) {
result = UD60x18.unwrap(x);
}
/// @notice Casts a UD60x18 number into uint128.
/// @dev Requirements:
/// - x must be less than or equal to `MAX_UINT128`.
function intoUint128(UD60x18 x) pure returns (uint128 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > MAX_UINT128) {
revert CastingErrors.PRBMath_UD60x18_IntoUint128_Overflow(x);
}
result = uint128(xUint);
}
/// @notice Casts a UD60x18 number into uint40.
/// @dev Requirements:
/// - x must be less than or equal to `MAX_UINT40`.
function intoUint40(UD60x18 x) pure returns (uint40 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > MAX_UINT40) {
revert CastingErrors.PRBMath_UD60x18_IntoUint40_Overflow(x);
}
result = uint40(xUint);
}
/// @notice Alias for {wrap}.
function ud(uint256 x) pure returns (UD60x18 result) {
result = UD60x18.wrap(x);
}
/// @notice Alias for {wrap}.
function ud60x18(uint256 x) pure returns (UD60x18 result) {
result = UD60x18.wrap(x);
}
/// @notice Unwraps a UD60x18 number into uint256.
function unwrap(UD60x18 x) pure returns (uint256 result) {
result = UD60x18.unwrap(x);
}
/// @notice Wraps a uint256 number into the UD60x18 value type.
function wrap(uint256 x) pure returns (UD60x18 result) {
result = UD60x18.wrap(x);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { UD60x18 } from "./ValueType.sol";
// NOTICE: the "u" prefix stands for "unwrapped".
/// @dev Euler's number as a UD60x18 number.
UD60x18 constant E = UD60x18.wrap(2_718281828459045235);
/// @dev The maximum input permitted in {exp}.
uint256 constant uEXP_MAX_INPUT = 133_084258667509499440;
UD60x18 constant EXP_MAX_INPUT = UD60x18.wrap(uEXP_MAX_INPUT);
/// @dev The maximum input permitted in {exp2}.
uint256 constant uEXP2_MAX_INPUT = 192e18 - 1;
UD60x18 constant EXP2_MAX_INPUT = UD60x18.wrap(uEXP2_MAX_INPUT);
/// @dev Half the UNIT number.
uint256 constant uHALF_UNIT = 0.5e18;
UD60x18 constant HALF_UNIT = UD60x18.wrap(uHALF_UNIT);
/// @dev $log_2(10)$ as a UD60x18 number.
uint256 constant uLOG2_10 = 3_321928094887362347;
UD60x18 constant LOG2_10 = UD60x18.wrap(uLOG2_10);
/// @dev $log_2(e)$ as a UD60x18 number.
uint256 constant uLOG2_E = 1_442695040888963407;
UD60x18 constant LOG2_E = UD60x18.wrap(uLOG2_E);
/// @dev The maximum value a UD60x18 number can have.
uint256 constant uMAX_UD60x18 = 115792089237316195423570985008687907853269984665640564039457_584007913129639935;
UD60x18 constant MAX_UD60x18 = UD60x18.wrap(uMAX_UD60x18);
/// @dev The maximum whole value a UD60x18 number can have.
uint256 constant uMAX_WHOLE_UD60x18 = 115792089237316195423570985008687907853269984665640564039457_000000000000000000;
UD60x18 constant MAX_WHOLE_UD60x18 = UD60x18.wrap(uMAX_WHOLE_UD60x18);
/// @dev PI as a UD60x18 number.
UD60x18 constant PI = UD60x18.wrap(3_141592653589793238);
/// @dev The unit number, which gives the decimal precision of UD60x18.
uint256 constant uUNIT = 1e18;
UD60x18 constant UNIT = UD60x18.wrap(uUNIT);
/// @dev The unit number squared.
uint256 constant uUNIT_SQUARED = 1e36;
UD60x18 constant UNIT_SQUARED = UD60x18.wrap(uUNIT_SQUARED);
/// @dev Zero as a UD60x18 number.
UD60x18 constant ZERO = UD60x18.wrap(0);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { uMAX_UD60x18, uUNIT } from "./Constants.sol";
import { PRBMath_UD60x18_Convert_Overflow } from "./Errors.sol";
import { UD60x18 } from "./ValueType.sol";
/// @notice Converts a UD60x18 number to a simple integer by dividing it by `UNIT`.
/// @dev The result is rounded toward zero.
/// @param x The UD60x18 number to convert.
/// @return result The same number in basic integer form.
function convert(UD60x18 x) pure returns (uint256 result) {
result = UD60x18.unwrap(x) / uUNIT;
}
/// @notice Converts a simple integer to UD60x18 by multiplying it by `UNIT`.
///
/// @dev Requirements:
/// - x must be less than or equal to `MAX_UD60x18 / UNIT`.
///
/// @param x The basic integer to convert.
/// @param result The same number converted to UD60x18.
function convert(uint256 x) pure returns (UD60x18 result) {
if (x > uMAX_UD60x18 / uUNIT) {
revert PRBMath_UD60x18_Convert_Overflow(x);
}
unchecked {
result = UD60x18.wrap(x * uUNIT);
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { UD60x18 } from "./ValueType.sol";
/// @notice Thrown when ceiling a number overflows UD60x18.
error PRBMath_UD60x18_Ceil_Overflow(UD60x18 x);
/// @notice Thrown when converting a basic integer to the fixed-point format overflows UD60x18.
error PRBMath_UD60x18_Convert_Overflow(uint256 x);
/// @notice Thrown when taking the natural exponent of a base greater than 133_084258667509499441.
error PRBMath_UD60x18_Exp_InputTooBig(UD60x18 x);
/// @notice Thrown when taking the binary exponent of a base greater than 192e18.
error PRBMath_UD60x18_Exp2_InputTooBig(UD60x18 x);
/// @notice Thrown when taking the geometric mean of two numbers and multiplying them overflows UD60x18.
error PRBMath_UD60x18_Gm_Overflow(UD60x18 x, UD60x18 y);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD1x18.
error PRBMath_UD60x18_IntoSD1x18_Overflow(UD60x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD59x18.
error PRBMath_UD60x18_IntoSD59x18_Overflow(UD60x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in UD2x18.
error PRBMath_UD60x18_IntoUD2x18_Overflow(UD60x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint128.
error PRBMath_UD60x18_IntoUint128_Overflow(UD60x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint40.
error PRBMath_UD60x18_IntoUint40_Overflow(UD60x18 x);
/// @notice Thrown when taking the logarithm of a number less than 1.
error PRBMath_UD60x18_Log_InputTooSmall(UD60x18 x);
/// @notice Thrown when calculating the square root overflows UD60x18.
error PRBMath_UD60x18_Sqrt_Overflow(UD60x18 x);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { wrap } from "./Casting.sol";
import { UD60x18 } from "./ValueType.sol";
/// @notice Implements the checked addition operation (+) in the UD60x18 type.
function add(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() + y.unwrap());
}
/// @notice Implements the AND (&) bitwise operation in the UD60x18 type.
function and(UD60x18 x, uint256 bits) pure returns (UD60x18 result) {
result = wrap(x.unwrap() & bits);
}
/// @notice Implements the AND (&) bitwise operation in the UD60x18 type.
function and2(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() & y.unwrap());
}
/// @notice Implements the equal operation (==) in the UD60x18 type.
function eq(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() == y.unwrap();
}
/// @notice Implements the greater than operation (>) in the UD60x18 type.
function gt(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() > y.unwrap();
}
/// @notice Implements the greater than or equal to operation (>=) in the UD60x18 type.
function gte(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() >= y.unwrap();
}
/// @notice Implements a zero comparison check function in the UD60x18 type.
function isZero(UD60x18 x) pure returns (bool result) {
// This wouldn't work if x could be negative.
result = x.unwrap() == 0;
}
/// @notice Implements the left shift operation (<<) in the UD60x18 type.
function lshift(UD60x18 x, uint256 bits) pure returns (UD60x18 result) {
result = wrap(x.unwrap() << bits);
}
/// @notice Implements the lower than operation (<) in the UD60x18 type.
function lt(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() < y.unwrap();
}
/// @notice Implements the lower than or equal to operation (<=) in the UD60x18 type.
function lte(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() <= y.unwrap();
}
/// @notice Implements the checked modulo operation (%) in the UD60x18 type.
function mod(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() % y.unwrap());
}
/// @notice Implements the not equal operation (!=) in the UD60x18 type.
function neq(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() != y.unwrap();
}
/// @notice Implements the NOT (~) bitwise operation in the UD60x18 type.
function not(UD60x18 x) pure returns (UD60x18 result) {
result = wrap(~x.unwrap());
}
/// @notice Implements the OR (|) bitwise operation in the UD60x18 type.
function or(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() | y.unwrap());
}
/// @notice Implements the right shift operation (>>) in the UD60x18 type.
function rshift(UD60x18 x, uint256 bits) pure returns (UD60x18 result) {
result = wrap(x.unwrap() >> bits);
}
/// @notice Implements the checked subtraction operation (-) in the UD60x18 type.
function sub(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() - y.unwrap());
}
/// @notice Implements the unchecked addition operation (+) in the UD60x18 type.
function uncheckedAdd(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
unchecked {
result = wrap(x.unwrap() + y.unwrap());
}
}
/// @notice Implements the unchecked subtraction operation (-) in the UD60x18 type.
function uncheckedSub(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
unchecked {
result = wrap(x.unwrap() - y.unwrap());
}
}
/// @notice Implements the XOR (^) bitwise operation in the UD60x18 type.
function xor(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() ^ y.unwrap());
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "../Common.sol" as Common;
import "./Errors.sol" as Errors;
import { wrap } from "./Casting.sol";
import {
uEXP_MAX_INPUT,
uEXP2_MAX_INPUT,
uHALF_UNIT,
uLOG2_10,
uLOG2_E,
uMAX_UD60x18,
uMAX_WHOLE_UD60x18,
UNIT,
uUNIT,
uUNIT_SQUARED,
ZERO
} from "./Constants.sol";
import { UD60x18 } from "./ValueType.sol";
/*//////////////////////////////////////////////////////////////////////////
MATHEMATICAL FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Calculates the arithmetic average of x and y using the following formula:
///
/// $$
/// avg(x, y) = (x & y) + ((xUint ^ yUint) / 2)
/// $$
//
/// In English, this is what this formula does:
///
/// 1. AND x and y.
/// 2. Calculate half of XOR x and y.
/// 3. Add the two results together.
///
/// This technique is known as SWAR, which stands for "SIMD within a register". You can read more about it here:
/// https://devblogs.microsoft.com/oldnewthing/20220207-00/?p=106223
///
/// @dev Notes:
/// - The result is rounded toward zero.
///
/// @param x The first operand as a UD60x18 number.
/// @param y The second operand as a UD60x18 number.
/// @return result The arithmetic average as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function avg(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
uint256 yUint = y.unwrap();
unchecked {
result = wrap((xUint & yUint) + ((xUint ^ yUint) >> 1));
}
}
/// @notice Yields the smallest whole number greater than or equal to x.
///
/// @dev This is optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional
/// counterparts. See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
///
/// Requirements:
/// - x must be less than or equal to `MAX_WHOLE_UD60x18`.
///
/// @param x The UD60x18 number to ceil.
/// @param result The smallest whole number greater than or equal to x, as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function ceil(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
if (xUint > uMAX_WHOLE_UD60x18) {
revert Errors.PRBMath_UD60x18_Ceil_Overflow(x);
}
assembly ("memory-safe") {
// Equivalent to `x % UNIT`.
let remainder := mod(x, uUNIT)
// Equivalent to `UNIT - remainder`.
let delta := sub(uUNIT, remainder)
// Equivalent to `x + remainder > 0 ? delta : 0`.
result := add(x, mul(delta, gt(remainder, 0)))
}
}
/// @notice Divides two UD60x18 numbers, returning a new UD60x18 number.
///
/// @dev Uses {Common.mulDiv} to enable overflow-safe multiplication and division.
///
/// Notes:
/// - Refer to the notes in {Common.mulDiv}.
///
/// Requirements:
/// - Refer to the requirements in {Common.mulDiv}.
///
/// @param x The numerator as a UD60x18 number.
/// @param y The denominator as a UD60x18 number.
/// @param result The quotient as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function div(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(Common.mulDiv(x.unwrap(), uUNIT, y.unwrap()));
}
/// @notice Calculates the natural exponent of x using the following formula:
///
/// $$
/// e^x = 2^{x * log_2{e}}
/// $$
///
/// @dev Requirements:
/// - x must be less than 133_084258667509499441.
///
/// @param x The exponent as a UD60x18 number.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function exp(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
// This check prevents values greater than 192e18 from being passed to {exp2}.
if (xUint > uEXP_MAX_INPUT) {
revert Errors.PRBMath_UD60x18_Exp_InputTooBig(x);
}
unchecked {
// Inline the fixed-point multiplication to save gas.
uint256 doubleUnitProduct = xUint * uLOG2_E;
result = exp2(wrap(doubleUnitProduct / uUNIT));
}
}
/// @notice Calculates the binary exponent of x using the binary fraction method.
///
/// @dev See https://ethereum.stackexchange.com/q/79903/24693
///
/// Requirements:
/// - x must be less than 192e18.
/// - The result must fit in UD60x18.
///
/// @param x The exponent as a UD60x18 number.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function exp2(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
// Numbers greater than or equal to 192e18 don't fit in the 192.64-bit format.
if (xUint > uEXP2_MAX_INPUT) {
revert Errors.PRBMath_UD60x18_Exp2_InputTooBig(x);
}
// Convert x to the 192.64-bit fixed-point format.
uint256 x_192x64 = (xUint << 64) / uUNIT;
// Pass x to the {Common.exp2} function, which uses the 192.64-bit fixed-point number representation.
result = wrap(Common.exp2(x_192x64));
}
/// @notice Yields the greatest whole number less than or equal to x.
/// @dev Optimized for fractional value inputs, because every whole value has (1e18 - 1) fractional counterparts.
/// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
/// @param x The UD60x18 number to floor.
/// @param result The greatest whole number less than or equal to x, as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function floor(UD60x18 x) pure returns (UD60x18 result) {
assembly ("memory-safe") {
// Equivalent to `x % UNIT`.
let remainder := mod(x, uUNIT)
// Equivalent to `x - remainder > 0 ? remainder : 0)`.
result := sub(x, mul(remainder, gt(remainder, 0)))
}
}
/// @notice Yields the excess beyond the floor of x using the odd function definition.
/// @dev See https://en.wikipedia.org/wiki/Fractional_part.
/// @param x The UD60x18 number to get the fractional part of.
/// @param result The fractional part of x as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function frac(UD60x18 x) pure returns (UD60x18 result) {
assembly ("memory-safe") {
result := mod(x, uUNIT)
}
}
/// @notice Calculates the geometric mean of x and y, i.e. $\sqrt{x * y}$, rounding down.
///
/// @dev Requirements:
/// - x * y must fit in UD60x18.
///
/// @param x The first operand as a UD60x18 number.
/// @param y The second operand as a UD60x18 number.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function gm(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
uint256 yUint = y.unwrap();
if (xUint == 0 || yUint == 0) {
return ZERO;
}
unchecked {
// Checking for overflow this way is faster than letting Solidity do it.
uint256 xyUint = xUint * yUint;
if (xyUint / xUint != yUint) {
revert Errors.PRBMath_UD60x18_Gm_Overflow(x, y);
}
// We don't need to multiply the result by `UNIT` here because the x*y product picked up a factor of `UNIT`
// during multiplication. See the comments in {Common.sqrt}.
result = wrap(Common.sqrt(xyUint));
}
}
/// @notice Calculates the inverse of x.
///
/// @dev Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - x must not be zero.
///
/// @param x The UD60x18 number for which to calculate the inverse.
/// @return result The inverse as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function inv(UD60x18 x) pure returns (UD60x18 result) {
unchecked {
result = wrap(uUNIT_SQUARED / x.unwrap());
}
}
/// @notice Calculates the natural logarithm of x using the following formula:
///
/// $$
/// ln{x} = log_2{x} / log_2{e}
/// $$
///
/// @dev Notes:
/// - Refer to the notes in {log2}.
/// - The precision isn't sufficiently fine-grained to return exactly `UNIT` when the input is `E`.
///
/// Requirements:
/// - Refer to the requirements in {log2}.
///
/// @param x The UD60x18 number for which to calculate the natural logarithm.
/// @return result The natural logarithm as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function ln(UD60x18 x) pure returns (UD60x18 result) {
unchecked {
// Inline the fixed-point multiplication to save gas. This is overflow-safe because the maximum value that
// {log2} can return is ~196_205294292027477728.
result = wrap(log2(x).unwrap() * uUNIT / uLOG2_E);
}
}
/// @notice Calculates the common logarithm of x using the following formula:
///
/// $$
/// log_{10}{x} = log_2{x} / log_2{10}
/// $$
///
/// However, if x is an exact power of ten, a hard coded value is returned.
///
/// @dev Notes:
/// - Refer to the notes in {log2}.
///
/// Requirements:
/// - Refer to the requirements in {log2}.
///
/// @param x The UD60x18 number for which to calculate the common logarithm.
/// @return result The common logarithm as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function log10(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
if (xUint < uUNIT) {
revert Errors.PRBMath_UD60x18_Log_InputTooSmall(x);
}
// Note that the `mul` in this assembly block is the standard multiplication operation, not {UD60x18.mul}.
// prettier-ignore
assembly ("memory-safe") {
switch x
case 1 { result := mul(uUNIT, sub(0, 18)) }
case 10 { result := mul(uUNIT, sub(1, 18)) }
case 100 { result := mul(uUNIT, sub(2, 18)) }
case 1000 { result := mul(uUNIT, sub(3, 18)) }
case 10000 { result := mul(uUNIT, sub(4, 18)) }
case 100000 { result := mul(uUNIT, sub(5, 18)) }
case 1000000 { result := mul(uUNIT, sub(6, 18)) }
case 10000000 { result := mul(uUNIT, sub(7, 18)) }
case 100000000 { result := mul(uUNIT, sub(8, 18)) }
case 1000000000 { result := mul(uUNIT, sub(9, 18)) }
case 10000000000 { result := mul(uUNIT, sub(10, 18)) }
case 100000000000 { result := mul(uUNIT, sub(11, 18)) }
case 1000000000000 { result := mul(uUNIT, sub(12, 18)) }
case 10000000000000 { result := mul(uUNIT, sub(13, 18)) }
case 100000000000000 { result := mul(uUNIT, sub(14, 18)) }
case 1000000000000000 { result := mul(uUNIT, sub(15, 18)) }
case 10000000000000000 { result := mul(uUNIT, sub(16, 18)) }
case 100000000000000000 { result := mul(uUNIT, sub(17, 18)) }
case 1000000000000000000 { result := 0 }
case 10000000000000000000 { result := uUNIT }
case 100000000000000000000 { result := mul(uUNIT, 2) }
case 1000000000000000000000 { result := mul(uUNIT, 3) }
case 10000000000000000000000 { result := mul(uUNIT, 4) }
case 100000000000000000000000 { result := mul(uUNIT, 5) }
case 1000000000000000000000000 { result := mul(uUNIT, 6) }
case 10000000000000000000000000 { result := mul(uUNIT, 7) }
case 100000000000000000000000000 { result := mul(uUNIT, 8) }
case 1000000000000000000000000000 { result := mul(uUNIT, 9) }
case 10000000000000000000000000000 { result := mul(uUNIT, 10) }
case 100000000000000000000000000000 { result := mul(uUNIT, 11) }
case 1000000000000000000000000000000 { result := mul(uUNIT, 12) }
case 10000000000000000000000000000000 { result := mul(uUNIT, 13) }
case 100000000000000000000000000000000 { result := mul(uUNIT, 14) }
case 1000000000000000000000000000000000 { result := mul(uUNIT, 15) }
case 10000000000000000000000000000000000 { result := mul(uUNIT, 16) }
case 100000000000000000000000000000000000 { result := mul(uUNIT, 17) }
case 1000000000000000000000000000000000000 { result := mul(uUNIT, 18) }
case 10000000000000000000000000000000000000 { result := mul(uUNIT, 19) }
case 100000000000000000000000000000000000000 { result := mul(uUNIT, 20) }
case 1000000000000000000000000000000000000000 { result := mul(uUNIT, 21) }
case 10000000000000000000000000000000000000000 { result := mul(uUNIT, 22) }
case 100000000000000000000000000000000000000000 { result := mul(uUNIT, 23) }
case 1000000000000000000000000000000000000000000 { result := mul(uUNIT, 24) }
case 10000000000000000000000000000000000000000000 { result := mul(uUNIT, 25) }
case 100000000000000000000000000000000000000000000 { result := mul(uUNIT, 26) }
case 1000000000000000000000000000000000000000000000 { result := mul(uUNIT, 27) }
case 10000000000000000000000000000000000000000000000 { result := mul(uUNIT, 28) }
case 100000000000000000000000000000000000000000000000 { result := mul(uUNIT, 29) }
case 1000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 30) }
case 10000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 31) }
case 100000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 32) }
case 1000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 33) }
case 10000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 34) }
case 100000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 35) }
case 1000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 36) }
case 10000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 37) }
case 100000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 38) }
case 1000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 39) }
case 10000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 40) }
case 100000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 41) }
case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 42) }
case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 43) }
case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 44) }
case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 45) }
case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 46) }
case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 47) }
case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 48) }
case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 49) }
case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 50) }
case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 51) }
case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 52) }
case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 53) }
case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 54) }
case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 55) }
case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 56) }
case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 57) }
case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 58) }
case 100000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 59) }
default { result := uMAX_UD60x18 }
}
if (result.unwrap() == uMAX_UD60x18) {
unchecked {
// Inline the fixed-point division to save gas.
result = wrap(log2(x).unwrap() * uUNIT / uLOG2_10);
}
}
}
/// @notice Calculates the binary logarithm of x using the iterative approximation algorithm:
///
/// $$
/// log_2{x} = n + log_2{y}, \text{ where } y = x*2^{-n}, \ y \in [1, 2)
/// $$
///
/// For $0 \leq x \lt 1$, the input is inverted:
///
/// $$
/// log_2{x} = -log_2{\frac{1}{x}}
/// $$
///
/// @dev See https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation
///
/// Notes:
/// - Due to the lossy precision of the iterative approximation, the results are not perfectly accurate to the last decimal.
///
/// Requirements:
/// - x must be greater than zero.
///
/// @param x The UD60x18 number for which to calculate the binary logarithm.
/// @return result The binary logarithm as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function log2(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
if (xUint < uUNIT) {
revert Errors.PRBMath_UD60x18_Log_InputTooSmall(x);
}
unchecked {
// Calculate the integer part of the logarithm.
uint256 n = Common.msb(xUint / uUNIT);
// This is the integer part of the logarithm as a UD60x18 number. The operation can't overflow because n
// n is at most 255 and UNIT is 1e18.
uint256 resultUint = n * uUNIT;
// Calculate $y = x * 2^{-n}$.
uint256 y = xUint >> n;
// If y is the unit number, the fractional part is zero.
if (y == uUNIT) {
return wrap(resultUint);
}
// Calculate the fractional part via the iterative approximation.
// The `delta >>= 1` part is equivalent to `delta /= 2`, but shifting bits is more gas efficient.
uint256 DOUBLE_UNIT = 2e18;
for (uint256 delta = uHALF_UNIT; delta > 0; delta >>= 1) {
y = (y * y) / uUNIT;
// Is y^2 >= 2e18 and so in the range [2e18, 4e18)?
if (y >= DOUBLE_UNIT) {
// Add the 2^{-m} factor to the logarithm.
resultUint += delta;
// Halve y, which corresponds to z/2 in the Wikipedia article.
y >>= 1;
}
}
result = wrap(resultUint);
}
}
/// @notice Multiplies two UD60x18 numbers together, returning a new UD60x18 number.
///
/// @dev Uses {Common.mulDiv} to enable overflow-safe multiplication and division.
///
/// Notes:
/// - Refer to the notes in {Common.mulDiv}.
///
/// Requirements:
/// - Refer to the requirements in {Common.mulDiv}.
///
/// @dev See the documentation in {Common.mulDiv18}.
/// @param x The multiplicand as a UD60x18 number.
/// @param y The multiplier as a UD60x18 number.
/// @return result The product as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function mul(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(Common.mulDiv18(x.unwrap(), y.unwrap()));
}
/// @notice Raises x to the power of y.
///
/// For $1 \leq x \leq \infty$, the following standard formula is used:
///
/// $$
/// x^y = 2^{log_2{x} * y}
/// $$
///
/// For $0 \leq x \lt 1$, since the unsigned {log2} is undefined, an equivalent formula is used:
///
/// $$
/// i = \frac{1}{x}
/// w = 2^{log_2{i} * y}
/// x^y = \frac{1}{w}
/// $$
///
/// @dev Notes:
/// - Refer to the notes in {log2} and {mul}.
/// - Returns `UNIT` for 0^0.
/// - It may not perform well with very small values of x. Consider using SD59x18 as an alternative.
///
/// Requirements:
/// - Refer to the requirements in {exp2}, {log2}, and {mul}.
///
/// @param x The base as a UD60x18 number.
/// @param y The exponent as a UD60x18 number.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function pow(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
uint256 yUint = y.unwrap();
// If both x and y are zero, the result is `UNIT`. If just x is zero, the result is always zero.
if (xUint == 0) {
return yUint == 0 ? UNIT : ZERO;
}
// If x is `UNIT`, the result is always `UNIT`.
else if (xUint == uUNIT) {
return UNIT;
}
// If y is zero, the result is always `UNIT`.
if (yUint == 0) {
return UNIT;
}
// If y is `UNIT`, the result is always x.
else if (yUint == uUNIT) {
return x;
}
// If x is greater than `UNIT`, use the standard formula.
if (xUint > uUNIT) {
result = exp2(mul(log2(x), y));
}
// Conversely, if x is less than `UNIT`, use the equivalent formula.
else {
UD60x18 i = wrap(uUNIT_SQUARED / xUint);
UD60x18 w = exp2(mul(log2(i), y));
result = wrap(uUNIT_SQUARED / w.unwrap());
}
}
/// @notice Raises x (a UD60x18 number) to the power y (an unsigned basic integer) using the well-known
/// algorithm "exponentiation by squaring".
///
/// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring.
///
/// Notes:
/// - Refer to the notes in {Common.mulDiv18}.
/// - Returns `UNIT` for 0^0.
///
/// Requirements:
/// - The result must fit in UD60x18.
///
/// @param x The base as a UD60x18 number.
/// @param y The exponent as a uint256.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function powu(UD60x18 x, uint256 y) pure returns (UD60x18 result) {
// Calculate the first iteration of the loop in advance.
uint256 xUint = x.unwrap();
uint256 resultUint = y & 1 > 0 ? xUint : uUNIT;
// Equivalent to `for(y /= 2; y > 0; y /= 2)`.
for (y >>= 1; y > 0; y >>= 1) {
xUint = Common.mulDiv18(xUint, xUint);
// Equivalent to `y % 2 == 1`.
if (y & 1 > 0) {
resultUint = Common.mulDiv18(resultUint, xUint);
}
}
result = wrap(resultUint);
}
/// @notice Calculates the square root of x using the Babylonian method.
///
/// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
///
/// Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - x must be less than `MAX_UD60x18 / UNIT`.
///
/// @param x The UD60x18 number for which to calculate the square root.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function sqrt(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
unchecked {
if (xUint > uMAX_UD60x18 / uUNIT) {
revert Errors.PRBMath_UD60x18_Sqrt_Overflow(x);
}
// Multiply x by `UNIT` to account for the factor of `UNIT` picked up when multiplying two UD60x18 numbers.
// In this case, the two numbers are both the square root.
result = wrap(Common.sqrt(xUint * uUNIT));
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Casting.sol" as Casting;
import "./Helpers.sol" as Helpers;
import "./Math.sol" as Math;
/// @notice The unsigned 60.18-decimal fixed-point number representation, which can have up to 60 digits and up to 18
/// decimals. The values of this are bound by the minimum and the maximum values permitted by the Solidity type uint256.
/// @dev The value type is defined here so it can be imported in all other files.
type UD60x18 is uint256;
/*//////////////////////////////////////////////////////////////////////////
CASTING
//////////////////////////////////////////////////////////////////////////*/
using {
Casting.intoSD1x18,
Casting.intoUD2x18,
Casting.intoSD59x18,
Casting.intoUint128,
Casting.intoUint256,
Casting.intoUint40,
Casting.unwrap
} for UD60x18 global;
/*//////////////////////////////////////////////////////////////////////////
MATHEMATICAL FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
// The global "using for" directive makes the functions in this library callable on the UD60x18 type.
using {
Math.avg,
Math.ceil,
Math.div,
Math.exp,
Math.exp2,
Math.floor,
Math.frac,
Math.gm,
Math.inv,
Math.ln,
Math.log10,
Math.log2,
Math.mul,
Math.pow,
Math.powu,
Math.sqrt
} for UD60x18 global;
/*//////////////////////////////////////////////////////////////////////////
HELPER FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
// The global "using for" directive makes the functions in this library callable on the UD60x18 type.
using {
Helpers.add,
Helpers.and,
Helpers.eq,
Helpers.gt,
Helpers.gte,
Helpers.isZero,
Helpers.lshift,
Helpers.lt,
Helpers.lte,
Helpers.mod,
Helpers.neq,
Helpers.not,
Helpers.or,
Helpers.rshift,
Helpers.sub,
Helpers.uncheckedAdd,
Helpers.uncheckedSub,
Helpers.xor
} for UD60x18 global;
/*//////////////////////////////////////////////////////////////////////////
OPERATORS
//////////////////////////////////////////////////////////////////////////*/
// The global "using for" directive makes it possible to use these operators on the UD60x18 type.
using {
Helpers.add as +,
Helpers.and2 as &,
Math.div as /,
Helpers.eq as ==,
Helpers.gt as >,
Helpers.gte as >=,
Helpers.lt as <,
Helpers.lte as <=,
Helpers.or as |,
Helpers.mod as %,
Math.mul as *,
Helpers.neq as !=,
Helpers.not as ~,
Helpers.sub as -,
Helpers.xor as ^
} for UD60x18 global;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
// Common.sol
//
// Common mathematical functions needed by both SD59x18 and UD60x18. Note that these global functions do not
// always operate with SD59x18 and UD60x18 numbers.
/*//////////////////////////////////////////////////////////////////////////
CUSTOM ERRORS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Thrown when the resultant value in {mulDiv} overflows uint256.
error PRBMath_MulDiv_Overflow(uint256 x, uint256 y, uint256 denominator);
/// @notice Thrown when the resultant value in {mulDiv18} overflows uint256.
error PRBMath_MulDiv18_Overflow(uint256 x, uint256 y);
/// @notice Thrown when one of the inputs passed to {mulDivSigned} is `type(int256).min`.
error PRBMath_MulDivSigned_InputTooSmall();
/// @notice Thrown when the resultant value in {mulDivSigned} overflows int256.
error PRBMath_MulDivSigned_Overflow(int256 x, int256 y);
/*//////////////////////////////////////////////////////////////////////////
CONSTANTS
//////////////////////////////////////////////////////////////////////////*/
/// @dev The maximum value a uint128 number can have.
uint128 constant MAX_UINT128 = type(uint128).max;
/// @dev The maximum value a uint40 number can have.
uint40 constant MAX_UINT40 = type(uint40).max;
/// @dev The unit number, which the decimal precision of the fixed-point types.
uint256 constant UNIT = 1e18;
/// @dev The unit number inverted mod 2^256.
uint256 constant UNIT_INVERSE = 78156646155174841979727994598816262306175212592076161876661_508869554232690281;
/// @dev The the largest power of two that divides the decimal value of `UNIT`. The logarithm of this value is the least significant
/// bit in the binary representation of `UNIT`.
uint256 constant UNIT_LPOTD = 262144;
/*//////////////////////////////////////////////////////////////////////////
FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Calculates the binary exponent of x using the binary fraction method.
/// @dev Has to use 192.64-bit fixed-point numbers. See https://ethereum.stackexchange.com/a/96594/24693.
/// @param x The exponent as an unsigned 192.64-bit fixed-point number.
/// @return result The result as an unsigned 60.18-decimal fixed-point number.
/// @custom:smtchecker abstract-function-nondet
function exp2(uint256 x) pure returns (uint256 result) {
unchecked {
// Start from 0.5 in the 192.64-bit fixed-point format.
result = 0x800000000000000000000000000000000000000000000000;
// The following logic multiplies the result by $\sqrt{2^{-i}}$ when the bit at position i is 1. Key points:
//
// 1. Intermediate results will not overflow, as the starting point is 2^191 and all magic factors are under 2^65.
// 2. The rationale for organizing the if statements into groups of 8 is gas savings. If the result of performing
// a bitwise AND operation between x and any value in the array [0x80; 0x40; 0x20; 0x10; 0x08; 0x04; 0x02; 0x01] is 1,
// we know that `x & 0xFF` is also 1.
if (x & 0xFF00000000000000 > 0) {
if (x & 0x8000000000000000 > 0) {
result = (result * 0x16A09E667F3BCC909) >> 64;
}
if (x & 0x4000000000000000 > 0) {
result = (result * 0x1306FE0A31B7152DF) >> 64;
}
if (x & 0x2000000000000000 > 0) {
result = (result * 0x1172B83C7D517ADCE) >> 64;
}
if (x & 0x1000000000000000 > 0) {
result = (result * 0x10B5586CF9890F62A) >> 64;
}
if (x & 0x800000000000000 > 0) {
result = (result * 0x1059B0D31585743AE) >> 64;
}
if (x & 0x400000000000000 > 0) {
result = (result * 0x102C9A3E778060EE7) >> 64;
}
if (x & 0x200000000000000 > 0) {
result = (result * 0x10163DA9FB33356D8) >> 64;
}
if (x & 0x100000000000000 > 0) {
result = (result * 0x100B1AFA5ABCBED61) >> 64;
}
}
if (x & 0xFF000000000000 > 0) {
if (x & 0x80000000000000 > 0) {
result = (result * 0x10058C86DA1C09EA2) >> 64;
}
if (x & 0x40000000000000 > 0) {
result = (result * 0x1002C605E2E8CEC50) >> 64;
}
if (x & 0x20000000000000 > 0) {
result = (result * 0x100162F3904051FA1) >> 64;
}
if (x & 0x10000000000000 > 0) {
result = (result * 0x1000B175EFFDC76BA) >> 64;
}
if (x & 0x8000000000000 > 0) {
result = (result * 0x100058BA01FB9F96D) >> 64;
}
if (x & 0x4000000000000 > 0) {
result = (result * 0x10002C5CC37DA9492) >> 64;
}
if (x & 0x2000000000000 > 0) {
result = (result * 0x1000162E525EE0547) >> 64;
}
if (x & 0x1000000000000 > 0) {
result = (result * 0x10000B17255775C04) >> 64;
}
}
if (x & 0xFF0000000000 > 0) {
if (x & 0x800000000000 > 0) {
result = (result * 0x1000058B91B5BC9AE) >> 64;
}
if (x & 0x400000000000 > 0) {
result = (result * 0x100002C5C89D5EC6D) >> 64;
}
if (x & 0x200000000000 > 0) {
result = (result * 0x10000162E43F4F831) >> 64;
}
if (x & 0x100000000000 > 0) {
result = (result * 0x100000B1721BCFC9A) >> 64;
}
if (x & 0x80000000000 > 0) {
result = (result * 0x10000058B90CF1E6E) >> 64;
}
if (x & 0x40000000000 > 0) {
result = (result * 0x1000002C5C863B73F) >> 64;
}
if (x & 0x20000000000 > 0) {
result = (result * 0x100000162E430E5A2) >> 64;
}
if (x & 0x10000000000 > 0) {
result = (result * 0x1000000B172183551) >> 64;
}
}
if (x & 0xFF00000000 > 0) {
if (x & 0x8000000000 > 0) {
result = (result * 0x100000058B90C0B49) >> 64;
}
if (x & 0x4000000000 > 0) {
result = (result * 0x10000002C5C8601CC) >> 64;
}
if (x & 0x2000000000 > 0) {
result = (result * 0x1000000162E42FFF0) >> 64;
}
if (x & 0x1000000000 > 0) {
result = (result * 0x10000000B17217FBB) >> 64;
}
if (x & 0x800000000 > 0) {
result = (result * 0x1000000058B90BFCE) >> 64;
}
if (x & 0x400000000 > 0) {
result = (result * 0x100000002C5C85FE3) >> 64;
}
if (x & 0x200000000 > 0) {
result = (result * 0x10000000162E42FF1) >> 64;
}
if (x & 0x100000000 > 0) {
result = (result * 0x100000000B17217F8) >> 64;
}
}
if (x & 0xFF000000 > 0) {
if (x & 0x80000000 > 0) {
result = (result * 0x10000000058B90BFC) >> 64;
}
if (x & 0x40000000 > 0) {
result = (result * 0x1000000002C5C85FE) >> 64;
}
if (x & 0x20000000 > 0) {
result = (result * 0x100000000162E42FF) >> 64;
}
if (x & 0x10000000 > 0) {
result = (result * 0x1000000000B17217F) >> 64;
}
if (x & 0x8000000 > 0) {
result = (result * 0x100000000058B90C0) >> 64;
}
if (x & 0x4000000 > 0) {
result = (result * 0x10000000002C5C860) >> 64;
}
if (x & 0x2000000 > 0) {
result = (result * 0x1000000000162E430) >> 64;
}
if (x & 0x1000000 > 0) {
result = (result * 0x10000000000B17218) >> 64;
}
}
if (x & 0xFF0000 > 0) {
if (x & 0x800000 > 0) {
result = (result * 0x1000000000058B90C) >> 64;
}
if (x & 0x400000 > 0) {
result = (result * 0x100000000002C5C86) >> 64;
}
if (x & 0x200000 > 0) {
result = (result * 0x10000000000162E43) >> 64;
}
if (x & 0x100000 > 0) {
result = (result * 0x100000000000B1721) >> 64;
}
if (x & 0x80000 > 0) {
result = (result * 0x10000000000058B91) >> 64;
}
if (x & 0x40000 > 0) {
result = (result * 0x1000000000002C5C8) >> 64;
}
if (x & 0x20000 > 0) {
result = (result * 0x100000000000162E4) >> 64;
}
if (x & 0x10000 > 0) {
result = (result * 0x1000000000000B172) >> 64;
}
}
if (x & 0xFF00 > 0) {
if (x & 0x8000 > 0) {
result = (result * 0x100000000000058B9) >> 64;
}
if (x & 0x4000 > 0) {
result = (result * 0x10000000000002C5D) >> 64;
}
if (x & 0x2000 > 0) {
result = (result * 0x1000000000000162E) >> 64;
}
if (x & 0x1000 > 0) {
result = (result * 0x10000000000000B17) >> 64;
}
if (x & 0x800 > 0) {
result = (result * 0x1000000000000058C) >> 64;
}
if (x & 0x400 > 0) {
result = (result * 0x100000000000002C6) >> 64;
}
if (x & 0x200 > 0) {
result = (result * 0x10000000000000163) >> 64;
}
if (x & 0x100 > 0) {
result = (result * 0x100000000000000B1) >> 64;
}
}
if (x & 0xFF > 0) {
if (x & 0x80 > 0) {
result = (result * 0x10000000000000059) >> 64;
}
if (x & 0x40 > 0) {
result = (result * 0x1000000000000002C) >> 64;
}
if (x & 0x20 > 0) {
result = (result * 0x10000000000000016) >> 64;
}
if (x & 0x10 > 0) {
result = (result * 0x1000000000000000B) >> 64;
}
if (x & 0x8 > 0) {
result = (result * 0x10000000000000006) >> 64;
}
if (x & 0x4 > 0) {
result = (result * 0x10000000000000003) >> 64;
}
if (x & 0x2 > 0) {
result = (result * 0x10000000000000001) >> 64;
}
if (x & 0x1 > 0) {
result = (result * 0x10000000000000001) >> 64;
}
}
// In the code snippet below, two operations are executed simultaneously:
//
// 1. The result is multiplied by $(2^n + 1)$, where $2^n$ represents the integer part, and the additional 1
// accounts for the initial guess of 0.5. This is achieved by subtracting from 191 instead of 192.
// 2. The result is then converted to an unsigned 60.18-decimal fixed-point format.
//
// The underlying logic is based on the relationship $2^{191-ip} = 2^{ip} / 2^{191}$, where $ip$ denotes the,
// integer part, $2^n$.
result *= UNIT;
result >>= (191 - (x >> 64));
}
}
/// @notice Finds the zero-based index of the first 1 in the binary representation of x.
///
/// @dev See the note on "msb" in this Wikipedia article: https://en.wikipedia.org/wiki/Find_first_set
///
/// Each step in this implementation is equivalent to this high-level code:
///
/// ```solidity
/// if (x >= 2 ** 128) {
/// x >>= 128;
/// result += 128;
/// }
/// ```
///
/// Where 128 is replaced with each respective power of two factor. See the full high-level implementation here:
/// https://gist.github.com/PaulRBerg/f932f8693f2733e30c4d479e8e980948
///
/// The Yul instructions used below are:
///
/// - "gt" is "greater than"
/// - "or" is the OR bitwise operator
/// - "shl" is "shift left"
/// - "shr" is "shift right"
///
/// @param x The uint256 number for which to find the index of the most significant bit.
/// @return result The index of the most significant bit as a uint256.
/// @custom:smtchecker abstract-function-nondet
function msb(uint256 x) pure returns (uint256 result) {
// 2^128
assembly ("memory-safe") {
let factor := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^64
assembly ("memory-safe") {
let factor := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^32
assembly ("memory-safe") {
let factor := shl(5, gt(x, 0xFFFFFFFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^16
assembly ("memory-safe") {
let factor := shl(4, gt(x, 0xFFFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^8
assembly ("memory-safe") {
let factor := shl(3, gt(x, 0xFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^4
assembly ("memory-safe") {
let factor := shl(2, gt(x, 0xF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^2
assembly ("memory-safe") {
let factor := shl(1, gt(x, 0x3))
x := shr(factor, x)
result := or(result, factor)
}
// 2^1
// No need to shift x any more.
assembly ("memory-safe") {
let factor := gt(x, 0x1)
result := or(result, factor)
}
}
/// @notice Calculates x*y÷denominator with 512-bit precision.
///
/// @dev Credits to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv.
///
/// Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - The denominator must not be zero.
/// - The result must fit in uint256.
///
/// @param x The multiplicand as a uint256.
/// @param y The multiplier as a uint256.
/// @param denominator The divisor as a uint256.
/// @return result The result as a uint256.
/// @custom:smtchecker abstract-function-nondet
function mulDiv(uint256 x, uint256 y, uint256 denominator) pure returns (uint256 result) {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512-bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly ("memory-safe") {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
unchecked {
return prod0 / denominator;
}
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
if (prod1 >= denominator) {
revert PRBMath_MulDiv_Overflow(x, y, denominator);
}
////////////////////////////////////////////////////////////////////////////
// 512 by 256 division
////////////////////////////////////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly ("memory-safe") {
// Compute remainder using the mulmod Yul instruction.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512-bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
unchecked {
// Calculate the largest power of two divisor of the denominator using the unary operator ~. This operation cannot overflow
// because the denominator cannot be zero at this point in the function execution. The result is always >= 1.
// For more detail, see https://cs.stackexchange.com/q/138556/92363.
uint256 lpotdod = denominator & (~denominator + 1);
uint256 flippedLpotdod;
assembly ("memory-safe") {
// Factor powers of two out of denominator.
denominator := div(denominator, lpotdod)
// Divide [prod1 prod0] by lpotdod.
prod0 := div(prod0, lpotdod)
// Get the flipped value `2^256 / lpotdod`. If the `lpotdod` is zero, the flipped value is one.
// `sub(0, lpotdod)` produces the two's complement version of `lpotdod`, which is equivalent to flipping all the bits.
// However, `div` interprets this value as an unsigned value: https://ethereum.stackexchange.com/q/147168/24693
flippedLpotdod := add(div(sub(0, lpotdod), lpotdod), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * flippedLpotdod;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
}
}
/// @notice Calculates x*y÷1e18 with 512-bit precision.
///
/// @dev A variant of {mulDiv} with constant folding, i.e. in which the denominator is hard coded to 1e18.
///
/// Notes:
/// - The body is purposely left uncommented; to understand how this works, see the documentation in {mulDiv}.
/// - The result is rounded toward zero.
/// - We take as an axiom that the result cannot be `MAX_UINT256` when x and y solve the following system of equations:
///
/// $$
/// \begin{cases}
/// x * y = MAX\_UINT256 * UNIT \\
/// (x * y) \% UNIT \geq \frac{UNIT}{2}
/// \end{cases}
/// $$
///
/// Requirements:
/// - Refer to the requirements in {mulDiv}.
/// - The result must fit in uint256.
///
/// @param x The multiplicand as an unsigned 60.18-decimal fixed-point number.
/// @param y The multiplier as an unsigned 60.18-decimal fixed-point number.
/// @return result The result as an unsigned 60.18-decimal fixed-point number.
/// @custom:smtchecker abstract-function-nondet
function mulDiv18(uint256 x, uint256 y) pure returns (uint256 result) {
uint256 prod0;
uint256 prod1;
assembly ("memory-safe") {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
if (prod1 == 0) {
unchecked {
return prod0 / UNIT;
}
}
if (prod1 >= UNIT) {
revert PRBMath_MulDiv18_Overflow(x, y);
}
uint256 remainder;
assembly ("memory-safe") {
remainder := mulmod(x, y, UNIT)
result :=
mul(
or(
div(sub(prod0, remainder), UNIT_LPOTD),
mul(sub(prod1, gt(remainder, prod0)), add(div(sub(0, UNIT_LPOTD), UNIT_LPOTD), 1))
),
UNIT_INVERSE
)
}
}
/// @notice Calculates x*y÷denominator with 512-bit precision.
///
/// @dev This is an extension of {mulDiv} for signed numbers, which works by computing the signs and the absolute values separately.
///
/// Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - Refer to the requirements in {mulDiv}.
/// - None of the inputs can be `type(int256).min`.
/// - The result must fit in int256.
///
/// @param x The multiplicand as an int256.
/// @param y The multiplier as an int256.
/// @param denominator The divisor as an int256.
/// @return result The result as an int256.
/// @custom:smtchecker abstract-function-nondet
function mulDivSigned(int256 x, int256 y, int256 denominator) pure returns (int256 result) {
if (x == type(int256).min || y == type(int256).min || denominator == type(int256).min) {
revert PRBMath_MulDivSigned_InputTooSmall();
}
// Get hold of the absolute values of x, y and the denominator.
uint256 xAbs;
uint256 yAbs;
uint256 dAbs;
unchecked {
xAbs = x < 0 ? uint256(-x) : uint256(x);
yAbs = y < 0 ? uint256(-y) : uint256(y);
dAbs = denominator < 0 ? uint256(-denominator) : uint256(denominator);
}
// Compute the absolute value of x*y÷denominator. The result must fit in int256.
uint256 resultAbs = mulDiv(xAbs, yAbs, dAbs);
if (resultAbs > uint256(type(int256).max)) {
revert PRBMath_MulDivSigned_Overflow(x, y);
}
// Get the signs of x, y and the denominator.
uint256 sx;
uint256 sy;
uint256 sd;
assembly ("memory-safe") {
// "sgt" is the "signed greater than" assembly instruction and "sub(0,1)" is -1 in two's complement.
sx := sgt(x, sub(0, 1))
sy := sgt(y, sub(0, 1))
sd := sgt(denominator, sub(0, 1))
}
// XOR over sx, sy and sd. What this does is to check whether there are 1 or 3 negative signs in the inputs.
// If there are, the result should be negative. Otherwise, it should be positive.
unchecked {
result = sx ^ sy ^ sd == 0 ? -int256(resultAbs) : int256(resultAbs);
}
}
/// @notice Calculates the square root of x using the Babylonian method.
///
/// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
///
/// Notes:
/// - If x is not a perfect square, the result is rounded down.
/// - Credits to OpenZeppelin for the explanations in comments below.
///
/// @param x The uint256 number for which to calculate the square root.
/// @return result The result as a uint256.
/// @custom:smtchecker abstract-function-nondet
function sqrt(uint256 x) pure returns (uint256 result) {
if (x == 0) {
return 0;
}
// For our first guess, we calculate the biggest power of 2 which is smaller than the square root of x.
//
// We know that the "msb" (most significant bit) of x is a power of 2 such that we have:
//
// $$
// msb(x) <= x <= 2*msb(x)$
// $$
//
// We write $msb(x)$ as $2^k$, and we get:
//
// $$
// k = log_2(x)
// $$
//
// Thus, we can write the initial inequality as:
//
// $$
// 2^{log_2(x)} <= x <= 2*2^{log_2(x)+1} \\
// sqrt(2^k) <= sqrt(x) < sqrt(2^{k+1}) \\
// 2^{k/2} <= sqrt(x) < 2^{(k+1)/2} <= 2^{(k/2)+1}
// $$
//
// Consequently, $2^{log_2(x) /2} is a good first approximation of sqrt(x) with at least one correct bit.
uint256 xAux = uint256(x);
result = 1;
if (xAux >= 2 ** 128) {
xAux >>= 128;
result <<= 64;
}
if (xAux >= 2 ** 64) {
xAux >>= 64;
result <<= 32;
}
if (xAux >= 2 ** 32) {
xAux >>= 32;
result <<= 16;
}
if (xAux >= 2 ** 16) {
xAux >>= 16;
result <<= 8;
}
if (xAux >= 2 ** 8) {
xAux >>= 8;
result <<= 4;
}
if (xAux >= 2 ** 4) {
xAux >>= 4;
result <<= 2;
}
if (xAux >= 2 ** 2) {
result <<= 1;
}
// At this point, `result` is an estimation with at least one bit of precision. We know the true value has at
// most 128 bits, since it is the square root of a uint256. Newton's method converges quadratically (precision
// doubles at every iteration). We thus need at most 7 iteration to turn our partial result with one bit of
// precision into the expected uint128 result.
unchecked {
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
// If x is not a perfect square, round the result toward zero.
uint256 roundedResult = x / result;
if (result >= roundedResult) {
result = roundedResult;
}
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { SD1x18 } from "./ValueType.sol";
/// @dev Euler's number as an SD1x18 number.
SD1x18 constant E = SD1x18.wrap(2_718281828459045235);
/// @dev The maximum value an SD1x18 number can have.
int64 constant uMAX_SD1x18 = 9_223372036854775807;
SD1x18 constant MAX_SD1x18 = SD1x18.wrap(uMAX_SD1x18);
/// @dev The maximum value an SD1x18 number can have.
int64 constant uMIN_SD1x18 = -9_223372036854775808;
SD1x18 constant MIN_SD1x18 = SD1x18.wrap(uMIN_SD1x18);
/// @dev PI as an SD1x18 number.
SD1x18 constant PI = SD1x18.wrap(3_141592653589793238);
/// @dev The unit number, which gives the decimal precision of SD1x18.
SD1x18 constant UNIT = SD1x18.wrap(1e18);
int256 constant uUNIT = 1e18;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Casting.sol" as Casting;
/// @notice The signed 1.18-decimal fixed-point number representation, which can have up to 1 digit and up to 18
/// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
/// type int64. This is useful when end users want to use int64 to save gas, e.g. with tight variable packing in contract
/// storage.
type SD1x18 is int64;
/*//////////////////////////////////////////////////////////////////////////
CASTING
//////////////////////////////////////////////////////////////////////////*/
using {
Casting.intoSD59x18,
Casting.intoUD2x18,
Casting.intoUD60x18,
Casting.intoUint256,
Casting.intoUint128,
Casting.intoUint40,
Casting.unwrap
} for SD1x18 global;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Casting.sol" as Casting;
import "./Helpers.sol" as Helpers;
import "./Math.sol" as Math;
/// @notice The signed 59.18-decimal fixed-point number representation, which can have up to 59 digits and up to 18
/// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
/// type int256.
type SD59x18 is int256;
/*//////////////////////////////////////////////////////////////////////////
CASTING
//////////////////////////////////////////////////////////////////////////*/
using {
Casting.intoInt256,
Casting.intoSD1x18,
Casting.intoUD2x18,
Casting.intoUD60x18,
Casting.intoUint256,
Casting.intoUint128,
Casting.intoUint40,
Casting.unwrap
} for SD59x18 global;
/*//////////////////////////////////////////////////////////////////////////
MATHEMATICAL FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
using {
Math.abs,
Math.avg,
Math.ceil,
Math.div,
Math.exp,
Math.exp2,
Math.floor,
Math.frac,
Math.gm,
Math.inv,
Math.log10,
Math.log2,
Math.ln,
Math.mul,
Math.pow,
Math.powu,
Math.sqrt
} for SD59x18 global;
/*//////////////////////////////////////////////////////////////////////////
HELPER FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
using {
Helpers.add,
Helpers.and,
Helpers.eq,
Helpers.gt,
Helpers.gte,
Helpers.isZero,
Helpers.lshift,
Helpers.lt,
Helpers.lte,
Helpers.mod,
Helpers.neq,
Helpers.not,
Helpers.or,
Helpers.rshift,
Helpers.sub,
Helpers.uncheckedAdd,
Helpers.uncheckedSub,
Helpers.uncheckedUnary,
Helpers.xor
} for SD59x18 global;
/*//////////////////////////////////////////////////////////////////////////
OPERATORS
//////////////////////////////////////////////////////////////////////////*/
// The global "using for" directive makes it possible to use these operators on the SD59x18 type.
using {
Helpers.add as +,
Helpers.and2 as &,
Math.div as /,
Helpers.eq as ==,
Helpers.gt as >,
Helpers.gte as >=,
Helpers.lt as <,
Helpers.lte as <=,
Helpers.mod as %,
Math.mul as *,
Helpers.neq as !=,
Helpers.not as ~,
Helpers.or as |,
Helpers.sub as -,
Helpers.unary as -,
Helpers.xor as ^
} for SD59x18 global;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { SD59x18 } from "./ValueType.sol";
// NOTICE: the "u" prefix stands for "unwrapped".
/// @dev Euler's number as an SD59x18 number.
SD59x18 constant E = SD59x18.wrap(2_718281828459045235);
/// @dev The maximum input permitted in {exp}.
int256 constant uEXP_MAX_INPUT = 133_084258667509499440;
SD59x18 constant EXP_MAX_INPUT = SD59x18.wrap(uEXP_MAX_INPUT);
/// @dev The maximum input permitted in {exp2}.
int256 constant uEXP2_MAX_INPUT = 192e18 - 1;
SD59x18 constant EXP2_MAX_INPUT = SD59x18.wrap(uEXP2_MAX_INPUT);
/// @dev Half the UNIT number.
int256 constant uHALF_UNIT = 0.5e18;
SD59x18 constant HALF_UNIT = SD59x18.wrap(uHALF_UNIT);
/// @dev $log_2(10)$ as an SD59x18 number.
int256 constant uLOG2_10 = 3_321928094887362347;
SD59x18 constant LOG2_10 = SD59x18.wrap(uLOG2_10);
/// @dev $log_2(e)$ as an SD59x18 number.
int256 constant uLOG2_E = 1_442695040888963407;
SD59x18 constant LOG2_E = SD59x18.wrap(uLOG2_E);
/// @dev The maximum value an SD59x18 number can have.
int256 constant uMAX_SD59x18 = 57896044618658097711785492504343953926634992332820282019728_792003956564819967;
SD59x18 constant MAX_SD59x18 = SD59x18.wrap(uMAX_SD59x18);
/// @dev The maximum whole value an SD59x18 number can have.
int256 constant uMAX_WHOLE_SD59x18 = 57896044618658097711785492504343953926634992332820282019728_000000000000000000;
SD59x18 constant MAX_WHOLE_SD59x18 = SD59x18.wrap(uMAX_WHOLE_SD59x18);
/// @dev The minimum value an SD59x18 number can have.
int256 constant uMIN_SD59x18 = -57896044618658097711785492504343953926634992332820282019728_792003956564819968;
SD59x18 constant MIN_SD59x18 = SD59x18.wrap(uMIN_SD59x18);
/// @dev The minimum whole value an SD59x18 number can have.
int256 constant uMIN_WHOLE_SD59x18 = -57896044618658097711785492504343953926634992332820282019728_000000000000000000;
SD59x18 constant MIN_WHOLE_SD59x18 = SD59x18.wrap(uMIN_WHOLE_SD59x18);
/// @dev PI as an SD59x18 number.
SD59x18 constant PI = SD59x18.wrap(3_141592653589793238);
/// @dev The unit number, which gives the decimal precision of SD59x18.
int256 constant uUNIT = 1e18;
SD59x18 constant UNIT = SD59x18.wrap(1e18);
/// @dev The unit number squared.
int256 constant uUNIT_SQUARED = 1e36;
SD59x18 constant UNIT_SQUARED = SD59x18.wrap(uUNIT_SQUARED);
/// @dev Zero as an SD59x18 number.
SD59x18 constant ZERO = SD59x18.wrap(0);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "../Common.sol" as Common;
import "./Errors.sol" as CastingErrors;
import { SD59x18 } from "../sd59x18/ValueType.sol";
import { UD2x18 } from "../ud2x18/ValueType.sol";
import { UD60x18 } from "../ud60x18/ValueType.sol";
import { SD1x18 } from "./ValueType.sol";
/// @notice Casts an SD1x18 number into SD59x18.
/// @dev There is no overflow check because the domain of SD1x18 is a subset of SD59x18.
function intoSD59x18(SD1x18 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(int256(SD1x18.unwrap(x)));
}
/// @notice Casts an SD1x18 number into UD2x18.
/// - x must be positive.
function intoUD2x18(SD1x18 x) pure returns (UD2x18 result) {
int64 xInt = SD1x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD1x18_ToUD2x18_Underflow(x);
}
result = UD2x18.wrap(uint64(xInt));
}
/// @notice Casts an SD1x18 number into UD60x18.
/// @dev Requirements:
/// - x must be positive.
function intoUD60x18(SD1x18 x) pure returns (UD60x18 result) {
int64 xInt = SD1x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD1x18_ToUD60x18_Underflow(x);
}
result = UD60x18.wrap(uint64(xInt));
}
/// @notice Casts an SD1x18 number into uint256.
/// @dev Requirements:
/// - x must be positive.
function intoUint256(SD1x18 x) pure returns (uint256 result) {
int64 xInt = SD1x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD1x18_ToUint256_Underflow(x);
}
result = uint256(uint64(xInt));
}
/// @notice Casts an SD1x18 number into uint128.
/// @dev Requirements:
/// - x must be positive.
function intoUint128(SD1x18 x) pure returns (uint128 result) {
int64 xInt = SD1x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD1x18_ToUint128_Underflow(x);
}
result = uint128(uint64(xInt));
}
/// @notice Casts an SD1x18 number into uint40.
/// @dev Requirements:
/// - x must be positive.
/// - x must be less than or equal to `MAX_UINT40`.
function intoUint40(SD1x18 x) pure returns (uint40 result) {
int64 xInt = SD1x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD1x18_ToUint40_Underflow(x);
}
if (xInt > int64(uint64(Common.MAX_UINT40))) {
revert CastingErrors.PRBMath_SD1x18_ToUint40_Overflow(x);
}
result = uint40(uint64(xInt));
}
/// @notice Alias for {wrap}.
function sd1x18(int64 x) pure returns (SD1x18 result) {
result = SD1x18.wrap(x);
}
/// @notice Unwraps an SD1x18 number into int64.
function unwrap(SD1x18 x) pure returns (int64 result) {
result = SD1x18.unwrap(x);
}
/// @notice Wraps an int64 number into SD1x18.
function wrap(int64 x) pure returns (SD1x18 result) {
result = SD1x18.wrap(x);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Errors.sol" as CastingErrors;
import { MAX_UINT128, MAX_UINT40 } from "../Common.sol";
import { uMAX_SD1x18, uMIN_SD1x18 } from "../sd1x18/Constants.sol";
import { SD1x18 } from "../sd1x18/ValueType.sol";
import { uMAX_UD2x18 } from "../ud2x18/Constants.sol";
import { UD2x18 } from "../ud2x18/ValueType.sol";
import { UD60x18 } from "../ud60x18/ValueType.sol";
import { SD59x18 } from "./ValueType.sol";
/// @notice Casts an SD59x18 number into int256.
/// @dev This is basically a functional alias for {unwrap}.
function intoInt256(SD59x18 x) pure returns (int256 result) {
result = SD59x18.unwrap(x);
}
/// @notice Casts an SD59x18 number into SD1x18.
/// @dev Requirements:
/// - x must be greater than or equal to `uMIN_SD1x18`.
/// - x must be less than or equal to `uMAX_SD1x18`.
function intoSD1x18(SD59x18 x) pure returns (SD1x18 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < uMIN_SD1x18) {
revert CastingErrors.PRBMath_SD59x18_IntoSD1x18_Underflow(x);
}
if (xInt > uMAX_SD1x18) {
revert CastingErrors.PRBMath_SD59x18_IntoSD1x18_Overflow(x);
}
result = SD1x18.wrap(int64(xInt));
}
/// @notice Casts an SD59x18 number into UD2x18.
/// @dev Requirements:
/// - x must be positive.
/// - x must be less than or equal to `uMAX_UD2x18`.
function intoUD2x18(SD59x18 x) pure returns (UD2x18 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUD2x18_Underflow(x);
}
if (xInt > int256(uint256(uMAX_UD2x18))) {
revert CastingErrors.PRBMath_SD59x18_IntoUD2x18_Overflow(x);
}
result = UD2x18.wrap(uint64(uint256(xInt)));
}
/// @notice Casts an SD59x18 number into UD60x18.
/// @dev Requirements:
/// - x must be positive.
function intoUD60x18(SD59x18 x) pure returns (UD60x18 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUD60x18_Underflow(x);
}
result = UD60x18.wrap(uint256(xInt));
}
/// @notice Casts an SD59x18 number into uint256.
/// @dev Requirements:
/// - x must be positive.
function intoUint256(SD59x18 x) pure returns (uint256 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUint256_Underflow(x);
}
result = uint256(xInt);
}
/// @notice Casts an SD59x18 number into uint128.
/// @dev Requirements:
/// - x must be positive.
/// - x must be less than or equal to `uMAX_UINT128`.
function intoUint128(SD59x18 x) pure returns (uint128 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUint128_Underflow(x);
}
if (xInt > int256(uint256(MAX_UINT128))) {
revert CastingErrors.PRBMath_SD59x18_IntoUint128_Overflow(x);
}
result = uint128(uint256(xInt));
}
/// @notice Casts an SD59x18 number into uint40.
/// @dev Requirements:
/// - x must be positive.
/// - x must be less than or equal to `MAX_UINT40`.
function intoUint40(SD59x18 x) pure returns (uint40 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUint40_Underflow(x);
}
if (xInt > int256(uint256(MAX_UINT40))) {
revert CastingErrors.PRBMath_SD59x18_IntoUint40_Overflow(x);
}
result = uint40(uint256(xInt));
}
/// @notice Alias for {wrap}.
function sd(int256 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(x);
}
/// @notice Alias for {wrap}.
function sd59x18(int256 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(x);
}
/// @notice Unwraps an SD59x18 number into int256.
function unwrap(SD59x18 x) pure returns (int256 result) {
result = SD59x18.unwrap(x);
}
/// @notice Wraps an int256 number into SD59x18.
function wrap(int256 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(x);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { wrap } from "./Casting.sol";
import { SD59x18 } from "./ValueType.sol";
/// @notice Implements the checked addition operation (+) in the SD59x18 type.
function add(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
return wrap(x.unwrap() + y.unwrap());
}
/// @notice Implements the AND (&) bitwise operation in the SD59x18 type.
function and(SD59x18 x, int256 bits) pure returns (SD59x18 result) {
return wrap(x.unwrap() & bits);
}
/// @notice Implements the AND (&) bitwise operation in the SD59x18 type.
function and2(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
return wrap(x.unwrap() & y.unwrap());
}
/// @notice Implements the equal (=) operation in the SD59x18 type.
function eq(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() == y.unwrap();
}
/// @notice Implements the greater than operation (>) in the SD59x18 type.
function gt(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() > y.unwrap();
}
/// @notice Implements the greater than or equal to operation (>=) in the SD59x18 type.
function gte(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() >= y.unwrap();
}
/// @notice Implements a zero comparison check function in the SD59x18 type.
function isZero(SD59x18 x) pure returns (bool result) {
result = x.unwrap() == 0;
}
/// @notice Implements the left shift operation (<<) in the SD59x18 type.
function lshift(SD59x18 x, uint256 bits) pure returns (SD59x18 result) {
result = wrap(x.unwrap() << bits);
}
/// @notice Implements the lower than operation (<) in the SD59x18 type.
function lt(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() < y.unwrap();
}
/// @notice Implements the lower than or equal to operation (<=) in the SD59x18 type.
function lte(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() <= y.unwrap();
}
/// @notice Implements the unchecked modulo operation (%) in the SD59x18 type.
function mod(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
result = wrap(x.unwrap() % y.unwrap());
}
/// @notice Implements the not equal operation (!=) in the SD59x18 type.
function neq(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() != y.unwrap();
}
/// @notice Implements the NOT (~) bitwise operation in the SD59x18 type.
function not(SD59x18 x) pure returns (SD59x18 result) {
result = wrap(~x.unwrap());
}
/// @notice Implements the OR (|) bitwise operation in the SD59x18 type.
function or(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
result = wrap(x.unwrap() | y.unwrap());
}
/// @notice Implements the right shift operation (>>) in the SD59x18 type.
function rshift(SD59x18 x, uint256 bits) pure returns (SD59x18 result) {
result = wrap(x.unwrap() >> bits);
}
/// @notice Implements the checked subtraction operation (-) in the SD59x18 type.
function sub(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
result = wrap(x.unwrap() - y.unwrap());
}
/// @notice Implements the checked unary minus operation (-) in the SD59x18 type.
function unary(SD59x18 x) pure returns (SD59x18 result) {
result = wrap(-x.unwrap());
}
/// @notice Implements the unchecked addition operation (+) in the SD59x18 type.
function uncheckedAdd(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
unchecked {
result = wrap(x.unwrap() + y.unwrap());
}
}
/// @notice Implements the unchecked subtraction operation (-) in the SD59x18 type.
function uncheckedSub(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
unchecked {
result = wrap(x.unwrap() - y.unwrap());
}
}
/// @notice Implements the unchecked unary minus operation (-) in the SD59x18 type.
function uncheckedUnary(SD59x18 x) pure returns (SD59x18 result) {
unchecked {
result = wrap(-x.unwrap());
}
}
/// @notice Implements the XOR (^) bitwise operation in the SD59x18 type.
function xor(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
result = wrap(x.unwrap() ^ y.unwrap());
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "../Common.sol" as Common;
import "./Errors.sol" as Errors;
import {
uEXP_MAX_INPUT,
uEXP2_MAX_INPUT,
uHALF_UNIT,
uLOG2_10,
uLOG2_E,
uMAX_SD59x18,
uMAX_WHOLE_SD59x18,
uMIN_SD59x18,
uMIN_WHOLE_SD59x18,
UNIT,
uUNIT,
uUNIT_SQUARED,
ZERO
} from "./Constants.sol";
import { wrap } from "./Helpers.sol";
import { SD59x18 } from "./ValueType.sol";
/// @notice Calculates the absolute value of x.
///
/// @dev Requirements:
/// - x must be greater than `MIN_SD59x18`.
///
/// @param x The SD59x18 number for which to calculate the absolute value.
/// @param result The absolute value of x as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function abs(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt == uMIN_SD59x18) {
revert Errors.PRBMath_SD59x18_Abs_MinSD59x18();
}
result = xInt < 0 ? wrap(-xInt) : x;
}
/// @notice Calculates the arithmetic average of x and y.
///
/// @dev Notes:
/// - The result is rounded toward zero.
///
/// @param x The first operand as an SD59x18 number.
/// @param y The second operand as an SD59x18 number.
/// @return result The arithmetic average as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function avg(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
int256 yInt = y.unwrap();
unchecked {
// This operation is equivalent to `x / 2 + y / 2`, and it can never overflow.
int256 sum = (xInt >> 1) + (yInt >> 1);
if (sum < 0) {
// If at least one of x and y is odd, add 1 to the result, because shifting negative numbers to the right
// rounds toward negative infinity. The right part is equivalent to `sum + (x % 2 == 1 || y % 2 == 1)`.
assembly ("memory-safe") {
result := add(sum, and(or(xInt, yInt), 1))
}
} else {
// Add 1 if both x and y are odd to account for the double 0.5 remainder truncated after shifting.
result = wrap(sum + (xInt & yInt & 1));
}
}
}
/// @notice Yields the smallest whole number greater than or equal to x.
///
/// @dev Optimized for fractional value inputs, because every whole value has (1e18 - 1) fractional counterparts.
/// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
///
/// Requirements:
/// - x must be less than or equal to `MAX_WHOLE_SD59x18`.
///
/// @param x The SD59x18 number to ceil.
/// @param result The smallest whole number greater than or equal to x, as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function ceil(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt > uMAX_WHOLE_SD59x18) {
revert Errors.PRBMath_SD59x18_Ceil_Overflow(x);
}
int256 remainder = xInt % uUNIT;
if (remainder == 0) {
result = x;
} else {
unchecked {
// Solidity uses C fmod style, which returns a modulus with the same sign as x.
int256 resultInt = xInt - remainder;
if (xInt > 0) {
resultInt += uUNIT;
}
result = wrap(resultInt);
}
}
}
/// @notice Divides two SD59x18 numbers, returning a new SD59x18 number.
///
/// @dev This is an extension of {Common.mulDiv} for signed numbers, which works by computing the signs and the absolute
/// values separately.
///
/// Notes:
/// - Refer to the notes in {Common.mulDiv}.
/// - The result is rounded toward zero.
///
/// Requirements:
/// - Refer to the requirements in {Common.mulDiv}.
/// - None of the inputs can be `MIN_SD59x18`.
/// - The denominator must not be zero.
/// - The result must fit in SD59x18.
///
/// @param x The numerator as an SD59x18 number.
/// @param y The denominator as an SD59x18 number.
/// @param result The quotient as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function div(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
int256 yInt = y.unwrap();
if (xInt == uMIN_SD59x18 || yInt == uMIN_SD59x18) {
revert Errors.PRBMath_SD59x18_Div_InputTooSmall();
}
// Get hold of the absolute values of x and y.
uint256 xAbs;
uint256 yAbs;
unchecked {
xAbs = xInt < 0 ? uint256(-xInt) : uint256(xInt);
yAbs = yInt < 0 ? uint256(-yInt) : uint256(yInt);
}
// Compute the absolute value (x*UNIT÷y). The resulting value must fit in SD59x18.
uint256 resultAbs = Common.mulDiv(xAbs, uint256(uUNIT), yAbs);
if (resultAbs > uint256(uMAX_SD59x18)) {
revert Errors.PRBMath_SD59x18_Div_Overflow(x, y);
}
// Check if x and y have the same sign using two's complement representation. The left-most bit represents the sign (1 for
// negative, 0 for positive or zero).
bool sameSign = (xInt ^ yInt) > -1;
// If the inputs have the same sign, the result should be positive. Otherwise, it should be negative.
unchecked {
result = wrap(sameSign ? int256(resultAbs) : -int256(resultAbs));
}
}
/// @notice Calculates the natural exponent of x using the following formula:
///
/// $$
/// e^x = 2^{x * log_2{e}}
/// $$
///
/// @dev Notes:
/// - Refer to the notes in {exp2}.
///
/// Requirements:
/// - Refer to the requirements in {exp2}.
/// - x must be less than 133_084258667509499441.
///
/// @param x The exponent as an SD59x18 number.
/// @return result The result as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function exp(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
// This check prevents values greater than 192e18 from being passed to {exp2}.
if (xInt > uEXP_MAX_INPUT) {
revert Errors.PRBMath_SD59x18_Exp_InputTooBig(x);
}
unchecked {
// Inline the fixed-point multiplication to save gas.
int256 doubleUnitProduct = xInt * uLOG2_E;
result = exp2(wrap(doubleUnitProduct / uUNIT));
}
}
/// @notice Calculates the binary exponent of x using the binary fraction method using the following formula:
///
/// $$
/// 2^{-x} = \frac{1}{2^x}
/// $$
///
/// @dev See https://ethereum.stackexchange.com/q/79903/24693.
///
/// Notes:
/// - If x is less than -59_794705707972522261, the result is zero.
///
/// Requirements:
/// - x must be less than 192e18.
/// - The result must fit in SD59x18.
///
/// @param x The exponent as an SD59x18 number.
/// @return result The result as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function exp2(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt < 0) {
// The inverse of any number less than this is truncated to zero.
if (xInt < -59_794705707972522261) {
return ZERO;
}
unchecked {
// Inline the fixed-point inversion to save gas.
result = wrap(uUNIT_SQUARED / exp2(wrap(-xInt)).unwrap());
}
} else {
// Numbers greater than or equal to 192e18 don't fit in the 192.64-bit format.
if (xInt > uEXP2_MAX_INPUT) {
revert Errors.PRBMath_SD59x18_Exp2_InputTooBig(x);
}
unchecked {
// Convert x to the 192.64-bit fixed-point format.
uint256 x_192x64 = uint256((xInt << 64) / uUNIT);
// It is safe to cast the result to int256 due to the checks above.
result = wrap(int256(Common.exp2(x_192x64)));
}
}
}
/// @notice Yields the greatest whole number less than or equal to x.
///
/// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional
/// counterparts. See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
///
/// Requirements:
/// - x must be greater than or equal to `MIN_WHOLE_SD59x18`.
///
/// @param x The SD59x18 number to floor.
/// @param result The greatest whole number less than or equal to x, as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function floor(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt < uMIN_WHOLE_SD59x18) {
revert Errors.PRBMath_SD59x18_Floor_Underflow(x);
}
int256 remainder = xInt % uUNIT;
if (remainder == 0) {
result = x;
} else {
unchecked {
// Solidity uses C fmod style, which returns a modulus with the same sign as x.
int256 resultInt = xInt - remainder;
if (xInt < 0) {
resultInt -= uUNIT;
}
result = wrap(resultInt);
}
}
}
/// @notice Yields the excess beyond the floor of x for positive numbers and the part of the number to the right.
/// of the radix point for negative numbers.
/// @dev Based on the odd function definition. https://en.wikipedia.org/wiki/Fractional_part
/// @param x The SD59x18 number to get the fractional part of.
/// @param result The fractional part of x as an SD59x18 number.
function frac(SD59x18 x) pure returns (SD59x18 result) {
result = wrap(x.unwrap() % uUNIT);
}
/// @notice Calculates the geometric mean of x and y, i.e. $\sqrt{x * y}$.
///
/// @dev Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - x * y must fit in SD59x18.
/// - x * y must not be negative, since complex numbers are not supported.
///
/// @param x The first operand as an SD59x18 number.
/// @param y The second operand as an SD59x18 number.
/// @return result The result as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function gm(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
int256 yInt = y.unwrap();
if (xInt == 0 || yInt == 0) {
return ZERO;
}
unchecked {
// Equivalent to `xy / x != y`. Checking for overflow this way is faster than letting Solidity do it.
int256 xyInt = xInt * yInt;
if (xyInt / xInt != yInt) {
revert Errors.PRBMath_SD59x18_Gm_Overflow(x, y);
}
// The product must not be negative, since complex numbers are not supported.
if (xyInt < 0) {
revert Errors.PRBMath_SD59x18_Gm_NegativeProduct(x, y);
}
// We don't need to multiply the result by `UNIT` here because the x*y product picked up a factor of `UNIT`
// during multiplication. See the comments in {Common.sqrt}.
uint256 resultUint = Common.sqrt(uint256(xyInt));
result = wrap(int256(resultUint));
}
}
/// @notice Calculates the inverse of x.
///
/// @dev Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - x must not be zero.
///
/// @param x The SD59x18 number for which to calculate the inverse.
/// @return result The inverse as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function inv(SD59x18 x) pure returns (SD59x18 result) {
result = wrap(uUNIT_SQUARED / x.unwrap());
}
/// @notice Calculates the natural logarithm of x using the following formula:
///
/// $$
/// ln{x} = log_2{x} / log_2{e}
/// $$
///
/// @dev Notes:
/// - Refer to the notes in {log2}.
/// - The precision isn't sufficiently fine-grained to return exactly `UNIT` when the input is `E`.
///
/// Requirements:
/// - Refer to the requirements in {log2}.
///
/// @param x The SD59x18 number for which to calculate the natural logarithm.
/// @return result The natural logarithm as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function ln(SD59x18 x) pure returns (SD59x18 result) {
// Inline the fixed-point multiplication to save gas. This is overflow-safe because the maximum value that
// {log2} can return is ~195_205294292027477728.
result = wrap(log2(x).unwrap() * uUNIT / uLOG2_E);
}
/// @notice Calculates the common logarithm of x using the following formula:
///
/// $$
/// log_{10}{x} = log_2{x} / log_2{10}
/// $$
///
/// However, if x is an exact power of ten, a hard coded value is returned.
///
/// @dev Notes:
/// - Refer to the notes in {log2}.
///
/// Requirements:
/// - Refer to the requirements in {log2}.
///
/// @param x The SD59x18 number for which to calculate the common logarithm.
/// @return result The common logarithm as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function log10(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt < 0) {
revert Errors.PRBMath_SD59x18_Log_InputTooSmall(x);
}
// Note that the `mul` in this block is the standard multiplication operation, not {SD59x18.mul}.
// prettier-ignore
assembly ("memory-safe") {
switch x
case 1 { result := mul(uUNIT, sub(0, 18)) }
case 10 { result := mul(uUNIT, sub(1, 18)) }
case 100 { result := mul(uUNIT, sub(2, 18)) }
case 1000 { result := mul(uUNIT, sub(3, 18)) }
case 10000 { result := mul(uUNIT, sub(4, 18)) }
case 100000 { result := mul(uUNIT, sub(5, 18)) }
case 1000000 { result := mul(uUNIT, sub(6, 18)) }
case 10000000 { result := mul(uUNIT, sub(7, 18)) }
case 100000000 { result := mul(uUNIT, sub(8, 18)) }
case 1000000000 { result := mul(uUNIT, sub(9, 18)) }
case 10000000000 { result := mul(uUNIT, sub(10, 18)) }
case 100000000000 { result := mul(uUNIT, sub(11, 18)) }
case 1000000000000 { result := mul(uUNIT, sub(12, 18)) }
case 10000000000000 { result := mul(uUNIT, sub(13, 18)) }
case 100000000000000 { result := mul(uUNIT, sub(14, 18)) }
case 1000000000000000 { result := mul(uUNIT, sub(15, 18)) }
case 10000000000000000 { result := mul(uUNIT, sub(16, 18)) }
case 100000000000000000 { result := mul(uUNIT, sub(17, 18)) }
case 1000000000000000000 { result := 0 }
case 10000000000000000000 { result := uUNIT }
case 100000000000000000000 { result := mul(uUNIT, 2) }
case 1000000000000000000000 { result := mul(uUNIT, 3) }
case 10000000000000000000000 { result := mul(uUNIT, 4) }
case 100000000000000000000000 { result := mul(uUNIT, 5) }
case 1000000000000000000000000 { result := mul(uUNIT, 6) }
case 10000000000000000000000000 { result := mul(uUNIT, 7) }
case 100000000000000000000000000 { result := mul(uUNIT, 8) }
case 1000000000000000000000000000 { result := mul(uUNIT, 9) }
case 10000000000000000000000000000 { result := mul(uUNIT, 10) }
case 100000000000000000000000000000 { result := mul(uUNIT, 11) }
case 1000000000000000000000000000000 { result := mul(uUNIT, 12) }
case 10000000000000000000000000000000 { result := mul(uUNIT, 13) }
case 100000000000000000000000000000000 { result := mul(uUNIT, 14) }
case 1000000000000000000000000000000000 { result := mul(uUNIT, 15) }
case 10000000000000000000000000000000000 { result := mul(uUNIT, 16) }
case 100000000000000000000000000000000000 { result := mul(uUNIT, 17) }
case 1000000000000000000000000000000000000 { result := mul(uUNIT, 18) }
case 10000000000000000000000000000000000000 { result := mul(uUNIT, 19) }
case 100000000000000000000000000000000000000 { result := mul(uUNIT, 20) }
case 1000000000000000000000000000000000000000 { result := mul(uUNIT, 21) }
case 10000000000000000000000000000000000000000 { result := mul(uUNIT, 22) }
case 100000000000000000000000000000000000000000 { result := mul(uUNIT, 23) }
case 1000000000000000000000000000000000000000000 { result := mul(uUNIT, 24) }
case 10000000000000000000000000000000000000000000 { result := mul(uUNIT, 25) }
case 100000000000000000000000000000000000000000000 { result := mul(uUNIT, 26) }
case 1000000000000000000000000000000000000000000000 { result := mul(uUNIT, 27) }
case 10000000000000000000000000000000000000000000000 { result := mul(uUNIT, 28) }
case 100000000000000000000000000000000000000000000000 { result := mul(uUNIT, 29) }
case 1000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 30) }
case 10000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 31) }
case 100000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 32) }
case 1000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 33) }
case 10000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 34) }
case 100000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 35) }
case 1000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 36) }
case 10000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 37) }
case 100000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 38) }
case 1000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 39) }
case 10000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 40) }
case 100000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 41) }
case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 42) }
case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 43) }
case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 44) }
case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 45) }
case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 46) }
case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 47) }
case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 48) }
case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 49) }
case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 50) }
case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 51) }
case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 52) }
case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 53) }
case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 54) }
case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 55) }
case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 56) }
case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 57) }
case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 58) }
default { result := uMAX_SD59x18 }
}
if (result.unwrap() == uMAX_SD59x18) {
unchecked {
// Inline the fixed-point division to save gas.
result = wrap(log2(x).unwrap() * uUNIT / uLOG2_10);
}
}
}
/// @notice Calculates the binary logarithm of x using the iterative approximation algorithm:
///
/// $$
/// log_2{x} = n + log_2{y}, \text{ where } y = x*2^{-n}, \ y \in [1, 2)
/// $$
///
/// For $0 \leq x \lt 1$, the input is inverted:
///
/// $$
/// log_2{x} = -log_2{\frac{1}{x}}
/// $$
///
/// @dev See https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation.
///
/// Notes:
/// - Due to the lossy precision of the iterative approximation, the results are not perfectly accurate to the last decimal.
///
/// Requirements:
/// - x must be greater than zero.
///
/// @param x The SD59x18 number for which to calculate the binary logarithm.
/// @return result The binary logarithm as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function log2(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt <= 0) {
revert Errors.PRBMath_SD59x18_Log_InputTooSmall(x);
}
unchecked {
int256 sign;
if (xInt >= uUNIT) {
sign = 1;
} else {
sign = -1;
// Inline the fixed-point inversion to save gas.
xInt = uUNIT_SQUARED / xInt;
}
// Calculate the integer part of the logarithm.
uint256 n = Common.msb(uint256(xInt / uUNIT));
// This is the integer part of the logarithm as an SD59x18 number. The operation can't overflow
// because n is at most 255, `UNIT` is 1e18, and the sign is either 1 or -1.
int256 resultInt = int256(n) * uUNIT;
// Calculate $y = x * 2^{-n}$.
int256 y = xInt >> n;
// If y is the unit number, the fractional part is zero.
if (y == uUNIT) {
return wrap(resultInt * sign);
}
// Calculate the fractional part via the iterative approximation.
// The `delta >>= 1` part is equivalent to `delta /= 2`, but shifting bits is more gas efficient.
int256 DOUBLE_UNIT = 2e18;
for (int256 delta = uHALF_UNIT; delta > 0; delta >>= 1) {
y = (y * y) / uUNIT;
// Is y^2 >= 2e18 and so in the range [2e18, 4e18)?
if (y >= DOUBLE_UNIT) {
// Add the 2^{-m} factor to the logarithm.
resultInt = resultInt + delta;
// Halve y, which corresponds to z/2 in the Wikipedia article.
y >>= 1;
}
}
resultInt *= sign;
result = wrap(resultInt);
}
}
/// @notice Multiplies two SD59x18 numbers together, returning a new SD59x18 number.
///
/// @dev Notes:
/// - Refer to the notes in {Common.mulDiv18}.
///
/// Requirements:
/// - Refer to the requirements in {Common.mulDiv18}.
/// - None of the inputs can be `MIN_SD59x18`.
/// - The result must fit in SD59x18.
///
/// @param x The multiplicand as an SD59x18 number.
/// @param y The multiplier as an SD59x18 number.
/// @return result The product as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function mul(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
int256 yInt = y.unwrap();
if (xInt == uMIN_SD59x18 || yInt == uMIN_SD59x18) {
revert Errors.PRBMath_SD59x18_Mul_InputTooSmall();
}
// Get hold of the absolute values of x and y.
uint256 xAbs;
uint256 yAbs;
unchecked {
xAbs = xInt < 0 ? uint256(-xInt) : uint256(xInt);
yAbs = yInt < 0 ? uint256(-yInt) : uint256(yInt);
}
// Compute the absolute value (x*y÷UNIT). The resulting value must fit in SD59x18.
uint256 resultAbs = Common.mulDiv18(xAbs, yAbs);
if (resultAbs > uint256(uMAX_SD59x18)) {
revert Errors.PRBMath_SD59x18_Mul_Overflow(x, y);
}
// Check if x and y have the same sign using two's complement representation. The left-most bit represents the sign (1 for
// negative, 0 for positive or zero).
bool sameSign = (xInt ^ yInt) > -1;
// If the inputs have the same sign, the result should be positive. Otherwise, it should be negative.
unchecked {
result = wrap(sameSign ? int256(resultAbs) : -int256(resultAbs));
}
}
/// @notice Raises x to the power of y using the following formula:
///
/// $$
/// x^y = 2^{log_2{x} * y}
/// $$
///
/// @dev Notes:
/// - Refer to the notes in {exp2}, {log2}, and {mul}.
/// - Returns `UNIT` for 0^0.
///
/// Requirements:
/// - Refer to the requirements in {exp2}, {log2}, and {mul}.
///
/// @param x The base as an SD59x18 number.
/// @param y Exponent to raise x to, as an SD59x18 number
/// @return result x raised to power y, as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function pow(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
int256 yInt = y.unwrap();
// If both x and y are zero, the result is `UNIT`. If just x is zero, the result is always zero.
if (xInt == 0) {
return yInt == 0 ? UNIT : ZERO;
}
// If x is `UNIT`, the result is always `UNIT`.
else if (xInt == uUNIT) {
return UNIT;
}
// If y is zero, the result is always `UNIT`.
if (yInt == 0) {
return UNIT;
}
// If y is `UNIT`, the result is always x.
else if (yInt == uUNIT) {
return x;
}
// Calculate the result using the formula.
result = exp2(mul(log2(x), y));
}
/// @notice Raises x (an SD59x18 number) to the power y (an unsigned basic integer) using the well-known
/// algorithm "exponentiation by squaring".
///
/// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring.
///
/// Notes:
/// - Refer to the notes in {Common.mulDiv18}.
/// - Returns `UNIT` for 0^0.
///
/// Requirements:
/// - Refer to the requirements in {abs} and {Common.mulDiv18}.
/// - The result must fit in SD59x18.
///
/// @param x The base as an SD59x18 number.
/// @param y The exponent as a uint256.
/// @return result The result as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function powu(SD59x18 x, uint256 y) pure returns (SD59x18 result) {
uint256 xAbs = uint256(abs(x).unwrap());
// Calculate the first iteration of the loop in advance.
uint256 resultAbs = y & 1 > 0 ? xAbs : uint256(uUNIT);
// Equivalent to `for(y /= 2; y > 0; y /= 2)`.
uint256 yAux = y;
for (yAux >>= 1; yAux > 0; yAux >>= 1) {
xAbs = Common.mulDiv18(xAbs, xAbs);
// Equivalent to `y % 2 == 1`.
if (yAux & 1 > 0) {
resultAbs = Common.mulDiv18(resultAbs, xAbs);
}
}
// The result must fit in SD59x18.
if (resultAbs > uint256(uMAX_SD59x18)) {
revert Errors.PRBMath_SD59x18_Powu_Overflow(x, y);
}
unchecked {
// Is the base negative and the exponent odd? If yes, the result should be negative.
int256 resultInt = int256(resultAbs);
bool isNegative = x.unwrap() < 0 && y & 1 == 1;
if (isNegative) {
resultInt = -resultInt;
}
result = wrap(resultInt);
}
}
/// @notice Calculates the square root of x using the Babylonian method.
///
/// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
///
/// Notes:
/// - Only the positive root is returned.
/// - The result is rounded toward zero.
///
/// Requirements:
/// - x cannot be negative, since complex numbers are not supported.
/// - x must be less than `MAX_SD59x18 / UNIT`.
///
/// @param x The SD59x18 number for which to calculate the square root.
/// @return result The result as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function sqrt(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt < 0) {
revert Errors.PRBMath_SD59x18_Sqrt_NegativeInput(x);
}
if (xInt > uMAX_SD59x18 / uUNIT) {
revert Errors.PRBMath_SD59x18_Sqrt_Overflow(x);
}
unchecked {
// Multiply x by `UNIT` to account for the factor of `UNIT` picked up when multiplying two SD59x18 numbers.
// In this case, the two numbers are both the square root.
uint256 resultUint = Common.sqrt(uint256(xInt * uUNIT));
result = wrap(int256(resultUint));
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { SD1x18 } from "./ValueType.sol";
/// @notice Thrown when trying to cast a SD1x18 number that doesn't fit in UD2x18.
error PRBMath_SD1x18_ToUD2x18_Underflow(SD1x18 x);
/// @notice Thrown when trying to cast a SD1x18 number that doesn't fit in UD60x18.
error PRBMath_SD1x18_ToUD60x18_Underflow(SD1x18 x);
/// @notice Thrown when trying to cast a SD1x18 number that doesn't fit in uint128.
error PRBMath_SD1x18_ToUint128_Underflow(SD1x18 x);
/// @notice Thrown when trying to cast a SD1x18 number that doesn't fit in uint256.
error PRBMath_SD1x18_ToUint256_Underflow(SD1x18 x);
/// @notice Thrown when trying to cast a SD1x18 number that doesn't fit in uint40.
error PRBMath_SD1x18_ToUint40_Overflow(SD1x18 x);
/// @notice Thrown when trying to cast a SD1x18 number that doesn't fit in uint40.
error PRBMath_SD1x18_ToUint40_Underflow(SD1x18 x);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { SD59x18 } from "./ValueType.sol";
/// @notice Thrown when taking the absolute value of `MIN_SD59x18`.
error PRBMath_SD59x18_Abs_MinSD59x18();
/// @notice Thrown when ceiling a number overflows SD59x18.
error PRBMath_SD59x18_Ceil_Overflow(SD59x18 x);
/// @notice Thrown when converting a basic integer to the fixed-point format overflows SD59x18.
error PRBMath_SD59x18_Convert_Overflow(int256 x);
/// @notice Thrown when converting a basic integer to the fixed-point format underflows SD59x18.
error PRBMath_SD59x18_Convert_Underflow(int256 x);
/// @notice Thrown when dividing two numbers and one of them is `MIN_SD59x18`.
error PRBMath_SD59x18_Div_InputTooSmall();
/// @notice Thrown when dividing two numbers and one of the intermediary unsigned results overflows SD59x18.
error PRBMath_SD59x18_Div_Overflow(SD59x18 x, SD59x18 y);
/// @notice Thrown when taking the natural exponent of a base greater than 133_084258667509499441.
error PRBMath_SD59x18_Exp_InputTooBig(SD59x18 x);
/// @notice Thrown when taking the binary exponent of a base greater than 192e18.
error PRBMath_SD59x18_Exp2_InputTooBig(SD59x18 x);
/// @notice Thrown when flooring a number underflows SD59x18.
error PRBMath_SD59x18_Floor_Underflow(SD59x18 x);
/// @notice Thrown when taking the geometric mean of two numbers and their product is negative.
error PRBMath_SD59x18_Gm_NegativeProduct(SD59x18 x, SD59x18 y);
/// @notice Thrown when taking the geometric mean of two numbers and multiplying them overflows SD59x18.
error PRBMath_SD59x18_Gm_Overflow(SD59x18 x, SD59x18 y);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD1x18.
error PRBMath_SD59x18_IntoSD1x18_Overflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD1x18.
error PRBMath_SD59x18_IntoSD1x18_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in UD2x18.
error PRBMath_SD59x18_IntoUD2x18_Overflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in UD2x18.
error PRBMath_SD59x18_IntoUD2x18_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in UD60x18.
error PRBMath_SD59x18_IntoUD60x18_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint128.
error PRBMath_SD59x18_IntoUint128_Overflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint128.
error PRBMath_SD59x18_IntoUint128_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint256.
error PRBMath_SD59x18_IntoUint256_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint40.
error PRBMath_SD59x18_IntoUint40_Overflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint40.
error PRBMath_SD59x18_IntoUint40_Underflow(SD59x18 x);
/// @notice Thrown when taking the logarithm of a number less than or equal to zero.
error PRBMath_SD59x18_Log_InputTooSmall(SD59x18 x);
/// @notice Thrown when multiplying two numbers and one of the inputs is `MIN_SD59x18`.
error PRBMath_SD59x18_Mul_InputTooSmall();
/// @notice Thrown when multiplying two numbers and the intermediary absolute result overflows SD59x18.
error PRBMath_SD59x18_Mul_Overflow(SD59x18 x, SD59x18 y);
/// @notice Thrown when raising a number to a power and hte intermediary absolute result overflows SD59x18.
error PRBMath_SD59x18_Powu_Overflow(SD59x18 x, uint256 y);
/// @notice Thrown when taking the square root of a negative number.
error PRBMath_SD59x18_Sqrt_NegativeInput(SD59x18 x);
/// @notice Thrown when the calculating the square root overflows SD59x18.
error PRBMath_SD59x18_Sqrt_Overflow(SD59x18 x);{
"remappings": [
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@prb/math/=lib/prb-math/src/",
"@prb/test/=lib/prb-test/src/",
"ds-test/=lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"openzeppelin/=lib/openzeppelin-contracts/contracts/",
"prb-math/=lib/prb-math/src/",
"prb-test/=lib/prb-test/src/",
"solady/=lib/solady/src/",
"solarray/=lib/solarray/src/"
],
"optimizer": {
"enabled": true,
"runs": 1000
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "none",
"appendCBOR": false
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "paris",
"viaIR": true,
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"contract IERC721Metadata","name":"nft","type":"address"},{"internalType":"string","name":"symbol","type":"string"}],"name":"SablierV2NFTDescriptor_UnknownNFT","type":"error"},{"inputs":[{"internalType":"contract IERC721Metadata","name":"sablier","type":"address"},{"internalType":"uint256","name":"streamId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"uri","type":"string"}],"stateMutability":"view","type":"function"}]Contract Creation Code
6080806040523461001757615da890816200001d8239f35b600080fdfe6080604052600436101561001257600080fd5b60003560e01c63e9dc63751461002757600080fd5b346142f35760403660031901126142f3576001600160a01b0360043516600435036142f357610056608061486b565b60006080819052606060a081905260c0819052610100819052610120819052610140819052610160829052610180919091526101a0526004356001600160a01b031660e08190526100a690614c55565b6101005260e0516040517feac8f5b80000000000000000000000000000000000000000000000000000000081526024803560048301529091602091839182906001600160a01b03165afa908115614300576000916147da575b506001600160a01b03610116911680608052615665565b60a05260e0516040517fad35efd40000000000000000000000000000000000000000000000000000000081526024803560048301529091602091839182906001600160a01b03165afa80156143005760009061479d575b6101779150615885565b6101205260e0516040517f4869e12d0000000000000000000000000000000000000000000000000000000081526024803560048301529091602091839182906001600160a01b03165afa80156143005760249160009161477e575b506fffffffffffffffffffffffffffffffff81166101605260e0516040517fa80fc071000000000000000000000000000000000000000000000000000000008152833560048201529260209184919082906001600160a01b03165afa9182156143005760009261474d575b506fffffffffffffffffffffffffffffffff821615614737576fffffffffffffffffffffffffffffffff9182169082166127100282160416610180526102846004356153c3565b610120608001526040514660208201526bffffffffffffffffffffffff1960043560601b16604082015260243560548201526054815280608081011067ffffffffffffffff60808301111761430c57608081016040526020815191012061041b602963ffffffff61032b6103048261016861ffff8860101c160616614b05565b91601e604660ff6103218460146050848d60081c16060116614b05565b9816060116614b05565b6040519485927f68736c2800000000000000000000000000000000000000000000000000000000602085015261036b815180926020602488019101614823565b83017f2c0000000000000000000000000000000000000000000000000000000000000060248201526103a7825180936020602585019101614823565b7f252c000000000000000000000000000000000000000000000000000000000000602583830101526103e58351809460206027868601019101614823565b01017f252900000000000000000000000000000000000000000000000000000000000060278201520360098101845201826148dc565b61042f6001600160a01b0360805116614c55565b60a05160e0516040517fbc2be1be0000000000000000000000000000000000000000000000000000000081526024803560048301529091602091839182906001600160a01b03165afa801561430057602491600091614718575b5060206001600160a01b0360606080015116604051938480927f9067b677000000000000000000000000000000000000000000000000000000008252823560048301525afa8015614300576104f1926000916146e9575b5064ffffffffff80911691166151d1565b61010051610180516105786021610515606461050e818606615740565b9404614b05565b604051938161052e869351809260208087019101614823565b82016105438251809360208085019101614823565b017f250000000000000000000000000000000000000000000000000000000000000060208201520360018101845201826148dc565b610100608001519060a060800151936105bf6fffffffffffffffffffffffffffffffff60e0608001511660ff6105b86001600160a01b03608051166155d8565b1690614e85565b956101206080015197604051996105d58b61486b565b8a5260208a015260408901526060880152608087015260a086015260c085015260e0840152610100830152610120820152604051806101c081011067ffffffffffffffff6101c08301111761430c576101c081016040526060815260006020820152606060408201526000606082015260006080820152606060a0820152600060c0820152600060e08201526060610100820152600061012082015260006101408201526060610160820152600061018082015260006101a082015260808201516106a660a0840151845190615a76565b906109b361015c604051926106ba846148c0565b600884527f50726f677265737300000000000000000000000000000000000000000000000060208501526107236040516106f381614888565b60009052855160208701207fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a4701490565b156146e1576090945b61073586614b05565b916040519586938493661e339034b21e9160c91b60208601526109818351958692610767846027840160208901614823565b6d11103334b6361e9111b33333111f60911b602785840101526c1e3932b1ba103bb4b23a341e9160991b603585840101526107ae8551809660206042888701019101614823565b7f22206865696768743d22313030222066696c6c2d6f7061636974793d222e3033828501860160428101919091527f222072783d223135222072793d22313522207374726f6b653d2223666666222060628201527f7374726f6b652d6f7061636974793d222e3122207374726f6b652d77696474686082820152651e911a11179f60d11b60a28201527f3c7465787420783d2232302220793d2233342220666f6e742d66616d696c793d60a88201527f2227436f7572696572204e6577272c417269616c2c6d6f6e6f7370616365222060c8820152703337b73a16b9b4bd329e911919383c111f60791b60e88201528651966108b491889160f990910190602001614823565b661e17ba32bc3a1f60c91b8285018601870160f98101919091527f3c7465787420783d2232302220793d2237322220666f6e742d66616d696c793d6101008201527f2227436f7572696572204e6577272c417269616c2c6d6f6e6f73706163652220610120820152703337b73a16b9b4bd329e91191b383c111f60791b61014082015287519761094f91899161015190910190602001614823565b661e17ba32bc3a1f60c91b6101518888888887010101010152602061015888888885519c8d9701010101019101614823565b631e17b39f60e11b90860190910190910190910190910161015881019190915281900361013c810190915201826148dc565b60a083015260c0820152602860e0830151604051906109d182614888565b60008252610c7761015c604051926109e8846148c0565b600684527f53746174757300000000000000000000000000000000000000000000000000006020850152610a1b84615cb6565b610a2482615d33565b808211156146d95750945b610a3a878701614b05565b91604051958693661e339034b21e9160c91b60208601528151610a64816027880160208601614823565b85016d11103334b6361e9111b33333111f60911b60278201526c1e3932b1ba103bb4b23a341e9160991b6035820152610aa7825180936020604285019101614823565b017f22206865696768743d22313030222066696c6c2d6f7061636974793d222e303360428201527f222072783d223135222072793d22313522207374726f6b653d2223666666222060628201527f7374726f6b652d6f7061636974793d222e3122207374726f6b652d77696474686082820152651e911a11179f60d11b60a28201527f3c7465787420783d2232302220793d2233342220666f6e742d66616d696c793d60a88201527f2227436f7572696572204e6577272c417269616c2c6d6f6e6f7370616365222060c8820152703337b73a16b9b4bd329e911919383c111f60791b60e8820152610ba382518093602060f985019101614823565b01661e17ba32bc3a1f60c91b60f98201527f3c7465787420783d2232302220793d2237322220666f6e742d66616d696c793d6101008201527f2227436f7572696572204e6577272c417269616c2c6d6f6e6f73706163652220610120820152703337b73a16b9b4bd329e91191b383c111f60791b610140820152610c3282518093602061015185019101614823565b01661e17ba32bc3a1f60c91b610151820152610c5982518093602061015885019101614823565b01631e17b39f60e11b6101588201520361013c8101845201826148dc565b61010084015201610120820152602861010083015160405190610c9982614888565b60008252610ce361015c60405192610cb0846148c0565b600884527f53747265616d65640000000000000000000000000000000000000000000000006020850152610a1b84615cb6565b6101608401520161018082015261102660608301516030604051610d0681614888565b60008152610fad61015c60405194610d1d866148c0565b600886527f4475726174696f6e0000000000000000000000000000000000000000000000006020870152610d5086615cb6565b610d5982615d33565b808211156146d15750935b610d7060288601614b05565b91604051978893661e339034b21e9160c91b60208601528151610d9a816027880160208601614823565b85016d11103334b6361e9111b33333111f60911b60278201526c1e3932b1ba103bb4b23a341e9160991b6035820152610ddd825180936020604285019101614823565b017f22206865696768743d22313030222066696c6c2d6f7061636974793d222e303360428201527f222072783d223135222072793d22313522207374726f6b653d2223666666222060628201527f7374726f6b652d6f7061636974793d222e3122207374726f6b652d77696474686082820152651e911a11179f60d11b60a28201527f3c7465787420783d2232302220793d2233342220666f6e742d66616d696c793d60a88201527f2227436f7572696572204e6577272c417269616c2c6d6f6e6f7370616365222060c8820152703337b73a16b9b4bd329e911919383c111f60791b60e8820152610ed982518093602060f985019101614823565b01661e17ba32bc3a1f60c91b60f98201527f3c7465787420783d2232302220793d2237322220666f6e742d66616d696c793d6101008201527f2227436f7572696572204e6577272c417269616c2c6d6f6e6f73706163652220610120820152703337b73a16b9b4bd329e91191b383c111f60791b610140820152610f6882518093602061015185019101614823565b01661e17ba32bc3a1f60c91b610151820152610f8f82518093602061015885019101614823565b01631e17b39f60e11b6101588201520361013c8101865201846148dc565b8260408601526028810160608601526101808501519060c0860151809161012088015192839185010101605881016020890152605719906103e8030160011c8060e0890152016010810161014088015201602081016101a08701520101608084015260a083015161010084015161016085015191614e1c565b8152604051908161010081011067ffffffffffffffff6101008401111761430c57610100820160405260c782527f3c726563742077696474683d223130302522206865696768743d22313030252260208301527f2066696c7465723d2275726c28234e6f69736529222f3e3c7265637420783d2260408301527f37302220793d223730222077696474683d2238363022206865696768743d223860608301527f3630222066696c6c3d2223666666222066696c6c2d6f7061636974793d222e3060808301527f33222072783d223435222072793d22343522207374726f6b653d22236666662260a08301527f207374726f6b652d6f7061636974793d222e3122207374726f6b652d7769647460c08301527f683d2234222f3e0000000000000000000000000000000000000000000000000060e083015282519160e084015191805194604051611175816148a4565b603381527f3c636972636c652069643d22476c6f772220723d22353030222066696c6c3d2260208201527f75726c282352616469616c476c6f7729222f3e000000000000000000000000006040820152604051966111d28861486b565b61011c88527f3c66696c7465722069643d224e6f697365223e3c6665466c6f6f6420783d223060208901527f2220793d2230222077696474683d223130302522206865696768743d2231303060408901527f252220666c6f6f642d636f6c6f723d2268736c283233302c3231252c3131252960608901527f2220666c6f6f642d6f7061636974793d22312220726573756c743d22666c6f6f60808901527f6446696c6c222f3e3c666554757262756c656e6365206261736546726571756560a08901527f6e63793d222e3422206e756d4f6374617665733d22332220726573756c743d2260c08901527f4e6f6973652220747970653d226672616374616c4e6f697365222f3e3c66654260e08901527f6c656e6420696e3d224e6f6973652220696e323d22666c6f6f6446696c6c22206101008901527f6d6f64653d22736f66742d6c69676874222f3e3c2f66696c7465723e0000000061012089015260405197886103a081011067ffffffffffffffff6103a08b01111761430c576103a0890160405261037b89527f3c706174682069643d224c6f676f222066696c6c3d2223666666222066696c6c60208a01527f2d6f7061636974793d222e312220643d226d3133332e3535392c3132342e303360408a01527f34632d2e3031332c322e3431322d312e3035392c342e3834382d322e3932332c60608a01527f362e3430322d322e3535382c312e3831392d352e3136382c332e3433392d372e60808a01527f3838382c342e3939362d31342e34342c382e3236322d33312e3034372c31322e60a08a01527f3536352d34372e3637342c31322e3536392d382e3835382e3033362d31372e3860c08a01527f33382d312e3237322d32362e3332382d332e3636332d392e3830362d322e373660e08a01527f362d31392e3038372d372e3131332d32372e3536322d31322e3737382d31332e6101008a01527f3834322d382e3032352c392e3436382d32382e3630362c31362e3135332d33356101208a01527f2e323635683063322e3033352d312e3833382c342e3235322d332e3534362c366101408a01527f2e3436332d352e323234683063362e3432392d352e3635352c31362e3231382d6101608a01527f322e3833352c32302e3335382c342e31372c342e3134332c352e3035372c382e6101808a01527f3831362c392e3634392c31332e39322c31332e373334682e30333763352e37336101a08a01527f362c362e3436312c31352e3335372d322e3235332c392e33382d382e34382c306101c08a01527f2c302d332e3531352d332e3531352d332e3531352d332e3531352d31312e34396101e08a01527f2d31312e3437382d35322e3635362d35322e3636342d36342e3833372d36342e6102008a01527f3833376c2e3034392d2e303337632d312e3732352d312e3630362d322e3731396102208a01527f2d332e3834372d322e3735312d362e3230346830632d2e3034362d322e3337356102408a01527f2c312e3036322d342e3538322c322e3732362d362e32323968306c2e3138352d6102608a01527f2e3134386830632e3039392d2e3036322c2e3232322d2e3134382c2e33372d2e6102808a01527f323539683063322e30362d312e3336322c332e3935312d322e3632312c362e306102a08a01527f34342d332e3834324335372e3736332d332e3437332c39372e37362d322e33346102c08a01527f312c3132382e3633372c31382e3333326331362e3637312c392e3934362d32366102e08a01527f2e3334342c35342e3831332d33382e3635312c34302e3139392d362e3239392d6103008a01527f362e3039362d31382e3036332d31372e3734332d31392e3636382d31382e38316103208a01527f312d362e3031362d342e3034372d31332e3036312c342e3737362d372e3735326103408a01527f2c392e3735316c36382e3235342c36382e33373163312e3732342c312e3630316103608a01527f2c322e3731342c332e38342c322e3733382c362e3139325a222f3e00000000006103808a0152604051978860a081011067ffffffffffffffff60a08b01111761430c57611cb0611d119160a08b0160405260758b527f3c706174682069643d22466c6f6174696e6754657874222066696c6c3d226e6f60208c01527f6e652220643d224d31323520343568373530733830203020383020383076373560408c01527f307330203830202d3830203830682d373530732d38302030202d3830202d383060608c01527f762d3735307330202d3830203830202d3830222f3e000000000000000000000060808c0152611867615a3d565b906040517f3c72616469616c4772616469656e742069643d2252616469616c476c6f77223e6020820152611d0c60d87f3c73746f70206f66667365743d223025222073746f702d636f6c6f723d22000093846040850152805161199960b88660208501936118d981605e840187614823565b8101997f222073746f702d6f7061636974793d222e36222f3e0000000000000000000000605e8c01527f3c73746f70206f66667365743d2231303025222073746f702d636f6c6f723d229a8b607382015261193e825180936020609385019101614823565b017f222073746f702d6f7061636974793d2230222f3e00000000000000000000000060938201527f3c2f72616469616c4772616469656e743e00000000000000000000000000000060a78201520360988101885201866148dc565b6119a1615a3d565b90604051967f3c6c696e6561724772616469656e742069643d2253616e64546f70222078313d60208901527f223025222079313d223025223e000000000000000000000000000000000000006040890152604d8801528251611a0781606b8a0184614823565b8701917f222f3e00000000000000000000000000000000000000000000000000000000009283606b82015289606e820152611a4c825180936020608e85019101614823565b019082608e830152611a9060a2897f3c2f6c696e6561724772616469656e743e0000000000000000000000000000009485609182015203608281018b5201896148dc565b611bd6610108611a9e615a3d565b6040519b8c917f3c6c696e6561724772616469656e742069643d2253616e64426f74746f6d222060208401527f78313d2231303025222079313d2231303025223e00000000000000000000000060408401527f3c73746f70206f66667365743d22313025222073746f702d636f6c6f723d22006054840152611b2a815180926020607387019101614823565b8201908760738301526076820152875190611b49826096830188614823565b018660968201527f3c616e696d617465206174747269627574654e616d653d22783122206475723d60998201527f2236732220726570656174436f756e743d22696e646566696e6974652220766160b98201527f6c7565733d223330253b3630253b313230253b3630253b3330253b222f3e000060d98201528560f78201520360e881018c52018a6148dc565b611bde615a3d565b906040519a8b957f3c6c696e6561724772616469656e742069643d22486f7572676c61737353747260208801527f6f6b6522206772616469656e745472616e73666f726d3d22726f74617465283960408801527f302922206772616469656e74556e6974733d227573657253706163654f6e557360608801527f65223e000000000000000000000000000000000000000000000000000000000060808801527f3c73746f70206f66667365743d22353025222073746f702d636f6c6f723d2200608388015251809260a2880190614823565b84018360a28201527f3c73746f70206f66667365743d22383025222073746f702d636f6c6f723d220060a5820152611cf282518093602060c485019101614823565b019160c483015260c78201520360b88101875201856148dc565b614e1c565b92611d31611d1d615813565b896020815191012090602081519101201490565b9788156146a8575b506040518060c081011067ffffffffffffffff60c08301111761430c5760c08101604052609081527f3c7061746820643d224d2035302c3336302061203330302c333030203020312c60208201527f31203630302c302061203330302c333030203020312c31202d3630302c30222060408201527f66696c6c3d2223666666222066696c6c2d6f7061636974793d222e303222207360608201527f74726f6b653d2275726c2823486f7572676c6173735374726f6b65292220737460808201527f726f6b652d77696474683d2234222f3e0000000000000000000000000000000060a082015260405193846102c081011067ffffffffffffffff6102c08701111761430c576102c0850160405261029885527f3c7061746820643d226d3536362c3136312e323031762d35332e39323463302d60208601527f31392e3338322d32322e3531332d33372e3536332d36332e3339382d35312e3160408601527f39382d34302e3735362d31332e3539322d39342e3934362d32312e3037392d3160608601527f35322e3538372d32312e303739732d3131312e3833382c372e3438372d31353260808601527f2e3630322c32312e303739632d34302e3839332c31332e3633362d36332e343160a08601527f332c33312e3831362d36332e3431332c35312e3139387635332e39323463302c60c08601527f31372e3138312c31372e3730342c33332e3432372c35302e3232332c34362e3360e08601527f3934763238342e383039632d33322e3531392c31322e39362d35302e3232332c6101008601527f32392e3230362d35302e3232332c34362e3339347635332e39323463302c31396101208601527f2e3338322c32322e35322c33372e3536332c36332e3431332c35312e3139382c6101408601527f34302e3736332c31332e3539322c39342e3935342c32312e3037392c3135322e6101608601527f3630322c32312e303739733131312e3833312d372e3438372c3135322e3538376101808601527f2d32312e3037396334302e3838362d31332e3633362c36332e3339382d33312e6101a08601527f3831362c36332e3339382d35312e313938762d35332e39323463302d31372e316101c08601527f39362d31372e3730342d33332e3433352d35302e3232332d34362e34303156326101e08601527f30372e3630336333322e3531392d31322e3936372c35302e3232332d32392e326102008601527f30362c35302e3232332d34362e3430315a6d2d3334372e3436322c35372e37396102208601527f336c3133302e3935392c3133312e3032372d3133302e3935392c3133312e30316102408601527f33563231382e3939345a6d3236322e3932342e303232763236322e3031386c2d6102608601527f3133302e3933372d3133312e3030362c3133302e3933372d3133312e3031335a6102808601527f222066696c6c3d2223313631383232223e3c2f706174683e00000000000000006102a0860152896000146144835760405161218b81614888565b60008152995b1561432257604051806101e081011067ffffffffffffffff6101e08301111761430c576101e081016040526101b181527f3c7061746820643d226d3438312e34362c3438312e35347638312e3031632d3260208201527f2e33352e37372d342e38322c312e35312d372e33392c322e32332d33302e332c60408201527f382e35342d37342e36352c31332e39322d3132342e30362c31332e39322d353360608201527f2e362c302d3130312e32342d362e33332d3133312e34372d31362e3136762d3860808201527f316c34362e332d34362e3331683137302e33336c34362e32392c34362e33315a60a08201527f222066696c6c3d2275726c282353616e64426f74746f6d29222f3e3c7061746860c08201527f20643d226d3433352e31372c3433352e323363302c312e31372d2e34362c322e60e08201527f33322d312e33332c332e34342d372e31312c392e30382d34312e39332c31352e6101008201527f39382d38332e38312c31352e3938732d37362e372d362e392d38332e38322d316101208201527f352e3938632d2e38372d312e31322d312e33332d322e32372d312e33332d332e6101408201527f3434762d2e30346c382e33342d382e33352e30312d2e30316331332e37322d366101608201527f2e35312c34322e39352d31312e30322c37362e382d31312e30327336322e39376101808201527f2c342e34392c37362e37322c31316c382e34322c382e34325a222066696c6c3d6101a08201527f2275726c282353616e64546f7029222f3e0000000000000000000000000000006101c0820152995b60405196876107e081011067ffffffffffffffff6107e08a01111761430c57613b9c9c612e586036602d9960819f97631e17b39f60e11b8d7f3c2f646566733e000000000000000000000000000000000000000000000000009a612f279f6107e0016040526107a782527f3c672066696c6c3d226e6f6e6522207374726f6b653d2275726c2823486f757260208301527f676c6173735374726f6b652922207374726f6b652d6c696e656361703d22726f60408301527f756e6422207374726f6b652d6d697465726c696d69743d22313022207374726f60608301527f6b652d77696474683d2234223e3c7061746820643d226d3536352e3634312c3160808301527f30372e323863302c392e3533372d352e35362c31382e3632392d31352e36373660a08301527f2c32362e393733682d2e303233632d392e3230342c372e3539362d32322e313960c08301527f342c31342e3536322d33382e3139372c32302e3539322d33392e3530342c313460e08301527f2e3933362d39372e3332352c32342e3335352d3136312e3733332c32342e33356101008301527f352d39302e34382c302d3136372e3934382d31382e3538322d3139392e3935336101208301527f2d34342e393438682d2e303233632d31302e3131352d382e3334342d31352e366101408301527f37362d31372e3433372d31352e3637362d32362e3937332c302d33392e3733356101608301527f2c39362e3535342d37312e3932312c3231352e3635322d37312e3932317332316101808301527f352e3632392c33322e3138352c3231352e3632392c37312e3932315a222f3e3c6101a08301527f7061746820643d226d3133342e33362c3136312e32303363302c33392e3733356101c08301527f2c39362e3535342c37312e3932312c3231352e3635322c37312e3932317332316101e08301527f352e3632392d33322e3138362c3231352e3632392d37312e393231222f3e3c6c6102008301527f696e652078313d223133342e3336222079313d223136312e323033222078323d6102208301527f223133342e3336222079323d223130372e3238222f3e3c6c696e652078313d226102408301527f3536352e3634222079313d223136312e323033222078323d223536352e3634226102608301527f2079323d223130372e3238222f3e3c6c696e652078313d223138342e353834226102808301527f2079313d223230362e383233222078323d223138342e353835222079323d22356102a08301527f33372e353739222f3e3c6c696e652078313d223231382e313831222079313d226102c08301527f3231382e313138222078323d223231382e313831222079323d223536322e35336102e08301527f37222f3e3c6c696e652078313d223438312e383138222079313d223231382e316103008301527f3432222078323d223438312e383139222079323d223536322e343238222f3e3c6103208301527f6c696e652078313d223531352e343135222079313d223230372e3335322220786103408301527f323d223531352e343136222079323d223533372e353739222f3e3c70617468206103608301527f643d226d3138342e35382c3533372e353863302c352e34352c342e32372c31306103808301527f2e36352c31322e30332c31352e3432682e303263352e35312c332e33392c31326103a08301527f2e37392c362e35352c32312e35352c392e34322c33302e32312c392e392c37386103c08301527f2e30322c31362e32382c3133312e38332c31362e32382c34392e34312c302c396103e08301527f332e37362d352e33382c3132342e30362d31332e39322c322e372d2e37362c356104008301527f2e32392d312e35342c372e37352d322e33352c382e37372d322e38372c31362e6104208301527f30352d362e30342c32312e35362d392e3433683063372e37362d342e37372c316104408301527f322e30342d392e39372c31322e30342d31352e3432222f3e3c7061746820643d6104608301527f226d3138342e3538322c3439322e363536632d33312e3335342c31322e3438356104808301527f2d35302e3232332c32382e35382d35302e3232332c34362e3134322c302c392e6104a08301527f3533362c352e3536342c31382e3632372c31352e3637372c32362e393639682e6104c08301527f30323263382e3530332c372e3030352c32302e3231332c31332e3436332c33346104e08301527f2e3532342c31392e3135392c392e3939392c332e3939312c32312e3236392c376105008301527f2e3630392c33332e3539372c31302e3738382c33362e34352c392e3430372c386105208301527f322e3138312c31352e3030322c3133312e3833352c31352e3030327339352e336105408301527f36332d352e3539352c3133312e3830372d31352e3030326331302e3834372d326105608301527f2e37392c32302e3836372d352e3932362c32392e3932342d392e3334392c312e6105808301527f3234342d2e3436372c322e3437332d2e3934322c332e3637332d312e3432342c6105a08301527f31342e3332362d352e3639362c32362e3033352d31322e3136312c33342e35326105c08301527f342d31392e313733682e3032326331302e3131342d382e3334322c31352e36376105e08301527f372d31372e3433332c31352e3637372d32362e3936392c302d31372e3536322d6106008301527f31382e3836392d33332e3636352d35302e3232332d34362e3135222f3e3c70616106208301527f746820643d226d3133342e33362c3539322e373263302c33392e3733352c39366106408301527f2e3535342c37312e3932312c3231352e3635322c37312e393231733231352e366106608301527f32392d33322e3138362c3231352e3632392d37312e393231222f3e3c6c696e656106808301527f2078313d223133342e3336222079313d223539322e3732222078323d223133346106a08301527f2e3336222079323d223533382e373937222f3e3c6c696e652078313d223536356106c08301527f2e3634222079313d223539322e3732222078323d223536352e3634222079323d6106e08301527f223533382e373937222f3e3c706f6c796c696e6520706f696e74733d223438316107008301527f2e383232203438312e393031203438312e373938203438312e383737203438316107208301527f2e373735203438312e383534203335302e303135203335302e303236203231386107408301527f2e313835203231382e313239222f3e3c706f6c796c696e6520706f696e74733d6107608301527f223231382e313835203438312e393031203231382e323331203438312e3835346107808301527f203335302e303135203335302e303236203438312e383232203231382e3135326107a08301527f222f3e3c2f673e000000000000000000000000000000000000000000000000006107c0830152604051998a957f3c672069643d22486f7572676c617373223e000000000000000000000000000060208801528551612df48160329860208a8c019101614823565b8701612e098251809360208a85019101614823565b01612e1d8251809360208985019101614823565b01612e318251809360208885019101614823565b01612e458251809360208785019101614823565b01918201520360168101865201846148dc565b6040519e8f9788977f3c646566733e000000000000000000000000000000000000000000000000000060208a0152612e9b8151809260206026809d019101614823565b8901612eb08251809360208c85019101614823565b01612ec48251809360208b85019101614823565b01612ed88251809360208a85019101614823565b01612eec8251809360208985019101614823565b01612f008251809360208885019101614823565b01612f148251809360208785019101614823565b019182015203600d8101895201876148dc565b6137ba604c60c0830151610120840151936135166131496040602084015193015196612f538186615981565b9461314461012b604051612f66816148c0565b600581527f2d3130302500000000000000000000000000000000000000000000000000000060208201526040519889917f3c74657874506174682073746172744f66667365743d220000000000000000006020840152612fd0815180926020603787019101614823565b7f2220687265663d2223466c6f6174696e6754657874222066696c6c3d2223666683820160378101919091527f662220666f6e742d66616d696c793d2227436f7572696572204e6577272c417260578201527f69616c2c6d6f6e6f7370616365222066696c6c2d6f7061636974793d222e3822607782015271103337b73a16b9b4bd329e91191b383c111f60711b60978201527f3c616e696d6174652061646469746976653d2273756d2220617474726962757460a98201527f654e616d653d2273746172744f66667365742220626567696e3d22307322206460c98201527f75723d22353073222066726f6d3d2230252220726570656174436f756e743d2260e98201527f696e646566696e6974652220746f3d2231303025222f3e00000000000000000061010982015282519261311491849161012090910190602001614823565b6a1e17ba32bc3a2830ba341f60a91b90830190910161012081019190915281900361010b810190915201876148dc565b615981565b9561332861012b60405161315c816148c0565b600281527f30250000000000000000000000000000000000000000000000000000000000006020820152604051998a917f3c74657874506174682073746172744f66667365743d2200000000000000000060208401526131c6815180926020603787019101614823565b82017f2220687265663d2223466c6f6174696e6754657874222066696c6c3d2223666660378201527f662220666f6e742d66616d696c793d2227436f7572696572204e6577272c417260578201527f69616c2c6d6f6e6f7370616365222066696c6c2d6f7061636974793d222e3822607782015271103337b73a16b9b4bd329e91191b383c111f60711b60978201527f3c616e696d6174652061646469746976653d2273756d2220617474726962757460a98201527f654e616d653d2273746172744f66667365742220626567696e3d22307322206460c98201527f75723d22353073222066726f6d3d2230252220726570656174436f756e743d2260e98201527f696e646566696e6974652220746f3d2231303025222f3e00000000000000000061010982015261330382518093602061012085019101614823565b016a1e17ba32bc3a2830ba341f60a91b6101208201520361010b81018a5201886148dc565b61333281846159e9565b9261351161012b604051613345816148c0565b600481527f2d3530250000000000000000000000000000000000000000000000000000000060208201526040519687917f3c74657874506174682073746172744f66667365743d2200000000000000000060208401526133af815180926020603787019101614823565b82017f2220687265663d2223466c6f6174696e6754657874222066696c6c3d2223666660378201527f662220666f6e742d66616d696c793d2227436f7572696572204e6577272c417260578201527f69616c2c6d6f6e6f7370616365222066696c6c2d6f7061636974793d222e3822607782015271103337b73a16b9b4bd329e91191b383c111f60711b60978201527f3c616e696d6174652061646469746976653d2273756d2220617474726962757460a98201527f654e616d653d2273746172744f66667365742220626567696e3d22307322206460c98201527f75723d22353073222066726f6d3d2230252220726570656174436f756e743d2260e98201527f696e646566696e6974652220746f3d2231303025222f3e0000000000000000006101098201526134ec82518093602061012085019101614823565b016a1e17ba32bc3a2830ba341f60a91b6101208201520361010b8101875201856148dc565b6159e9565b906136f561012b604051613529816148c0565b600381527f353025000000000000000000000000000000000000000000000000000000000060208201526040519485917f3c74657874506174682073746172744f66667365743d220000000000000000006020840152613593815180926020603787019101614823565b82017f2220687265663d2223466c6f6174696e6754657874222066696c6c3d2223666660378201527f662220666f6e742d66616d696c793d2227436f7572696572204e6577272c417260578201527f69616c2c6d6f6e6f7370616365222066696c6c2d6f7061636974793d222e3822607782015271103337b73a16b9b4bd329e91191b383c111f60711b60978201527f3c616e696d6174652061646469746976653d2273756d2220617474726962757460a98201527f654e616d653d2273746172744f66667365742220626567696e3d22307322206460c98201527f75723d22353073222066726f6d3d2230252220726570656174436f756e743d2260e98201527f696e646566696e6974652220746f3d2231303025222f3e0000000000000000006101098201526136d082518093602061012085019101614823565b016a1e17ba32bc3a2830ba341f60a91b6101208201520361010b8101855201836148dc565b6040519586937f3c7465787420746578742d72656e646572696e673d226f7074696d697a65537060208601527f656564223e000000000000000000000000000000000000000000000000000000604086015261375b815180926020604589019101614823565b8401613771825180936020604585019101614823565b01613786825180936020604585019101614823565b0161379b825180936020604585019101614823565b01661e17ba32bc3a1f60c91b604582015203602c8101845201826148dc565b613a9b61019c60e084015193610140810151906137fc6137f66137f06137ea60806101a086015195015199614b05565b94614b05565b92614b05565b96614b05565b906040519687937f3c75736520687265663d2223476c6f77222066696c6c2d6f7061636974793d2260208601527f2e39222f3e00000000000000000000000000000000000000000000000000000060408601527f3c75736520687265663d2223476c6f772220783d22313030302220793d22313060458601527f3030222066696c6c2d6f7061636974793d222e39222f3e00000000000000000060658601527f3c75736520687265663d22234c6f676f2220783d223137302220793d22313730607c8601527f22207472616e73666f726d3d227363616c65282e3629222f3e3c757365206872609c8601527f65663d2223486f7572676c6173732220783d223135302220793d22393022207460bc8601527f72616e73666f726d3d22726f746174652831302922207472616e73666f726d2d60dc8601527f6f726967696e3d2235303020353030222f3e000000000000000000000000000060fc8601527f3c75736520687265663d222350726f67726573732220783d220000000000000061010e860152805161399681610127936020858a019101614823565b8501927f2220793d22373930222f3e0000000000000000000000000000000000000000008481809694819501527f3c75736520687265663d22235374617475732220783d22000000000000000000610132820152825190613a01826101499560208785019101614823565b01918201527f3c75736520687265663d222353747265616d65642220783d2200000000000000610154820152825190613a448261016d9560208785019101614823565b01918201527f3c75736520687265663d22234475726174696f6e2220783d2200000000000000610178820152825190613a87826101919560208785019101614823565b01918201520361017c8101855201836148dc565b6040519586937f3c73766720786d6c6e733d22687474703a2f2f7777772e77332e6f72672f323060208601527f30302f737667222077696474683d223130303022206865696768743d2231303060408601527f30222076696577426f783d2230203020313030302031303030223e00000000006060860152613b27815180926020607b89019101614823565b8401613b3d825180936020607b85019101614823565b01613b52825180936020607b85019101614823565b01613b67825180936020607b85019101614823565b017f3c2f7376673e0000000000000000000000000000000000000000000000000000607b8201520360618101845201826148dc565b6101405260a05160e0516040517fb971302a0000000000000000000000000000000000000000000000000000000081526024803560048301529091602091839182906001600160a01b03165afa908115614300576000916142b5575b6142b161424a61414f614240609487613d376089613c158a614c55565b9260a0608001516040519485927f5b7b2274726169745f74797065223a224173736574222c2276616c7565223a226020850152613c5c815180926020604088019101614823565b8301907f227d2c7b2274726169745f74797065223a2253656e646572222c2276616c756560408301527f223a22000000000000000000000000000000000000000000000000000000000091826060820152613cc1825180936020606385019101614823565b01907f227d2c7b2274726169745f74797065223a22537461747573222c2276616c756560638301526083820152613d02825180936020608685019101614823565b017f227d5d000000000000000000000000000000000000000000000000000000000060868201520360698101845201826148dc565b6101a05160a05161403961017e613d4f602435614b05565b936080800151613d696001600160a01b0360805116614c55565b90604051968793613f2660208601987f54686973204e465420726570726573656e74732061207061796d656e742073748a527f7265616d20696e2061205361626c696572205632200000000000000000000000604088015282516020840190613dd68160558b0184614823565b8801947f20636f6e74726163742e20546865206f776e6572206f662074686973204e465460558701527f2063616e207769746864726177207468652073747265616d656420617373657460758701527f732c207768696368206172652064656e6f6d696e6174656420696e2000000000609587015282516020840196613e608260b183018a614823565b017f2e5c6e5c6e2d2053747265616d2049443a20000000000000000000000000000060b1820152613e9b82518093602060c385019101614823565b01613ed47f5c6e2d2000000000000000000000000000000000000000000000000000000000958660c384015251809360c7840190614823565b01947f20416464726573733a2000000000000000000000000000000000000000000000958660c7820152613f1282518093602060d185019101614823565b019260d184015251809360d5840190614823565b019060d5820152613f4182518093602060df85019101614823565b017f5c6e5c6e0000000000000000000000000000000000000000000000000000000060df8201527fe29aa0efb88f205741524e494e473a205472616e7366657272696e672074686560e38201527f204e4654206d616b657320746865206e6577206f776e657220746865207265636101038201527f697069656e74206f66207468652073747265616d2e205468652066756e6473206101238201527f617265206e6f74206175746f6d61746963616c6c792077697468647261776e206101438201527f666f72207468652070726576696f757320726563697069656e742e00000000006101638201520361015e8101855201836148dc565b6101a051906141aa61404c602435614b05565b916140cb602d604051809560208201976a029b0b13634b2b9102b19160ad1b8952614081815180926020602b87019101614823565b82017f2023000000000000000000000000000000000000000000000000000000000000602b8201526140bc8251809360208785019101614823565b0103600d8101865201846148dc565b610140516140d890614991565b94604051998a977f7b2261747472696275746573223a00000000000000000000000000000000000060208a0152614119815180926020602e8d019101614823565b8801917f2c226465736372697074696f6e223a2200000000000000000000000000000000602e840152518093603e840190614823565b01917f222c2265787465726e616c5f75726c223a2268747470733a2f2f7361626c6965603e8401527f722e636f6d222c226e616d65223a220000000000000000000000000000000000605e840152518093606d840190614823565b017f222c22696d616765223a22646174613a696d6167652f7376672b786d6c3b6261606d8201527f736536342c000000000000000000000000000000000000000000000000000000608d82015261420b825180936020609285019101614823565b017f227d00000000000000000000000000000000000000000000000000000000000060928201520360748101845201826148dc565b60c0819052614991565b61429d603d60405180937f646174613a6170706c69636174696f6e2f6a736f6e3b6261736536342c000000602083015261428d8151809260208686019101614823565b810103601d8101845201826148dc565b604051918291602083526020830190614846565b0390f35b90506020813d6020116142f8575b816142d0602093836148dc565b810103126142f35751906001600160a01b03821682036142f3579061414f613bf8565b600080fd5b3d91506142c3565b6040513d6000823e3d90fd5b634e487b7160e01b600052604160045260246000fd5b6040518061012081011067ffffffffffffffff6101208301111761430c57610120810160405260f881527f3c7061746820643d226d3438312e34362c3530342e3130317635382e3434396360208201527f2d322e33352e37372d342e38322c312e35312d372e33392c322e32332d33302e60408201527f332c382e35342d37342e36352c31332e39322d3132342e30362c31332e39322d60608201527f35332e362c302d3130312e32342d362e33332d3133312e34372d31362e31367660808201527f2d35382e343339683236322e39325a222066696c6c3d2275726c282353616e6460a08201527f426f74746f6d29222f3e3c656c6c697073652063783d22333530222063793d2260c08201527f3530342e313031222072783d223133312e343632222072793d2232382e31303860e08201527f222066696c6c3d2275726c282353616e64546f7029222f3e0000000000000000610100820152996123de565b604051806101c081011067ffffffffffffffff6101c08301111761430c576101c0810160405261019981527f3c706f6c79676f6e20706f696e74733d22333530203335302e3032362034313560208201527f2e3033203238342e39373820323835203238342e39373820333530203335302e60408201527f303236222066696c6c3d2275726c282353616e64426f74746f6d29222f3e3c7060608201527f61746820643d226d3431362e3334312c3238312e39373563302c2e3931342d2e60808201527f3335342c312e3830392d312e3033352c322e36382d352e3534322c372e30373660a08201527f2d33322e3636312c31322e34352d36352e32382c31322e34352d33322e36323460c08201527f2c302d35392e3733382d352e3337342d36352e32382d31322e34352d2e36383160e08201527f2d2e3837322d312e3033352d312e3736372d312e3033352d322e36382c302d2e6101008201527f3931342e3335342d312e3830382c312e3033352d322e3637362c352e3534322d6101208201527f372e3037362c33322e3635362d31322e34352c36352e32382d31322e34352c336101408201527f322e3631392c302c35392e3733382c352e3337342c36352e32382c31322e34356101608201527f2e3638312e3836372c312e3033352c312e3736322c312e3033352c322e3637366101808201527f5a222066696c6c3d2275726c282353616e64546f7029222f3e000000000000006101a082015299612191565b6146ca9198506146b661584c565b906020815191012090602081519101201490565b9638611d39565b905093610d64565b905094610a2f565b60d09461072c565b61470b915060203d602011614711575b61470381836148dc565b810190614926565b386104e0565b503d6146f9565b614731915060203d6020116147115761470381836148dc565b38610489565b634e487b7160e01b600052601260045260246000fd5b61477091925060203d602011614777575b61476881836148dc565b8101906148fe565b903861023d565b503d61475e565b614797915060203d6020116147775761476881836148dc565b386101d2565b506020813d6020116147d2575b816147b7602093836148dc565b810103126142f3575160058110156142f3576101779061016d565b3d91506147aa565b90506020813d60201161481b575b816147f5602093836148dc565b810103126142f357516001600160a01b03811681036142f3576001600160a01b036100ff565b3d91506147e8565b60005b8381106148365750506000910152565b8181015183820152602001614826565b9060209161485f81518092818552858086019101614823565b601f01601f1916010190565b610140810190811067ffffffffffffffff82111761430c57604052565b6020810190811067ffffffffffffffff82111761430c57604052565b6060810190811067ffffffffffffffff82111761430c57604052565b6040810190811067ffffffffffffffff82111761430c57604052565b90601f8019910116810190811067ffffffffffffffff82111761430c57604052565b908160209103126142f357516fffffffffffffffffffffffffffffffff811681036142f35790565b908160209103126142f3575164ffffffffff811681036142f35790565b67ffffffffffffffff811161430c57601f01601f191660200190565b9061496982614943565b61497660405191826148dc565b8281528092614987601f1991614943565b0190602036910137565b805115614af1576040516149a4816148a4565b604081527f4142434445464748494a4b4c4d4e4f505152535455565758595a61626364656660208201527f6768696a6b6c6d6e6f707172737475767778797a303132333435363738392b2f60408201528151600292838201809211614adb5760038092047f3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81168103614adb57614a3e908594951b61495f565b936020850193829183518401925b838110614a8a5750505050510680600114614a7757600214614a6c575090565b603d90600019015390565b50603d9081600019820153600119015390565b85600491979293949701918251600190603f9082828260121c16880101518453828282600c1c16880101518385015382828260061c1688010151888501531685010151878201530195929190614a4c565b634e487b7160e01b600052601160045260246000fd5b50604051614afe81614888565b6000815290565b806000917a184f03e93ff9f4daa797ed6e38ed64bf6a1f01000000000000000080821015614c47575b506d04ee2d6d415b85acef810000000080831015614c38575b50662386f26fc1000080831015614c29575b506305f5e10080831015614c1a575b5061271080831015614c0b575b506064821015614bfb575b600a80921015614bf1575b600190816021614b9c82870161495f565b95860101905b614bae575b5050505090565b600019019083907f30313233343536373839616263646566000000000000000000000000000000008282061a835304918215614bec57919082614ba2565b614ba7565b9160010191614b8b565b9190606460029104910191614b80565b60049193920491019138614b75565b60089193920491019138614b68565b60109193920491019138614b59565b60209193920491019138614b47565b604093508104915038614b2e565b6001600160a01b031660405190614c6b826148a4565b602a8252602082016040368237825115614d8357603090538151600190811015614d8357607860218401536029905b808211614d08575050614caa5790565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602060248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152fd5b9091600f81166010811015614d6e577f3031323334353637383961626364656600000000000000000000000000000000901a614d448486614d99565b5360041c918015614d59576000190190614c9a565b60246000634e487b7160e01b81526011600452fd5b60246000634e487b7160e01b81526032600452fd5b634e487b7160e01b600052603260045260246000fd5b908151811015614d83570160200190565b60405190614db7826148c0565b600482527f2667743b000000000000000000000000000000000000000000000000000000006020830152565b60405190614df0826148c0565b600482527f266c743b000000000000000000000000000000000000000000000000000000006020830152565b90614e839294936040519586928451614e3d81602097888089019101614823565b8401614e5182518093888085019101614823565b01614e6482518093878085019101614823565b01614e7782518093868085019101614823565b010380855201836148dc565b565b80156151965760009180615171575090505b6001908082811015614f0457505050614eae614de3565b614f01602260405183614ecb829551809260208086019101614823565b81017f203100000000000000000000000000000000000000000000000000000000000060208201520360028101845201826148dc565b90565b66038d7ea4c6800011156151145760409081519060a0820182811067ffffffffffffffff82111761430c57808452614f3b81614888565b600081528252825190614f4d826148c0565b8482526020917f4b0000000000000000000000000000000000000000000000000000000000000083820152828401528351614f87816148c0565b8581527f4d0000000000000000000000000000000000000000000000000000000000000083820152848401528351614fbe816148c0565b8581527f42000000000000000000000000000000000000000000000000000000000000008382015260608401528351614ff6816148c0565b8581527f54000000000000000000000000000000000000000000000000000000000000008382015260808401526000918583965b6150e8575b5084519461503c866148c0565b6007908187527f2623383830353b0000000000000000000000000000000000000000000000000083880152519560005b8281106150d557505050506150b66150bc917f20000000000000000000000000000000000000000000000000000000000000006027870152600886526150b1866148c0565b614b05565b91615740565b916005851015614d8357614f019460051b015192614e1c565b818101840151888201850152830161506c565b9591926103e89081851061510b57508680916064600a870406950493019661502a565b9392965061502f565b505061511e614daa565b614f0160286040518361513b829551809260208086019101614823565b81017f203939392e39395400000000000000000000000000000000000000000000000060208201520360088101845201826148dc565b600a0a918215615182575004614e97565b80634e487b7160e01b602492526012600452fd5b50506040516151a4816148c0565b600181527f3000000000000000000000000000000000000000000000000000000000000000602082015290565b620151809103048061523957506151e6614de3565b614f01602660405183615203829551809260208086019101614823565b81017f203120446179000000000000000000000000000000000000000000000000000060208201520360068101845201826148dc565b61270f811161530857600181036152c557614f01602061528d60405161525e816148c0565b600481527f20446179000000000000000000000000000000000000000000000000000000008382015293614b05565b60405193816152a58693518092868087019101614823565b82016152b982518093868085019101614823565b010380845201826148dc565b614f01602061528d6040516152d9816148c0565b600581527f20446179730000000000000000000000000000000000000000000000000000008382015293614b05565b50615311614daa565b614f01602a6040518361532e829551809260208086019101614823565b81017f2039393939204461797300000000000000000000000000000000000000000000602082015203600a8101845201826148dc565b6020818303126142f35780519067ffffffffffffffff82116142f3570181601f820112156142f357805161539781614943565b926153a560405194856148dc565b818452602082840101116142f357614f019160208085019101614823565b6001600160a01b031660409081516395d89b4160e01b8152600081600481855afa90811561559d5760009161557c575b506154588351615402816148c0565b601181527f5341422d56322d4c4f434b55502d4c494e0000000000000000000000000000006020918201528251908301207fc66b376a19264d832c1bc254000c18944ca5aa57ed50f4ea637c4da424d4c3bb1490565b1561549657505051615469816148c0565b600d81527f4c6f636b7570204c696e65617200000000000000000000000000000000000000602082015290565b6154fa83516154a4816148c0565b601181527f5341422d56322d4c4f434b55502d44594e0000000000000000000000000000006020918201528251908301207f6ab655856fa5352de8c05542b1937ac63c59342da992602767c02734cc5391651490565b156155385750505161550b816148c0565b600e81527f4c6f636b75702044796e616d6963000000000000000000000000000000000000602082015290565b6155789083519384937f814a8a2e000000000000000000000000000000000000000000000000000000008552600485015260248401526044830190614846565b0390fd5b615597913d8091833e61558f81836148dc565b810190615364565b386153f3565b83513d6000823e3d90fd5b3d156155d3573d906155b982614943565b916155c760405193846148dc565b82523d6000602084013e565b606090565b60405160208101907f313ce56700000000000000000000000000000000000000000000000000000000825260048152615610816148c0565b6000928392839251915afa6156236155a8565b908061565a575b156156565760208180518101031261565257602001519060ff8216820361564f575090565b80fd5b5080fd5b5090565b50602081511461562a565b6000809160405160208101906395d89b4160e01b825260048152615688816148c0565b51915afa6156946155a8565b90158015615734575b6156fa57806020806156b493518301019101615364565b601e815111600014614f0157506040516156cd816148c0565b600b81527f4c6f6e672053796d626f6c000000000000000000000000000000000000000000602082015290565b50604051615707816148c0565b600581527f4552433230000000000000000000000000000000000000000000000000000000602082015290565b5060408151111561569d565b806157525750604051614afe81614888565b600a8110156157b75761576490614b05565b614f01602260405180937f2e3000000000000000000000000000000000000000000000000000000000000060208301526157a78151809260208686019101614823565b81010360028101845201826148dc565b6157c090614b05565b614f01602160405180937f2e0000000000000000000000000000000000000000000000000000000000000060208301526158038151809260208686019101614823565b81010360018101845201826148dc565b60405190615820826148c0565b600782527f536574746c6564000000000000000000000000000000000000000000000000006020830152565b60405190615859826148c0565b600882527f4465706c657465640000000000000000000000000000000000000000000000006020830152565b600581101561596b576004810361589f5750614f0161584c565b600381036158e157506040516158b4816148c0565b600881527f43616e63656c6564000000000000000000000000000000000000000000000000602082015290565b6001810361592357506040516158f6816148c0565b600981527f53747265616d696e670000000000000000000000000000000000000000000000602082015290565b60020361593257614f01615813565b60405161593e816148c0565b600781527f50656e64696e6700000000000000000000000000000000000000000000000000602082015290565b634e487b7160e01b600052602160045260246000fd5b6030614e839193929360405194816159a3879351809260208087019101614823565b820164010714051160dd1b60208201526a029b0b13634b2b9102b19160ad1b60258201526159da8251809360208785019101614823565b010360108101855201836148dc565b6025614e83919392936040519481615a0b879351809260208087019101614823565b820164010714051160dd1b6020820152615a2e8251809360208785019101614823565b010360058101855201836148dc565b60405190615a4a826148c0565b601082527f68736c283233302c3231252c31312529000000000000000000000000000000006020830152565b8015615ca857615a84615a3d565b90612710908103908111614adb57614f0191615aa261013692614b05565b6040519485927f3c672066696c6c3d226e6f6e65223e000000000000000000000000000000000060208501527f3c636972636c652063783d22313636222063793d2235302220723d2232322220602f8501527f7374726f6b653d22000000000000000000000000000000000000000000000000604f850152615b2e815180926020605788019101614823565b83017f22207374726f6b652d77696474683d223130222f3e000000000000000000000060578201527f3c636972636c652063783d22313636222063793d2235302220706174684c656e606c8201527f6774683d2231303030302220723d22323222207374726f6b653d220000000000608c820152615bb682518093602060a785019101614823565b017f22207374726f6b652d6461736861727261793d22313030303022207374726f6b60a78201527f652d646173686f66667365743d2200000000000000000000000000000000000060c7820152615c1782518093602060d585019101614823565b017f22207374726f6b652d6c696e656361703d22726f756e6422207374726f6b652d60d58201527f77696474683d223522207472616e73666f726d3d22726f74617465282d39302960f58201527f22207472616e73666f726d2d6f726967696e3d22313636203530222f3e000000610115820152631e17b39f60e11b610132820152036101168101845201826148dc565b5050604051614afe81614888565b60009080518015615d2b579060009182915b818310615cda57505050600d02900390565b909193603b60f81b7fff00000000000000000000000000000000000000000000000000000000000000615d0d8785614d99565b511614615d23575b600d01936001019190615cc8565b849350615d15565b505050600090565b60009080518015615d2b579060009182915b818310615d575750505060041b900390565b909193603b60f81b7fff00000000000000000000000000000000000000000000000000000000000000615d8a8785614d99565b511614615da0575b601001936001019190615d45565b849350615d9256
Deployed Bytecode
0x6080604052600436101561001257600080fd5b60003560e01c63e9dc63751461002757600080fd5b346142f35760403660031901126142f3576001600160a01b0360043516600435036142f357610056608061486b565b60006080819052606060a081905260c0819052610100819052610120819052610140819052610160829052610180919091526101a0526004356001600160a01b031660e08190526100a690614c55565b6101005260e0516040517feac8f5b80000000000000000000000000000000000000000000000000000000081526024803560048301529091602091839182906001600160a01b03165afa908115614300576000916147da575b506001600160a01b03610116911680608052615665565b60a05260e0516040517fad35efd40000000000000000000000000000000000000000000000000000000081526024803560048301529091602091839182906001600160a01b03165afa80156143005760009061479d575b6101779150615885565b6101205260e0516040517f4869e12d0000000000000000000000000000000000000000000000000000000081526024803560048301529091602091839182906001600160a01b03165afa80156143005760249160009161477e575b506fffffffffffffffffffffffffffffffff81166101605260e0516040517fa80fc071000000000000000000000000000000000000000000000000000000008152833560048201529260209184919082906001600160a01b03165afa9182156143005760009261474d575b506fffffffffffffffffffffffffffffffff821615614737576fffffffffffffffffffffffffffffffff9182169082166127100282160416610180526102846004356153c3565b610120608001526040514660208201526bffffffffffffffffffffffff1960043560601b16604082015260243560548201526054815280608081011067ffffffffffffffff60808301111761430c57608081016040526020815191012061041b602963ffffffff61032b6103048261016861ffff8860101c160616614b05565b91601e604660ff6103218460146050848d60081c16060116614b05565b9816060116614b05565b6040519485927f68736c2800000000000000000000000000000000000000000000000000000000602085015261036b815180926020602488019101614823565b83017f2c0000000000000000000000000000000000000000000000000000000000000060248201526103a7825180936020602585019101614823565b7f252c000000000000000000000000000000000000000000000000000000000000602583830101526103e58351809460206027868601019101614823565b01017f252900000000000000000000000000000000000000000000000000000000000060278201520360098101845201826148dc565b61042f6001600160a01b0360805116614c55565b60a05160e0516040517fbc2be1be0000000000000000000000000000000000000000000000000000000081526024803560048301529091602091839182906001600160a01b03165afa801561430057602491600091614718575b5060206001600160a01b0360606080015116604051938480927f9067b677000000000000000000000000000000000000000000000000000000008252823560048301525afa8015614300576104f1926000916146e9575b5064ffffffffff80911691166151d1565b61010051610180516105786021610515606461050e818606615740565b9404614b05565b604051938161052e869351809260208087019101614823565b82016105438251809360208085019101614823565b017f250000000000000000000000000000000000000000000000000000000000000060208201520360018101845201826148dc565b610100608001519060a060800151936105bf6fffffffffffffffffffffffffffffffff60e0608001511660ff6105b86001600160a01b03608051166155d8565b1690614e85565b956101206080015197604051996105d58b61486b565b8a5260208a015260408901526060880152608087015260a086015260c085015260e0840152610100830152610120820152604051806101c081011067ffffffffffffffff6101c08301111761430c576101c081016040526060815260006020820152606060408201526000606082015260006080820152606060a0820152600060c0820152600060e08201526060610100820152600061012082015260006101408201526060610160820152600061018082015260006101a082015260808201516106a660a0840151845190615a76565b906109b361015c604051926106ba846148c0565b600884527f50726f677265737300000000000000000000000000000000000000000000000060208501526107236040516106f381614888565b60009052855160208701207fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a4701490565b156146e1576090945b61073586614b05565b916040519586938493661e339034b21e9160c91b60208601526109818351958692610767846027840160208901614823565b6d11103334b6361e9111b33333111f60911b602785840101526c1e3932b1ba103bb4b23a341e9160991b603585840101526107ae8551809660206042888701019101614823565b7f22206865696768743d22313030222066696c6c2d6f7061636974793d222e3033828501860160428101919091527f222072783d223135222072793d22313522207374726f6b653d2223666666222060628201527f7374726f6b652d6f7061636974793d222e3122207374726f6b652d77696474686082820152651e911a11179f60d11b60a28201527f3c7465787420783d2232302220793d2233342220666f6e742d66616d696c793d60a88201527f2227436f7572696572204e6577272c417269616c2c6d6f6e6f7370616365222060c8820152703337b73a16b9b4bd329e911919383c111f60791b60e88201528651966108b491889160f990910190602001614823565b661e17ba32bc3a1f60c91b8285018601870160f98101919091527f3c7465787420783d2232302220793d2237322220666f6e742d66616d696c793d6101008201527f2227436f7572696572204e6577272c417269616c2c6d6f6e6f73706163652220610120820152703337b73a16b9b4bd329e91191b383c111f60791b61014082015287519761094f91899161015190910190602001614823565b661e17ba32bc3a1f60c91b6101518888888887010101010152602061015888888885519c8d9701010101019101614823565b631e17b39f60e11b90860190910190910190910190910161015881019190915281900361013c810190915201826148dc565b60a083015260c0820152602860e0830151604051906109d182614888565b60008252610c7761015c604051926109e8846148c0565b600684527f53746174757300000000000000000000000000000000000000000000000000006020850152610a1b84615cb6565b610a2482615d33565b808211156146d95750945b610a3a878701614b05565b91604051958693661e339034b21e9160c91b60208601528151610a64816027880160208601614823565b85016d11103334b6361e9111b33333111f60911b60278201526c1e3932b1ba103bb4b23a341e9160991b6035820152610aa7825180936020604285019101614823565b017f22206865696768743d22313030222066696c6c2d6f7061636974793d222e303360428201527f222072783d223135222072793d22313522207374726f6b653d2223666666222060628201527f7374726f6b652d6f7061636974793d222e3122207374726f6b652d77696474686082820152651e911a11179f60d11b60a28201527f3c7465787420783d2232302220793d2233342220666f6e742d66616d696c793d60a88201527f2227436f7572696572204e6577272c417269616c2c6d6f6e6f7370616365222060c8820152703337b73a16b9b4bd329e911919383c111f60791b60e8820152610ba382518093602060f985019101614823565b01661e17ba32bc3a1f60c91b60f98201527f3c7465787420783d2232302220793d2237322220666f6e742d66616d696c793d6101008201527f2227436f7572696572204e6577272c417269616c2c6d6f6e6f73706163652220610120820152703337b73a16b9b4bd329e91191b383c111f60791b610140820152610c3282518093602061015185019101614823565b01661e17ba32bc3a1f60c91b610151820152610c5982518093602061015885019101614823565b01631e17b39f60e11b6101588201520361013c8101845201826148dc565b61010084015201610120820152602861010083015160405190610c9982614888565b60008252610ce361015c60405192610cb0846148c0565b600884527f53747265616d65640000000000000000000000000000000000000000000000006020850152610a1b84615cb6565b6101608401520161018082015261102660608301516030604051610d0681614888565b60008152610fad61015c60405194610d1d866148c0565b600886527f4475726174696f6e0000000000000000000000000000000000000000000000006020870152610d5086615cb6565b610d5982615d33565b808211156146d15750935b610d7060288601614b05565b91604051978893661e339034b21e9160c91b60208601528151610d9a816027880160208601614823565b85016d11103334b6361e9111b33333111f60911b60278201526c1e3932b1ba103bb4b23a341e9160991b6035820152610ddd825180936020604285019101614823565b017f22206865696768743d22313030222066696c6c2d6f7061636974793d222e303360428201527f222072783d223135222072793d22313522207374726f6b653d2223666666222060628201527f7374726f6b652d6f7061636974793d222e3122207374726f6b652d77696474686082820152651e911a11179f60d11b60a28201527f3c7465787420783d2232302220793d2233342220666f6e742d66616d696c793d60a88201527f2227436f7572696572204e6577272c417269616c2c6d6f6e6f7370616365222060c8820152703337b73a16b9b4bd329e911919383c111f60791b60e8820152610ed982518093602060f985019101614823565b01661e17ba32bc3a1f60c91b60f98201527f3c7465787420783d2232302220793d2237322220666f6e742d66616d696c793d6101008201527f2227436f7572696572204e6577272c417269616c2c6d6f6e6f73706163652220610120820152703337b73a16b9b4bd329e91191b383c111f60791b610140820152610f6882518093602061015185019101614823565b01661e17ba32bc3a1f60c91b610151820152610f8f82518093602061015885019101614823565b01631e17b39f60e11b6101588201520361013c8101865201846148dc565b8260408601526028810160608601526101808501519060c0860151809161012088015192839185010101605881016020890152605719906103e8030160011c8060e0890152016010810161014088015201602081016101a08701520101608084015260a083015161010084015161016085015191614e1c565b8152604051908161010081011067ffffffffffffffff6101008401111761430c57610100820160405260c782527f3c726563742077696474683d223130302522206865696768743d22313030252260208301527f2066696c7465723d2275726c28234e6f69736529222f3e3c7265637420783d2260408301527f37302220793d223730222077696474683d2238363022206865696768743d223860608301527f3630222066696c6c3d2223666666222066696c6c2d6f7061636974793d222e3060808301527f33222072783d223435222072793d22343522207374726f6b653d22236666662260a08301527f207374726f6b652d6f7061636974793d222e3122207374726f6b652d7769647460c08301527f683d2234222f3e0000000000000000000000000000000000000000000000000060e083015282519160e084015191805194604051611175816148a4565b603381527f3c636972636c652069643d22476c6f772220723d22353030222066696c6c3d2260208201527f75726c282352616469616c476c6f7729222f3e000000000000000000000000006040820152604051966111d28861486b565b61011c88527f3c66696c7465722069643d224e6f697365223e3c6665466c6f6f6420783d223060208901527f2220793d2230222077696474683d223130302522206865696768743d2231303060408901527f252220666c6f6f642d636f6c6f723d2268736c283233302c3231252c3131252960608901527f2220666c6f6f642d6f7061636974793d22312220726573756c743d22666c6f6f60808901527f6446696c6c222f3e3c666554757262756c656e6365206261736546726571756560a08901527f6e63793d222e3422206e756d4f6374617665733d22332220726573756c743d2260c08901527f4e6f6973652220747970653d226672616374616c4e6f697365222f3e3c66654260e08901527f6c656e6420696e3d224e6f6973652220696e323d22666c6f6f6446696c6c22206101008901527f6d6f64653d22736f66742d6c69676874222f3e3c2f66696c7465723e0000000061012089015260405197886103a081011067ffffffffffffffff6103a08b01111761430c576103a0890160405261037b89527f3c706174682069643d224c6f676f222066696c6c3d2223666666222066696c6c60208a01527f2d6f7061636974793d222e312220643d226d3133332e3535392c3132342e303360408a01527f34632d2e3031332c322e3431322d312e3035392c342e3834382d322e3932332c60608a01527f362e3430322d322e3535382c312e3831392d352e3136382c332e3433392d372e60808a01527f3838382c342e3939362d31342e34342c382e3236322d33312e3034372c31322e60a08a01527f3536352d34372e3637342c31322e3536392d382e3835382e3033362d31372e3860c08a01527f33382d312e3237322d32362e3332382d332e3636332d392e3830362d322e373660e08a01527f362d31392e3038372d372e3131332d32372e3536322d31322e3737382d31332e6101008a01527f3834322d382e3032352c392e3436382d32382e3630362c31362e3135332d33356101208a01527f2e323635683063322e3033352d312e3833382c342e3235322d332e3534362c366101408a01527f2e3436332d352e323234683063362e3432392d352e3635352c31362e3231382d6101608a01527f322e3833352c32302e3335382c342e31372c342e3134332c352e3035372c382e6101808a01527f3831362c392e3634392c31332e39322c31332e373334682e30333763352e37336101a08a01527f362c362e3436312c31352e3335372d322e3235332c392e33382d382e34382c306101c08a01527f2c302d332e3531352d332e3531352d332e3531352d332e3531352d31312e34396101e08a01527f2d31312e3437382d35322e3635362d35322e3636342d36342e3833372d36342e6102008a01527f3833376c2e3034392d2e303337632d312e3732352d312e3630362d322e3731396102208a01527f2d332e3834372d322e3735312d362e3230346830632d2e3034362d322e3337356102408a01527f2c312e3036322d342e3538322c322e3732362d362e32323968306c2e3138352d6102608a01527f2e3134386830632e3039392d2e3036322c2e3232322d2e3134382c2e33372d2e6102808a01527f323539683063322e30362d312e3336322c332e3935312d322e3632312c362e306102a08a01527f34342d332e3834324335372e3736332d332e3437332c39372e37362d322e33346102c08a01527f312c3132382e3633372c31382e3333326331362e3637312c392e3934362d32366102e08a01527f2e3334342c35342e3831332d33382e3635312c34302e3139392d362e3239392d6103008a01527f362e3039362d31382e3036332d31372e3734332d31392e3636382d31382e38316103208a01527f312d362e3031362d342e3034372d31332e3036312c342e3737362d372e3735326103408a01527f2c392e3735316c36382e3235342c36382e33373163312e3732342c312e3630316103608a01527f2c322e3731342c332e38342c322e3733382c362e3139325a222f3e00000000006103808a0152604051978860a081011067ffffffffffffffff60a08b01111761430c57611cb0611d119160a08b0160405260758b527f3c706174682069643d22466c6f6174696e6754657874222066696c6c3d226e6f60208c01527f6e652220643d224d31323520343568373530733830203020383020383076373560408c01527f307330203830202d3830203830682d373530732d38302030202d3830202d383060608c01527f762d3735307330202d3830203830202d3830222f3e000000000000000000000060808c0152611867615a3d565b906040517f3c72616469616c4772616469656e742069643d2252616469616c476c6f77223e6020820152611d0c60d87f3c73746f70206f66667365743d223025222073746f702d636f6c6f723d22000093846040850152805161199960b88660208501936118d981605e840187614823565b8101997f222073746f702d6f7061636974793d222e36222f3e0000000000000000000000605e8c01527f3c73746f70206f66667365743d2231303025222073746f702d636f6c6f723d229a8b607382015261193e825180936020609385019101614823565b017f222073746f702d6f7061636974793d2230222f3e00000000000000000000000060938201527f3c2f72616469616c4772616469656e743e00000000000000000000000000000060a78201520360988101885201866148dc565b6119a1615a3d565b90604051967f3c6c696e6561724772616469656e742069643d2253616e64546f70222078313d60208901527f223025222079313d223025223e000000000000000000000000000000000000006040890152604d8801528251611a0781606b8a0184614823565b8701917f222f3e00000000000000000000000000000000000000000000000000000000009283606b82015289606e820152611a4c825180936020608e85019101614823565b019082608e830152611a9060a2897f3c2f6c696e6561724772616469656e743e0000000000000000000000000000009485609182015203608281018b5201896148dc565b611bd6610108611a9e615a3d565b6040519b8c917f3c6c696e6561724772616469656e742069643d2253616e64426f74746f6d222060208401527f78313d2231303025222079313d2231303025223e00000000000000000000000060408401527f3c73746f70206f66667365743d22313025222073746f702d636f6c6f723d22006054840152611b2a815180926020607387019101614823565b8201908760738301526076820152875190611b49826096830188614823565b018660968201527f3c616e696d617465206174747269627574654e616d653d22783122206475723d60998201527f2236732220726570656174436f756e743d22696e646566696e6974652220766160b98201527f6c7565733d223330253b3630253b313230253b3630253b3330253b222f3e000060d98201528560f78201520360e881018c52018a6148dc565b611bde615a3d565b906040519a8b957f3c6c696e6561724772616469656e742069643d22486f7572676c61737353747260208801527f6f6b6522206772616469656e745472616e73666f726d3d22726f74617465283960408801527f302922206772616469656e74556e6974733d227573657253706163654f6e557360608801527f65223e000000000000000000000000000000000000000000000000000000000060808801527f3c73746f70206f66667365743d22353025222073746f702d636f6c6f723d2200608388015251809260a2880190614823565b84018360a28201527f3c73746f70206f66667365743d22383025222073746f702d636f6c6f723d220060a5820152611cf282518093602060c485019101614823565b019160c483015260c78201520360b88101875201856148dc565b614e1c565b92611d31611d1d615813565b896020815191012090602081519101201490565b9788156146a8575b506040518060c081011067ffffffffffffffff60c08301111761430c5760c08101604052609081527f3c7061746820643d224d2035302c3336302061203330302c333030203020312c60208201527f31203630302c302061203330302c333030203020312c31202d3630302c30222060408201527f66696c6c3d2223666666222066696c6c2d6f7061636974793d222e303222207360608201527f74726f6b653d2275726c2823486f7572676c6173735374726f6b65292220737460808201527f726f6b652d77696474683d2234222f3e0000000000000000000000000000000060a082015260405193846102c081011067ffffffffffffffff6102c08701111761430c576102c0850160405261029885527f3c7061746820643d226d3536362c3136312e323031762d35332e39323463302d60208601527f31392e3338322d32322e3531332d33372e3536332d36332e3339382d35312e3160408601527f39382d34302e3735362d31332e3539322d39342e3934362d32312e3037392d3160608601527f35322e3538372d32312e303739732d3131312e3833382c372e3438372d31353260808601527f2e3630322c32312e303739632d34302e3839332c31332e3633362d36332e343160a08601527f332c33312e3831362d36332e3431332c35312e3139387635332e39323463302c60c08601527f31372e3138312c31372e3730342c33332e3432372c35302e3232332c34362e3360e08601527f3934763238342e383039632d33322e3531392c31322e39362d35302e3232332c6101008601527f32392e3230362d35302e3232332c34362e3339347635332e39323463302c31396101208601527f2e3338322c32322e35322c33372e3536332c36332e3431332c35312e3139382c6101408601527f34302e3736332c31332e3539322c39342e3935342c32312e3037392c3135322e6101608601527f3630322c32312e303739733131312e3833312d372e3438372c3135322e3538376101808601527f2d32312e3037396334302e3838362d31332e3633362c36332e3339382d33312e6101a08601527f3831362c36332e3339382d35312e313938762d35332e39323463302d31372e316101c08601527f39362d31372e3730342d33332e3433352d35302e3232332d34362e34303156326101e08601527f30372e3630336333322e3531392d31322e3936372c35302e3232332d32392e326102008601527f30362c35302e3232332d34362e3430315a6d2d3334372e3436322c35372e37396102208601527f336c3133302e3935392c3133312e3032372d3133302e3935392c3133312e30316102408601527f33563231382e3939345a6d3236322e3932342e303232763236322e3031386c2d6102608601527f3133302e3933372d3133312e3030362c3133302e3933372d3133312e3031335a6102808601527f222066696c6c3d2223313631383232223e3c2f706174683e00000000000000006102a0860152896000146144835760405161218b81614888565b60008152995b1561432257604051806101e081011067ffffffffffffffff6101e08301111761430c576101e081016040526101b181527f3c7061746820643d226d3438312e34362c3438312e35347638312e3031632d3260208201527f2e33352e37372d342e38322c312e35312d372e33392c322e32332d33302e332c60408201527f382e35342d37342e36352c31332e39322d3132342e30362c31332e39322d353360608201527f2e362c302d3130312e32342d362e33332d3133312e34372d31362e3136762d3860808201527f316c34362e332d34362e3331683137302e33336c34362e32392c34362e33315a60a08201527f222066696c6c3d2275726c282353616e64426f74746f6d29222f3e3c7061746860c08201527f20643d226d3433352e31372c3433352e323363302c312e31372d2e34362c322e60e08201527f33322d312e33332c332e34342d372e31312c392e30382d34312e39332c31352e6101008201527f39382d38332e38312c31352e3938732d37362e372d362e392d38332e38322d316101208201527f352e3938632d2e38372d312e31322d312e33332d322e32372d312e33332d332e6101408201527f3434762d2e30346c382e33342d382e33352e30312d2e30316331332e37322d366101608201527f2e35312c34322e39352d31312e30322c37362e382d31312e30327336322e39376101808201527f2c342e34392c37362e37322c31316c382e34322c382e34325a222066696c6c3d6101a08201527f2275726c282353616e64546f7029222f3e0000000000000000000000000000006101c0820152995b60405196876107e081011067ffffffffffffffff6107e08a01111761430c57613b9c9c612e586036602d9960819f97631e17b39f60e11b8d7f3c2f646566733e000000000000000000000000000000000000000000000000009a612f279f6107e0016040526107a782527f3c672066696c6c3d226e6f6e6522207374726f6b653d2275726c2823486f757260208301527f676c6173735374726f6b652922207374726f6b652d6c696e656361703d22726f60408301527f756e6422207374726f6b652d6d697465726c696d69743d22313022207374726f60608301527f6b652d77696474683d2234223e3c7061746820643d226d3536352e3634312c3160808301527f30372e323863302c392e3533372d352e35362c31382e3632392d31352e36373660a08301527f2c32362e393733682d2e303233632d392e3230342c372e3539362d32322e313960c08301527f342c31342e3536322d33382e3139372c32302e3539322d33392e3530342c313460e08301527f2e3933362d39372e3332352c32342e3335352d3136312e3733332c32342e33356101008301527f352d39302e34382c302d3136372e3934382d31382e3538322d3139392e3935336101208301527f2d34342e393438682d2e303233632d31302e3131352d382e3334342d31352e366101408301527f37362d31372e3433372d31352e3637362d32362e3937332c302d33392e3733356101608301527f2c39362e3535342d37312e3932312c3231352e3635322d37312e3932317332316101808301527f352e3632392c33322e3138352c3231352e3632392c37312e3932315a222f3e3c6101a08301527f7061746820643d226d3133342e33362c3136312e32303363302c33392e3733356101c08301527f2c39362e3535342c37312e3932312c3231352e3635322c37312e3932317332316101e08301527f352e3632392d33322e3138362c3231352e3632392d37312e393231222f3e3c6c6102008301527f696e652078313d223133342e3336222079313d223136312e323033222078323d6102208301527f223133342e3336222079323d223130372e3238222f3e3c6c696e652078313d226102408301527f3536352e3634222079313d223136312e323033222078323d223536352e3634226102608301527f2079323d223130372e3238222f3e3c6c696e652078313d223138342e353834226102808301527f2079313d223230362e383233222078323d223138342e353835222079323d22356102a08301527f33372e353739222f3e3c6c696e652078313d223231382e313831222079313d226102c08301527f3231382e313138222078323d223231382e313831222079323d223536322e35336102e08301527f37222f3e3c6c696e652078313d223438312e383138222079313d223231382e316103008301527f3432222078323d223438312e383139222079323d223536322e343238222f3e3c6103208301527f6c696e652078313d223531352e343135222079313d223230372e3335322220786103408301527f323d223531352e343136222079323d223533372e353739222f3e3c70617468206103608301527f643d226d3138342e35382c3533372e353863302c352e34352c342e32372c31306103808301527f2e36352c31322e30332c31352e3432682e303263352e35312c332e33392c31326103a08301527f2e37392c362e35352c32312e35352c392e34322c33302e32312c392e392c37386103c08301527f2e30322c31362e32382c3133312e38332c31362e32382c34392e34312c302c396103e08301527f332e37362d352e33382c3132342e30362d31332e39322c322e372d2e37362c356104008301527f2e32392d312e35342c372e37352d322e33352c382e37372d322e38372c31362e6104208301527f30352d362e30342c32312e35362d392e3433683063372e37362d342e37372c316104408301527f322e30342d392e39372c31322e30342d31352e3432222f3e3c7061746820643d6104608301527f226d3138342e3538322c3439322e363536632d33312e3335342c31322e3438356104808301527f2d35302e3232332c32382e35382d35302e3232332c34362e3134322c302c392e6104a08301527f3533362c352e3536342c31382e3632372c31352e3637372c32362e393639682e6104c08301527f30323263382e3530332c372e3030352c32302e3231332c31332e3436332c33346104e08301527f2e3532342c31392e3135392c392e3939392c332e3939312c32312e3236392c376105008301527f2e3630392c33332e3539372c31302e3738382c33362e34352c392e3430372c386105208301527f322e3138312c31352e3030322c3133312e3833352c31352e3030327339352e336105408301527f36332d352e3539352c3133312e3830372d31352e3030326331302e3834372d326105608301527f2e37392c32302e3836372d352e3932362c32392e3932342d392e3334392c312e6105808301527f3234342d2e3436372c322e3437332d2e3934322c332e3637332d312e3432342c6105a08301527f31342e3332362d352e3639362c32362e3033352d31322e3136312c33342e35326105c08301527f342d31392e313733682e3032326331302e3131342d382e3334322c31352e36376105e08301527f372d31372e3433332c31352e3637372d32362e3936392c302d31372e3536322d6106008301527f31382e3836392d33332e3636352d35302e3232332d34362e3135222f3e3c70616106208301527f746820643d226d3133342e33362c3539322e373263302c33392e3733352c39366106408301527f2e3535342c37312e3932312c3231352e3635322c37312e393231733231352e366106608301527f32392d33322e3138362c3231352e3632392d37312e393231222f3e3c6c696e656106808301527f2078313d223133342e3336222079313d223539322e3732222078323d223133346106a08301527f2e3336222079323d223533382e373937222f3e3c6c696e652078313d223536356106c08301527f2e3634222079313d223539322e3732222078323d223536352e3634222079323d6106e08301527f223533382e373937222f3e3c706f6c796c696e6520706f696e74733d223438316107008301527f2e383232203438312e393031203438312e373938203438312e383737203438316107208301527f2e373735203438312e383534203335302e303135203335302e303236203231386107408301527f2e313835203231382e313239222f3e3c706f6c796c696e6520706f696e74733d6107608301527f223231382e313835203438312e393031203231382e323331203438312e3835346107808301527f203335302e303135203335302e303236203438312e383232203231382e3135326107a08301527f222f3e3c2f673e000000000000000000000000000000000000000000000000006107c0830152604051998a957f3c672069643d22486f7572676c617373223e000000000000000000000000000060208801528551612df48160329860208a8c019101614823565b8701612e098251809360208a85019101614823565b01612e1d8251809360208985019101614823565b01612e318251809360208885019101614823565b01612e458251809360208785019101614823565b01918201520360168101865201846148dc565b6040519e8f9788977f3c646566733e000000000000000000000000000000000000000000000000000060208a0152612e9b8151809260206026809d019101614823565b8901612eb08251809360208c85019101614823565b01612ec48251809360208b85019101614823565b01612ed88251809360208a85019101614823565b01612eec8251809360208985019101614823565b01612f008251809360208885019101614823565b01612f148251809360208785019101614823565b019182015203600d8101895201876148dc565b6137ba604c60c0830151610120840151936135166131496040602084015193015196612f538186615981565b9461314461012b604051612f66816148c0565b600581527f2d3130302500000000000000000000000000000000000000000000000000000060208201526040519889917f3c74657874506174682073746172744f66667365743d220000000000000000006020840152612fd0815180926020603787019101614823565b7f2220687265663d2223466c6f6174696e6754657874222066696c6c3d2223666683820160378101919091527f662220666f6e742d66616d696c793d2227436f7572696572204e6577272c417260578201527f69616c2c6d6f6e6f7370616365222066696c6c2d6f7061636974793d222e3822607782015271103337b73a16b9b4bd329e91191b383c111f60711b60978201527f3c616e696d6174652061646469746976653d2273756d2220617474726962757460a98201527f654e616d653d2273746172744f66667365742220626567696e3d22307322206460c98201527f75723d22353073222066726f6d3d2230252220726570656174436f756e743d2260e98201527f696e646566696e6974652220746f3d2231303025222f3e00000000000000000061010982015282519261311491849161012090910190602001614823565b6a1e17ba32bc3a2830ba341f60a91b90830190910161012081019190915281900361010b810190915201876148dc565b615981565b9561332861012b60405161315c816148c0565b600281527f30250000000000000000000000000000000000000000000000000000000000006020820152604051998a917f3c74657874506174682073746172744f66667365743d2200000000000000000060208401526131c6815180926020603787019101614823565b82017f2220687265663d2223466c6f6174696e6754657874222066696c6c3d2223666660378201527f662220666f6e742d66616d696c793d2227436f7572696572204e6577272c417260578201527f69616c2c6d6f6e6f7370616365222066696c6c2d6f7061636974793d222e3822607782015271103337b73a16b9b4bd329e91191b383c111f60711b60978201527f3c616e696d6174652061646469746976653d2273756d2220617474726962757460a98201527f654e616d653d2273746172744f66667365742220626567696e3d22307322206460c98201527f75723d22353073222066726f6d3d2230252220726570656174436f756e743d2260e98201527f696e646566696e6974652220746f3d2231303025222f3e00000000000000000061010982015261330382518093602061012085019101614823565b016a1e17ba32bc3a2830ba341f60a91b6101208201520361010b81018a5201886148dc565b61333281846159e9565b9261351161012b604051613345816148c0565b600481527f2d3530250000000000000000000000000000000000000000000000000000000060208201526040519687917f3c74657874506174682073746172744f66667365743d2200000000000000000060208401526133af815180926020603787019101614823565b82017f2220687265663d2223466c6f6174696e6754657874222066696c6c3d2223666660378201527f662220666f6e742d66616d696c793d2227436f7572696572204e6577272c417260578201527f69616c2c6d6f6e6f7370616365222066696c6c2d6f7061636974793d222e3822607782015271103337b73a16b9b4bd329e91191b383c111f60711b60978201527f3c616e696d6174652061646469746976653d2273756d2220617474726962757460a98201527f654e616d653d2273746172744f66667365742220626567696e3d22307322206460c98201527f75723d22353073222066726f6d3d2230252220726570656174436f756e743d2260e98201527f696e646566696e6974652220746f3d2231303025222f3e0000000000000000006101098201526134ec82518093602061012085019101614823565b016a1e17ba32bc3a2830ba341f60a91b6101208201520361010b8101875201856148dc565b6159e9565b906136f561012b604051613529816148c0565b600381527f353025000000000000000000000000000000000000000000000000000000000060208201526040519485917f3c74657874506174682073746172744f66667365743d220000000000000000006020840152613593815180926020603787019101614823565b82017f2220687265663d2223466c6f6174696e6754657874222066696c6c3d2223666660378201527f662220666f6e742d66616d696c793d2227436f7572696572204e6577272c417260578201527f69616c2c6d6f6e6f7370616365222066696c6c2d6f7061636974793d222e3822607782015271103337b73a16b9b4bd329e91191b383c111f60711b60978201527f3c616e696d6174652061646469746976653d2273756d2220617474726962757460a98201527f654e616d653d2273746172744f66667365742220626567696e3d22307322206460c98201527f75723d22353073222066726f6d3d2230252220726570656174436f756e743d2260e98201527f696e646566696e6974652220746f3d2231303025222f3e0000000000000000006101098201526136d082518093602061012085019101614823565b016a1e17ba32bc3a2830ba341f60a91b6101208201520361010b8101855201836148dc565b6040519586937f3c7465787420746578742d72656e646572696e673d226f7074696d697a65537060208601527f656564223e000000000000000000000000000000000000000000000000000000604086015261375b815180926020604589019101614823565b8401613771825180936020604585019101614823565b01613786825180936020604585019101614823565b0161379b825180936020604585019101614823565b01661e17ba32bc3a1f60c91b604582015203602c8101845201826148dc565b613a9b61019c60e084015193610140810151906137fc6137f66137f06137ea60806101a086015195015199614b05565b94614b05565b92614b05565b96614b05565b906040519687937f3c75736520687265663d2223476c6f77222066696c6c2d6f7061636974793d2260208601527f2e39222f3e00000000000000000000000000000000000000000000000000000060408601527f3c75736520687265663d2223476c6f772220783d22313030302220793d22313060458601527f3030222066696c6c2d6f7061636974793d222e39222f3e00000000000000000060658601527f3c75736520687265663d22234c6f676f2220783d223137302220793d22313730607c8601527f22207472616e73666f726d3d227363616c65282e3629222f3e3c757365206872609c8601527f65663d2223486f7572676c6173732220783d223135302220793d22393022207460bc8601527f72616e73666f726d3d22726f746174652831302922207472616e73666f726d2d60dc8601527f6f726967696e3d2235303020353030222f3e000000000000000000000000000060fc8601527f3c75736520687265663d222350726f67726573732220783d220000000000000061010e860152805161399681610127936020858a019101614823565b8501927f2220793d22373930222f3e0000000000000000000000000000000000000000008481809694819501527f3c75736520687265663d22235374617475732220783d22000000000000000000610132820152825190613a01826101499560208785019101614823565b01918201527f3c75736520687265663d222353747265616d65642220783d2200000000000000610154820152825190613a448261016d9560208785019101614823565b01918201527f3c75736520687265663d22234475726174696f6e2220783d2200000000000000610178820152825190613a87826101919560208785019101614823565b01918201520361017c8101855201836148dc565b6040519586937f3c73766720786d6c6e733d22687474703a2f2f7777772e77332e6f72672f323060208601527f30302f737667222077696474683d223130303022206865696768743d2231303060408601527f30222076696577426f783d2230203020313030302031303030223e00000000006060860152613b27815180926020607b89019101614823565b8401613b3d825180936020607b85019101614823565b01613b52825180936020607b85019101614823565b01613b67825180936020607b85019101614823565b017f3c2f7376673e0000000000000000000000000000000000000000000000000000607b8201520360618101845201826148dc565b6101405260a05160e0516040517fb971302a0000000000000000000000000000000000000000000000000000000081526024803560048301529091602091839182906001600160a01b03165afa908115614300576000916142b5575b6142b161424a61414f614240609487613d376089613c158a614c55565b9260a0608001516040519485927f5b7b2274726169745f74797065223a224173736574222c2276616c7565223a226020850152613c5c815180926020604088019101614823565b8301907f227d2c7b2274726169745f74797065223a2253656e646572222c2276616c756560408301527f223a22000000000000000000000000000000000000000000000000000000000091826060820152613cc1825180936020606385019101614823565b01907f227d2c7b2274726169745f74797065223a22537461747573222c2276616c756560638301526083820152613d02825180936020608685019101614823565b017f227d5d000000000000000000000000000000000000000000000000000000000060868201520360698101845201826148dc565b6101a05160a05161403961017e613d4f602435614b05565b936080800151613d696001600160a01b0360805116614c55565b90604051968793613f2660208601987f54686973204e465420726570726573656e74732061207061796d656e742073748a527f7265616d20696e2061205361626c696572205632200000000000000000000000604088015282516020840190613dd68160558b0184614823565b8801947f20636f6e74726163742e20546865206f776e6572206f662074686973204e465460558701527f2063616e207769746864726177207468652073747265616d656420617373657460758701527f732c207768696368206172652064656e6f6d696e6174656420696e2000000000609587015282516020840196613e608260b183018a614823565b017f2e5c6e5c6e2d2053747265616d2049443a20000000000000000000000000000060b1820152613e9b82518093602060c385019101614823565b01613ed47f5c6e2d2000000000000000000000000000000000000000000000000000000000958660c384015251809360c7840190614823565b01947f20416464726573733a2000000000000000000000000000000000000000000000958660c7820152613f1282518093602060d185019101614823565b019260d184015251809360d5840190614823565b019060d5820152613f4182518093602060df85019101614823565b017f5c6e5c6e0000000000000000000000000000000000000000000000000000000060df8201527fe29aa0efb88f205741524e494e473a205472616e7366657272696e672074686560e38201527f204e4654206d616b657320746865206e6577206f776e657220746865207265636101038201527f697069656e74206f66207468652073747265616d2e205468652066756e6473206101238201527f617265206e6f74206175746f6d61746963616c6c792077697468647261776e206101438201527f666f72207468652070726576696f757320726563697069656e742e00000000006101638201520361015e8101855201836148dc565b6101a051906141aa61404c602435614b05565b916140cb602d604051809560208201976a029b0b13634b2b9102b19160ad1b8952614081815180926020602b87019101614823565b82017f2023000000000000000000000000000000000000000000000000000000000000602b8201526140bc8251809360208785019101614823565b0103600d8101865201846148dc565b610140516140d890614991565b94604051998a977f7b2261747472696275746573223a00000000000000000000000000000000000060208a0152614119815180926020602e8d019101614823565b8801917f2c226465736372697074696f6e223a2200000000000000000000000000000000602e840152518093603e840190614823565b01917f222c2265787465726e616c5f75726c223a2268747470733a2f2f7361626c6965603e8401527f722e636f6d222c226e616d65223a220000000000000000000000000000000000605e840152518093606d840190614823565b017f222c22696d616765223a22646174613a696d6167652f7376672b786d6c3b6261606d8201527f736536342c000000000000000000000000000000000000000000000000000000608d82015261420b825180936020609285019101614823565b017f227d00000000000000000000000000000000000000000000000000000000000060928201520360748101845201826148dc565b60c0819052614991565b61429d603d60405180937f646174613a6170706c69636174696f6e2f6a736f6e3b6261736536342c000000602083015261428d8151809260208686019101614823565b810103601d8101845201826148dc565b604051918291602083526020830190614846565b0390f35b90506020813d6020116142f8575b816142d0602093836148dc565b810103126142f35751906001600160a01b03821682036142f3579061414f613bf8565b600080fd5b3d91506142c3565b6040513d6000823e3d90fd5b634e487b7160e01b600052604160045260246000fd5b6040518061012081011067ffffffffffffffff6101208301111761430c57610120810160405260f881527f3c7061746820643d226d3438312e34362c3530342e3130317635382e3434396360208201527f2d322e33352e37372d342e38322c312e35312d372e33392c322e32332d33302e60408201527f332c382e35342d37342e36352c31332e39322d3132342e30362c31332e39322d60608201527f35332e362c302d3130312e32342d362e33332d3133312e34372d31362e31367660808201527f2d35382e343339683236322e39325a222066696c6c3d2275726c282353616e6460a08201527f426f74746f6d29222f3e3c656c6c697073652063783d22333530222063793d2260c08201527f3530342e313031222072783d223133312e343632222072793d2232382e31303860e08201527f222066696c6c3d2275726c282353616e64546f7029222f3e0000000000000000610100820152996123de565b604051806101c081011067ffffffffffffffff6101c08301111761430c576101c0810160405261019981527f3c706f6c79676f6e20706f696e74733d22333530203335302e3032362034313560208201527f2e3033203238342e39373820323835203238342e39373820333530203335302e60408201527f303236222066696c6c3d2275726c282353616e64426f74746f6d29222f3e3c7060608201527f61746820643d226d3431362e3334312c3238312e39373563302c2e3931342d2e60808201527f3335342c312e3830392d312e3033352c322e36382d352e3534322c372e30373660a08201527f2d33322e3636312c31322e34352d36352e32382c31322e34352d33322e36323460c08201527f2c302d35392e3733382d352e3337342d36352e32382d31322e34352d2e36383160e08201527f2d2e3837322d312e3033352d312e3736372d312e3033352d322e36382c302d2e6101008201527f3931342e3335342d312e3830382c312e3033352d322e3637362c352e3534322d6101208201527f372e3037362c33322e3635362d31322e34352c36352e32382d31322e34352c336101408201527f322e3631392c302c35392e3733382c352e3337342c36352e32382c31322e34356101608201527f2e3638312e3836372c312e3033352c312e3736322c312e3033352c322e3637366101808201527f5a222066696c6c3d2275726c282353616e64546f7029222f3e000000000000006101a082015299612191565b6146ca9198506146b661584c565b906020815191012090602081519101201490565b9638611d39565b905093610d64565b905094610a2f565b60d09461072c565b61470b915060203d602011614711575b61470381836148dc565b810190614926565b386104e0565b503d6146f9565b614731915060203d6020116147115761470381836148dc565b38610489565b634e487b7160e01b600052601260045260246000fd5b61477091925060203d602011614777575b61476881836148dc565b8101906148fe565b903861023d565b503d61475e565b614797915060203d6020116147775761476881836148dc565b386101d2565b506020813d6020116147d2575b816147b7602093836148dc565b810103126142f3575160058110156142f3576101779061016d565b3d91506147aa565b90506020813d60201161481b575b816147f5602093836148dc565b810103126142f357516001600160a01b03811681036142f3576001600160a01b036100ff565b3d91506147e8565b60005b8381106148365750506000910152565b8181015183820152602001614826565b9060209161485f81518092818552858086019101614823565b601f01601f1916010190565b610140810190811067ffffffffffffffff82111761430c57604052565b6020810190811067ffffffffffffffff82111761430c57604052565b6060810190811067ffffffffffffffff82111761430c57604052565b6040810190811067ffffffffffffffff82111761430c57604052565b90601f8019910116810190811067ffffffffffffffff82111761430c57604052565b908160209103126142f357516fffffffffffffffffffffffffffffffff811681036142f35790565b908160209103126142f3575164ffffffffff811681036142f35790565b67ffffffffffffffff811161430c57601f01601f191660200190565b9061496982614943565b61497660405191826148dc565b8281528092614987601f1991614943565b0190602036910137565b805115614af1576040516149a4816148a4565b604081527f4142434445464748494a4b4c4d4e4f505152535455565758595a61626364656660208201527f6768696a6b6c6d6e6f707172737475767778797a303132333435363738392b2f60408201528151600292838201809211614adb5760038092047f3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81168103614adb57614a3e908594951b61495f565b936020850193829183518401925b838110614a8a5750505050510680600114614a7757600214614a6c575090565b603d90600019015390565b50603d9081600019820153600119015390565b85600491979293949701918251600190603f9082828260121c16880101518453828282600c1c16880101518385015382828260061c1688010151888501531685010151878201530195929190614a4c565b634e487b7160e01b600052601160045260246000fd5b50604051614afe81614888565b6000815290565b806000917a184f03e93ff9f4daa797ed6e38ed64bf6a1f01000000000000000080821015614c47575b506d04ee2d6d415b85acef810000000080831015614c38575b50662386f26fc1000080831015614c29575b506305f5e10080831015614c1a575b5061271080831015614c0b575b506064821015614bfb575b600a80921015614bf1575b600190816021614b9c82870161495f565b95860101905b614bae575b5050505090565b600019019083907f30313233343536373839616263646566000000000000000000000000000000008282061a835304918215614bec57919082614ba2565b614ba7565b9160010191614b8b565b9190606460029104910191614b80565b60049193920491019138614b75565b60089193920491019138614b68565b60109193920491019138614b59565b60209193920491019138614b47565b604093508104915038614b2e565b6001600160a01b031660405190614c6b826148a4565b602a8252602082016040368237825115614d8357603090538151600190811015614d8357607860218401536029905b808211614d08575050614caa5790565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602060248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152fd5b9091600f81166010811015614d6e577f3031323334353637383961626364656600000000000000000000000000000000901a614d448486614d99565b5360041c918015614d59576000190190614c9a565b60246000634e487b7160e01b81526011600452fd5b60246000634e487b7160e01b81526032600452fd5b634e487b7160e01b600052603260045260246000fd5b908151811015614d83570160200190565b60405190614db7826148c0565b600482527f2667743b000000000000000000000000000000000000000000000000000000006020830152565b60405190614df0826148c0565b600482527f266c743b000000000000000000000000000000000000000000000000000000006020830152565b90614e839294936040519586928451614e3d81602097888089019101614823565b8401614e5182518093888085019101614823565b01614e6482518093878085019101614823565b01614e7782518093868085019101614823565b010380855201836148dc565b565b80156151965760009180615171575090505b6001908082811015614f0457505050614eae614de3565b614f01602260405183614ecb829551809260208086019101614823565b81017f203100000000000000000000000000000000000000000000000000000000000060208201520360028101845201826148dc565b90565b66038d7ea4c6800011156151145760409081519060a0820182811067ffffffffffffffff82111761430c57808452614f3b81614888565b600081528252825190614f4d826148c0565b8482526020917f4b0000000000000000000000000000000000000000000000000000000000000083820152828401528351614f87816148c0565b8581527f4d0000000000000000000000000000000000000000000000000000000000000083820152848401528351614fbe816148c0565b8581527f42000000000000000000000000000000000000000000000000000000000000008382015260608401528351614ff6816148c0565b8581527f54000000000000000000000000000000000000000000000000000000000000008382015260808401526000918583965b6150e8575b5084519461503c866148c0565b6007908187527f2623383830353b0000000000000000000000000000000000000000000000000083880152519560005b8281106150d557505050506150b66150bc917f20000000000000000000000000000000000000000000000000000000000000006027870152600886526150b1866148c0565b614b05565b91615740565b916005851015614d8357614f019460051b015192614e1c565b818101840151888201850152830161506c565b9591926103e89081851061510b57508680916064600a870406950493019661502a565b9392965061502f565b505061511e614daa565b614f0160286040518361513b829551809260208086019101614823565b81017f203939392e39395400000000000000000000000000000000000000000000000060208201520360088101845201826148dc565b600a0a918215615182575004614e97565b80634e487b7160e01b602492526012600452fd5b50506040516151a4816148c0565b600181527f3000000000000000000000000000000000000000000000000000000000000000602082015290565b620151809103048061523957506151e6614de3565b614f01602660405183615203829551809260208086019101614823565b81017f203120446179000000000000000000000000000000000000000000000000000060208201520360068101845201826148dc565b61270f811161530857600181036152c557614f01602061528d60405161525e816148c0565b600481527f20446179000000000000000000000000000000000000000000000000000000008382015293614b05565b60405193816152a58693518092868087019101614823565b82016152b982518093868085019101614823565b010380845201826148dc565b614f01602061528d6040516152d9816148c0565b600581527f20446179730000000000000000000000000000000000000000000000000000008382015293614b05565b50615311614daa565b614f01602a6040518361532e829551809260208086019101614823565b81017f2039393939204461797300000000000000000000000000000000000000000000602082015203600a8101845201826148dc565b6020818303126142f35780519067ffffffffffffffff82116142f3570181601f820112156142f357805161539781614943565b926153a560405194856148dc565b818452602082840101116142f357614f019160208085019101614823565b6001600160a01b031660409081516395d89b4160e01b8152600081600481855afa90811561559d5760009161557c575b506154588351615402816148c0565b601181527f5341422d56322d4c4f434b55502d4c494e0000000000000000000000000000006020918201528251908301207fc66b376a19264d832c1bc254000c18944ca5aa57ed50f4ea637c4da424d4c3bb1490565b1561549657505051615469816148c0565b600d81527f4c6f636b7570204c696e65617200000000000000000000000000000000000000602082015290565b6154fa83516154a4816148c0565b601181527f5341422d56322d4c4f434b55502d44594e0000000000000000000000000000006020918201528251908301207f6ab655856fa5352de8c05542b1937ac63c59342da992602767c02734cc5391651490565b156155385750505161550b816148c0565b600e81527f4c6f636b75702044796e616d6963000000000000000000000000000000000000602082015290565b6155789083519384937f814a8a2e000000000000000000000000000000000000000000000000000000008552600485015260248401526044830190614846565b0390fd5b615597913d8091833e61558f81836148dc565b810190615364565b386153f3565b83513d6000823e3d90fd5b3d156155d3573d906155b982614943565b916155c760405193846148dc565b82523d6000602084013e565b606090565b60405160208101907f313ce56700000000000000000000000000000000000000000000000000000000825260048152615610816148c0565b6000928392839251915afa6156236155a8565b908061565a575b156156565760208180518101031261565257602001519060ff8216820361564f575090565b80fd5b5080fd5b5090565b50602081511461562a565b6000809160405160208101906395d89b4160e01b825260048152615688816148c0565b51915afa6156946155a8565b90158015615734575b6156fa57806020806156b493518301019101615364565b601e815111600014614f0157506040516156cd816148c0565b600b81527f4c6f6e672053796d626f6c000000000000000000000000000000000000000000602082015290565b50604051615707816148c0565b600581527f4552433230000000000000000000000000000000000000000000000000000000602082015290565b5060408151111561569d565b806157525750604051614afe81614888565b600a8110156157b75761576490614b05565b614f01602260405180937f2e3000000000000000000000000000000000000000000000000000000000000060208301526157a78151809260208686019101614823565b81010360028101845201826148dc565b6157c090614b05565b614f01602160405180937f2e0000000000000000000000000000000000000000000000000000000000000060208301526158038151809260208686019101614823565b81010360018101845201826148dc565b60405190615820826148c0565b600782527f536574746c6564000000000000000000000000000000000000000000000000006020830152565b60405190615859826148c0565b600882527f4465706c657465640000000000000000000000000000000000000000000000006020830152565b600581101561596b576004810361589f5750614f0161584c565b600381036158e157506040516158b4816148c0565b600881527f43616e63656c6564000000000000000000000000000000000000000000000000602082015290565b6001810361592357506040516158f6816148c0565b600981527f53747265616d696e670000000000000000000000000000000000000000000000602082015290565b60020361593257614f01615813565b60405161593e816148c0565b600781527f50656e64696e6700000000000000000000000000000000000000000000000000602082015290565b634e487b7160e01b600052602160045260246000fd5b6030614e839193929360405194816159a3879351809260208087019101614823565b820164010714051160dd1b60208201526a029b0b13634b2b9102b19160ad1b60258201526159da8251809360208785019101614823565b010360108101855201836148dc565b6025614e83919392936040519481615a0b879351809260208087019101614823565b820164010714051160dd1b6020820152615a2e8251809360208785019101614823565b010360058101855201836148dc565b60405190615a4a826148c0565b601082527f68736c283233302c3231252c31312529000000000000000000000000000000006020830152565b8015615ca857615a84615a3d565b90612710908103908111614adb57614f0191615aa261013692614b05565b6040519485927f3c672066696c6c3d226e6f6e65223e000000000000000000000000000000000060208501527f3c636972636c652063783d22313636222063793d2235302220723d2232322220602f8501527f7374726f6b653d22000000000000000000000000000000000000000000000000604f850152615b2e815180926020605788019101614823565b83017f22207374726f6b652d77696474683d223130222f3e000000000000000000000060578201527f3c636972636c652063783d22313636222063793d2235302220706174684c656e606c8201527f6774683d2231303030302220723d22323222207374726f6b653d220000000000608c820152615bb682518093602060a785019101614823565b017f22207374726f6b652d6461736861727261793d22313030303022207374726f6b60a78201527f652d646173686f66667365743d2200000000000000000000000000000000000060c7820152615c1782518093602060d585019101614823565b017f22207374726f6b652d6c696e656361703d22726f756e6422207374726f6b652d60d58201527f77696474683d223522207472616e73666f726d3d22726f74617465282d39302960f58201527f22207472616e73666f726d2d6f726967696e3d22313636203530222f3e000000610115820152631e17b39f60e11b610132820152036101168101845201826148dc565b5050604051614afe81614888565b60009080518015615d2b579060009182915b818310615cda57505050600d02900390565b909193603b60f81b7fff00000000000000000000000000000000000000000000000000000000000000615d0d8785614d99565b511614615d23575b600d01936001019190615cc8565b849350615d15565b505050600090565b60009080518015615d2b579060009182915b818310615d575750505060041b900390565b909193603b60f81b7fff00000000000000000000000000000000000000000000000000000000000000615d8a8785614d99565b511614615da0575b601001936001019190615d45565b849350615d9256
Loading...
Loading
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 34 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.