// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import { ICheckpoints } from "./interfaces/ICheckpoints.sol";
/// @title Checkpoints
/// @notice Contract for storing checkpoints of share balances for each user and trend
contract Checkpoints is ICheckpoints {
mapping(address user => mapping(bytes32 trend => uint256[] shares)) internal _checkpoints;
mapping(bytes32 trend => uint256[] supply) internal _trendSupplyCheckpoints;
/// @notice Gets the checkpoint for a user and trend at a given block number
/// @param checkpoints The storage array to read the checkpoint from
/// @param blockNumber The block number to get the checkpoint at
function readCheckpoint(uint256[] storage checkpoints, uint256 blockNumber) internal view returns (uint128) {
if (blockNumber >= block.number) {
revert BlockNumberNotFoundYet();
}
uint256 low = 0;
uint256 high = checkpoints.length;
while (low < high) {
uint256 mid = Math.average(low, high);
uint128 midBlock = decodeBlockNumber(checkpoints[mid]);
if (midBlock > blockNumber) {
high = mid;
} else {
low = mid + 1;
}
}
return high == 0 ? 0 : decodeShares(checkpoints[high - 1]);
}
/// @notice Writes a checkpoint to a storage array using a function for the operation (add or subtract)
/// @param checkpoints The storage array to write the checkpoint to
/// @param operation The operation to perform on the checkpoint (add or subtract)
/// @param difference The difference to perform the operation with
/// @return oldShares The old shares of the checkpoint
/// @return newShares The new shares of the checkpoint
function writeCheckpoint(
uint256[] storage checkpoints,
function(uint256, uint256) view returns (uint256) operation,
uint256 difference
) internal returns (uint256 oldShares, uint256 newShares) {
uint256 position = checkpoints.length;
oldShares = position == 0 ? 0 : decodeShares(checkpoints[position - 1]);
newShares = operation(oldShares, difference);
if (position > 0) {
uint128 fromBlock = decodeBlockNumber(checkpoints[position - 1]);
if (fromBlock == block.number) {
checkpoints[position - 1] = encodeCheckpoint(fromBlock, SafeCast.toUint128(newShares));
return (oldShares, newShares);
}
}
checkpoints.push(encodeCheckpoint(SafeCast.toUint128(block.number), SafeCast.toUint128(newShares)));
}
/// @notice Encodes a checkpoint into a uint256 [blockNumber, shares]
/// @param blockNumber The block number of the checkpoint
/// @param shares The shares of the checkpoint
/// @return The encoded checkpoint
function encodeCheckpoint(uint128 blockNumber, uint128 shares) public pure returns (uint256) {
return (uint256(blockNumber) << 128) | uint256(shares);
}
/// @notice Decodes a checkpoint from a uint256 [blockNumber, shares]
/// @param checkpoint The checkpoint to decode
/// @return blockNumber The block number of the checkpoint
function decodeCheckpoint(uint256 checkpoint) public pure returns (uint128 blockNumber, uint128 shares) {
blockNumber = decodeBlockNumber(checkpoint);
shares = decodeShares(checkpoint);
}
/// @notice Decodes a checkpoint into a uint128 blockNumber
/// @param checkpoint The checkpoint to decode
/// @return The decoded block number
function decodeBlockNumber(uint256 checkpoint) internal pure returns (uint128) {
return uint128(checkpoint >> 128);
}
/// @notice Decodes a checkpoint into a uint128 shares
/// @param checkpoint The checkpoint to decode
/// @return The decoded share
function decodeShares(uint256 checkpoint) internal pure returns (uint128) {
return uint128(checkpoint);
}
/// @notice Get number of checkpoints for `account`.
/// @param user The address of the account to check
/// @param trend The trend to check
/// @return The number of checkpoints for `account`
function checkpointsLength(address user, bytes32 trend) public view virtual returns (uint256) {
return _checkpoints[user][trend].length;
}
/// @notice Get number of checkpoints for `account` and `trend`.
/// @param blockNumber The block number to get the checkpoint at
/// @param trend The trend to check
/// @return The total supply of the trend at the given block number
function getPastTotalSupply(uint256 blockNumber, bytes32 trend) public view returns (uint128) {
return readCheckpoint(_trendSupplyCheckpoints[trend], blockNumber);
}
/// @notice Gets the checkpoint for a user and trend at a given block number
/// @param user The address of the account to check
/// @param trend The trend to check
/// @param blockNumber The block number to get the checkpoint at
function getPastShares(address user, bytes32 trend, uint256 blockNumber) public view returns (uint128) {
return readCheckpoint(_checkpoints[user][trend], blockNumber);
}
/// @notice Adds two numbers, reverts on overflow.
/// @param a The first number to add.
/// @param b The second number to add.
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/// @notice Subtracts two numbers, reverts on overflow (i.
/// @param a The first number to subtract.
/// @param b The second number to subtract.
function subtract(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
/// @title ICheckpoints
/// @notice Interface for the Checkpoints contract, which stores checkpoints of share balances for each user and trend
interface ICheckpoints {
/// @notice Emitted when a user's shares change
/// @param user The address of the user
/// @param trend The trend of the shares
/// @param previousBalance The previous balance of the user
/// @param newBalance The new balance of the user
event SharesChanged(address user, bytes32 trend, uint256 previousBalance, uint256 newBalance);
/// @notice Thrown when the block number is not mined yet
error BlockNumberNotFoundYet();
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
interface IReferrals {
enum CodeState {
INVALID,
VALID,
USED
}
struct ReferralCode {
CodeState state;
address owner;
}
struct ReferralData {
uint256 startDate; // the date when the referral was created
address referrer; // the addres who refers someone
address referee; // the address who is being referred
}
struct UsedCodes {
string code;
bool used;
}
struct FullReferralData {
uint256 amountOfReferee;
uint256 canRenewCodesAt;
ReferralData referralData;
UsedCodes[] codes;
}
event RegisteredReferer(address referee, address referrer);
error NotRegistered();
error InvalidReferralCode();
error OnlyTrendsMarketAllowed();
error ReferralCodeAlreadyUsed();
error CannotRenewReferralCodesYet();
error RefereeAlreadyHasReferrer(address referee, address referrer);
function register(address referee, string calldata code) external;
function getReferrer(address user) external view returns (address);
function getReferral(address user) external view returns (ReferralData memory);
function getFullReferralData() external view returns (FullReferralData memory);
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
/// @title ITrendMarkets
/// @notice Interface for the TrendMarkets contract, which allows users to buy and sell shares of trends
interface ITrendMarkets {
struct Checkpoint {
uint128 blockNumber;
uint128 shares;
}
/// @notice Emitted when a trade is executed
/// @param trader The address of the trader
/// @param trend The trend of the trade
/// @param isBuy Whether the trade is a buy or sell
/// @param shareAmount The amount of shares traded
/// @param ethAmount The amount of ETH sent
/// @param protocolEthAmount The amount of ETH sent to the protocol
/// @param dailyPotEthAmount The amount of ETH sent to the daily pot
/// @param supply The new supply of shares
event Trade(
address trader,
bytes32 trend,
bool isBuy,
uint256 shareAmount,
uint256 ethAmount,
uint256 protocolEthAmount,
uint256 dailyPotEthAmount,
uint256 supply
);
/// @notice Emitted when a referral fee is received
/// @param referrer The address of the referrer
/// @param amount The amount of ETH received
event ReferralFeeReceived(address referrer, uint256 amount);
/// @notice Emitted when a trend is enabled
/// @param trendName The trend name
/// @param trendHash The hash of the trend name
event TrendEnabled(string trendName, bytes32 trendHash);
/// @notice Emitted when top trends are set
/// @param trendsNames The hashes of the trends name
/// @param trendsHashes The hashes of the trends name
/// @param timestamp The trend name
event TopTrendsEnabled(string[] trendsNames, bytes32[] trendsHashes, uint256 timestamp);
/// @notice Emitted when a payout is processed
/// @param amount The amount of ETH sent
/// @param txHash The hash of the transaction
/// @param timestamp The timestamp of the payout
event PayoutProcessed(uint256 amount, bytes32 txHash, uint256 timestamp);
/// @notice The price of a share based on the supply and amount
function getPrice(uint256 supply, uint256 amount) external returns (uint256);
/// @notice The price to buy a share based on the supply and amount
function getBuyPrice(bytes32 trend, uint256 amount) external view returns (uint256);
/// @notice The price to sell a share based on the supply and amount
function getSellPrice(bytes32 trend, uint256 amount) external view returns (uint256);
/// @notice Used to buy shares of a trend with ETH
function buyShares(bytes32 trend, uint256 amount, address offChainReferrer) external payable;
/// @notice Used to sell shares of a trend for ETH
function sellShares(bytes32 trend, uint256 amount, address offChainReferrer) external payable;
/// @notice Thrown when the trend is not enabled
error TrendNotEnabled();
/// @notice Thrown when there are not enough shares to sell
error NotEnoughSharesToSell();
/// @notice Thrown when the user doesn't have enough shares to sell
error InsufficientSharesBalance();
/// @notice Thrown when the funds are not sent
error FundsNotSent();
/// @notice Thrown when the payment is insufficient
error InsufficientPayment();
/// @notice Thrown when the user isn't referred
error UserNotReferred();
/// @notice Thrown when the fee percent is too high
error FeePercentTooHigh();
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Muldiv operation overflow.
*/
error MathOverflowedMulDiv();
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an overflow flag.
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @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 towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
return a / b;
}
// (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 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
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.
if (denominator <= prod1) {
revert MathOverflowedMulDiv();
}
///////////////////////////////////////////////
// 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.
uint256 twos = denominator & (0 - denominator);
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 (unsignedRoundsUp(rounding) && 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
* towards zero.
*
* 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 + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* 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 + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* 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 + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* 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 + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { ITrendMarkets } from "./interfaces/ITrendMarkets.sol";
import { IReferrals } from "./interfaces/IReferrals.sol";
import { Checkpoints } from "./Checkpoints.sol";
/*
_________ _______ _______ _ ______ _______
\__ __/( ____ )( ____ \( ( /|( __ \ ( ____ \
) ( | ( )|| ( \/| \ ( || ( \ )| ( \/
| | | (____)|| (__ | \ | || | ) || (_____
| | | __)| __) | (\ \) || | | |(_____ )
| | | (\ ( | ( | | \ || | ) | ) |
| | | ) \ \__| (____/\| ) \ || (__/ )/\____) |
)_( |/ \__/(_______/|/ )_)(______/ \_______)
_______ _______ _______ _ _______ _________
( )( ___ )( ____ )| \ /\( ____ \\__ __/
| () () || ( ) || ( )|| \ / /| ( \/ ) (
| || || || (___) || (____)|| (_/ / | (__ | |
| |(_)| || ___ || __)| _ ( | __) | |
| | | || ( ) || (\ ( | ( \ \ | ( | |
| ) ( || ) ( || ) \ \__| / \ \| (____/\ | |
|/ \||/ \||/ \__/|_/ \/(_______/ )_(
*/
/// @title TrendMarkets
/// @notice Contract for buying and selling shares of trends
contract TrendMarkets is ITrendMarkets, Checkpoints, Ownable {
uint256 public protocolFeePercent;
uint256 public dailyPotFeePercent;
bool public referralFeesEnabled;
bool public gatekeepingEnabled;
bool public offChainReferralsEnabled;
address public referralSystem;
address public protocolFeeDestination;
address public dailyPotFeeDestination;
mapping(bytes32 trend => uint256 supply) public sharesSupply;
mapping(address user => uint256 earnings) public referralEarnings;
mapping(bytes32 trend => mapping(address user => uint256 balance)) public sharesBalance;
/// @dev Emits a {OwnershipTransferred} event.
/// @param _protocolFeePercent The new protocol fee percent
/// @param _dailyPotFeePercent The new daily pot fee percent
/// @param _protocolFeeDestination The new protocol fee destination
/// @param _dailyPotFeeDestination The new daily pot fee destination
constructor(
uint256 _protocolFeePercent,
uint256 _dailyPotFeePercent,
address _referralSystem,
address _protocolFeeDestination,
address _dailyPotFeeDestination
) Ownable(msg.sender) {
protocolFeePercent = _protocolFeePercent;
dailyPotFeePercent = _dailyPotFeePercent;
referralSystem = _referralSystem;
protocolFeeDestination = _protocolFeeDestination;
dailyPotFeeDestination = _dailyPotFeeDestination;
gatekeepingEnabled = true;
referralFeesEnabled = true;
offChainReferralsEnabled = false;
}
/// @notice Set the address to send the protocol fee to
/// @param _feeDestination The address to send the protocol fee to
function setFeeDestination(address _feeDestination) public onlyOwner {
protocolFeeDestination = _feeDestination;
}
/// @notice Set the address to send the daily pot fee to
/// @param _feeDestination The address to send the daily pot fee to
function setDailyPotFeeDestination(address _feeDestination) public onlyOwner {
dailyPotFeeDestination = _feeDestination;
}
/// @notice Set the protocol fee percent
/// @param _feePercent The new protocol fee percent
function setProtocolFeePercent(uint256 _feePercent) public onlyOwner {
// the fee percent should be between 0 and 15%
if (_feePercent > 150000000000000000) {
revert FeePercentTooHigh();
}
protocolFeePercent = _feePercent;
}
/// @notice Set the daily pot fee percent
/// @param _feePercent The new daily pot fee percent
function setDailyPotFeePercent(uint256 _feePercent) public onlyOwner {
// the fee percent should be between 0 and 15%
if (_feePercent > 150000000000000000) {
revert FeePercentTooHigh();
}
dailyPotFeePercent = _feePercent;
}
/// @notice Toggles the gatekeeping status
function toggleGatekeeping() public onlyOwner {
gatekeepingEnabled = !gatekeepingEnabled;
}
/// @notice Toggles the referral fees status
function toggleReferralFees() public onlyOwner {
referralFeesEnabled = !referralFeesEnabled;
}
function toggleOffChainReferrals() public onlyOwner {
offChainReferralsEnabled = !offChainReferralsEnabled;
}
/// @notice Set the referral system address
/// @param _referralSystem The new referral system address
function setReferralSystemAddress(address _referralSystem) public onlyOwner {
referralSystem = _referralSystem;
}
/// @notice Enable a trend to be traded
/// @param trendsNames Array of trend names to enable
/// @param trendsHashes Array of trend hashes to enable
function enableTrends(string[] calldata trendsNames, bytes32[] calldata trendsHashes) public onlyOwner {
for (uint256 i = 0; i < trendsHashes.length; i++) {
// if the trend is already enabled, skip it
if (sharesSupply[trendsHashes[i]] != 0) {
continue;
}
sharesSupply[trendsHashes[i]] = 1;
emit TrendEnabled(trendsNames[i], trendsHashes[i]);
}
}
/// @notice Sets the top trends to be traded
/// @param trendsNames Array of trend names to enable
/// @param trendsHashes Array of trend hashes to enable
function enableTopTrends(string[] calldata trendsNames, bytes32[] calldata trendsHashes) public onlyOwner {
emit TopTrendsEnabled(trendsNames, trendsHashes, block.timestamp);
enableTrends(trendsNames, trendsHashes);
}
/// @notice Called when the payout is processed
/// @param amount The amount of ETH sent
/// @param txHash The hash of the transaction
function payoutProcessed(uint256 amount, bytes32 txHash) public onlyOwner {
emit PayoutProcessed(amount, txHash, block.timestamp);
}
/// @notice Get trend supplies for multiple trends
/// @param trends The trends to get the supplies of
/// @return supplies The supplies of the trends
function getShareSupplies(bytes32[] calldata trends) public view returns (uint256[] memory) {
uint256[] memory supplies = new uint[](trends.length);
for (uint256 i = 0; i < trends.length; i++) {
supplies[i] = sharesSupply[trends[i]];
}
return supplies;
}
/// @notice The price of a share is calculated as follows:
/// linear = 0.001 + (N - 1) * 0.0001
/// tier1 = if (N > 10, 0.00015 * (N - 10), 0)
/// tier2 = if (N > 100, 0.0002 * (N - 100), 0)
/// tier3 = if (N > 500, 0.00025 * (N - 500), 0)
/// price = linear + tier1 + tier2 + tier3
/// @param supply The current supply of shares
/// @param amount The amount of shares to buy or sell
function getPrice(uint256 supply, uint256 amount) public pure returns (uint256) {
uint256 price = 0;
for (uint256 share = supply + 1; share <= supply + amount; share++) {
price += 0.001 ether + (share - 1) * 0.0001 ether;
if (share > 10) {
price += 0.00015 ether * (share - 10);
}
if (share > 100) {
price += 0.0002 ether * (share - 100);
}
if (share > 500) {
price += 0.00025 ether * (share - 500);
}
}
return price;
}
/// @notice Get the buy price of a share
/// @param trend The trend to get the price of
/// @param amount The amount of shares to buy
function getBuyPrice(bytes32 trend, uint256 amount) public view returns (uint256) {
return getPrice(sharesSupply[trend], amount);
}
/// @notice Get the sell price of a share
/// @param trend The trend to get the price of
/// @param amount The amount of shares to sell
function getSellPrice(bytes32 trend, uint256 amount) public view returns (uint256) {
return getPrice(sharesSupply[trend] - amount, amount);
}
/// @notice Get the buy price of a share after fees
/// @param trend The trend to get the price of
/// @param amount The amount of shares to buy
function getBuyPriceAfterFee(bytes32 trend, uint256 amount) public view returns (uint256) {
uint256 price = getBuyPrice(trend, amount);
uint256 protocolFee = (price * protocolFeePercent) / 1 ether;
uint256 dailyPotFee = (price * dailyPotFeePercent) / 1 ether;
return price + protocolFee + dailyPotFee;
}
/// @notice Get the sell price of a share after fees
/// @param trend The trend to get the price of
/// @param amount The amount of shares to sell
function getSellPriceAfterFee(bytes32 trend, uint256 amount) public view returns (uint256) {
uint256 price = getSellPrice(trend, amount);
uint256 protocolFee = (price * protocolFeePercent) / 1 ether;
uint256 dailyPotFee = (price * dailyPotFeePercent) / 1 ether;
return price - protocolFee - dailyPotFee;
}
/// @notice Buy shares
/// @param trend The trend to buy shares of
/// @param amount The amount of shares to buy
function buyShares(bytes32 trend, uint256 amount, address offChainReferrer) public payable {
address referrer = getReferrer(offChainReferrer);
uint256 supply = sharesSupply[trend];
if (supply == 0) {
revert TrendNotEnabled();
}
uint256 price = getPrice(supply, amount);
uint256 protocolFee = (price * protocolFeePercent) / 1 ether;
uint256 dailyPotFee = (price * dailyPotFeePercent) / 1 ether;
if (msg.value != price + protocolFee + dailyPotFee) {
revert InsufficientPayment();
}
sharesBalance[trend][msg.sender] = sharesBalance[trend][msg.sender] + amount;
sharesSupply[trend] = supply + amount;
writeCheckpoint(_checkpoints[msg.sender][trend], add, amount);
emit Trade(msg.sender, trend, true, amount, price, protocolFee, dailyPotFee, supply + amount);
emit SharesChanged(msg.sender, trend, amount, supply + amount);
uint256 remainingProtocolFee = handleReferralFees(protocolFee, referrer);
(bool success1, ) = protocolFeeDestination.call{ value: remainingProtocolFee }("");
(bool success2, ) = dailyPotFeeDestination.call{ value: dailyPotFee }("");
if (!(success1 && success2)) {
revert FundsNotSent();
}
}
/// @notice Sell shares
/// @param trend The trend to sell shares of
/// @param amount The amount of shares to sell
function sellShares(bytes32 trend, uint256 amount, address offChainReferrer) public payable {
address referrer = getReferrer(offChainReferrer);
uint256 supply = sharesSupply[trend];
if (amount >= supply) {
revert NotEnoughSharesToSell();
}
uint256 price = getPrice(supply - amount, amount);
uint256 protocolFee = (price * protocolFeePercent) / 1 ether;
uint256 dailyPotFee = (price * dailyPotFeePercent) / 1 ether;
// the subtraction should fail if the user doesn't have enough shares but check it anyway :)
if (sharesBalance[trend][msg.sender] < amount) {
revert InsufficientSharesBalance();
}
sharesBalance[trend][msg.sender] = sharesBalance[trend][msg.sender] - amount;
sharesSupply[trend] = supply - amount;
writeCheckpoint(_checkpoints[msg.sender][trend], subtract, amount);
emit Trade(msg.sender, trend, false, amount, price, protocolFee, dailyPotFee, supply - amount);
emit SharesChanged(msg.sender, trend, amount, supply + amount);
uint256 remainingProtocolFee = handleReferralFees(protocolFee, referrer);
(bool success1, ) = msg.sender.call{ value: price - protocolFee - dailyPotFee }("");
(bool success2, ) = protocolFeeDestination.call{ value: remainingProtocolFee }("");
(bool success3, ) = dailyPotFeeDestination.call{ value: dailyPotFee }("");
if (!(success1 && success2 && success3)) {
revert FundsNotSent();
}
}
function getReferrer(address offChainReferrer) private view returns (address referrer) {
referrer = IReferrals(referralSystem).getReferrer(msg.sender);
if (offChainReferrer != address(0) && offChainReferralsEnabled) {
referrer = offChainReferrer;
}
// gatekeeping is checked only for on-chain referrals
else if (gatekeepingEnabled && referrer == address(0)) {
revert UserNotReferred();
}
}
function handleReferralFees(uint256 protocolFee, address referrer) private returns (uint256 fee) {
fee = protocolFee;
if (referralFeesEnabled && referrer != address(0)) {
fee = protocolFee / 2;
(bool success3, ) = referrer.call{ value: fee }("");
if (success3) {
referralEarnings[referrer] += fee;
emit ReferralFeeReceived(referrer, fee);
}
}
}
}
{
"compilationTarget": {
"contracts/TrendMarkets.sol": "TrendMarkets"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "none",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 800
},
"remappings": []
}
[{"inputs":[{"internalType":"uint256","name":"_protocolFeePercent","type":"uint256"},{"internalType":"uint256","name":"_dailyPotFeePercent","type":"uint256"},{"internalType":"address","name":"_referralSystem","type":"address"},{"internalType":"address","name":"_protocolFeeDestination","type":"address"},{"internalType":"address","name":"_dailyPotFeeDestination","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"BlockNumberNotFoundYet","type":"error"},{"inputs":[],"name":"FeePercentTooHigh","type":"error"},{"inputs":[],"name":"FundsNotSent","type":"error"},{"inputs":[],"name":"InsufficientPayment","type":"error"},{"inputs":[],"name":"InsufficientSharesBalance","type":"error"},{"inputs":[],"name":"NotEnoughSharesToSell","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[{"internalType":"uint8","name":"bits","type":"uint8"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"SafeCastOverflowedUintDowncast","type":"error"},{"inputs":[],"name":"TrendNotEnabled","type":"error"},{"inputs":[],"name":"UserNotReferred","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"txHash","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"PayoutProcessed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"referrer","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ReferralFeeReceived","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"bytes32","name":"trend","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"previousBalance","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newBalance","type":"uint256"}],"name":"SharesChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string[]","name":"trendsNames","type":"string[]"},{"indexed":false,"internalType":"bytes32[]","name":"trendsHashes","type":"bytes32[]"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"TopTrendsEnabled","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"trader","type":"address"},{"indexed":false,"internalType":"bytes32","name":"trend","type":"bytes32"},{"indexed":false,"internalType":"bool","name":"isBuy","type":"bool"},{"indexed":false,"internalType":"uint256","name":"shareAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"ethAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"protocolEthAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"dailyPotEthAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"supply","type":"uint256"}],"name":"Trade","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"trendName","type":"string"},{"indexed":false,"internalType":"bytes32","name":"trendHash","type":"bytes32"}],"name":"TrendEnabled","type":"event"},{"inputs":[{"internalType":"bytes32","name":"trend","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"offChainReferrer","type":"address"}],"name":"buyShares","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"bytes32","name":"trend","type":"bytes32"}],"name":"checkpointsLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"dailyPotFeeDestination","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"dailyPotFeePercent","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"checkpoint","type":"uint256"}],"name":"decodeCheckpoint","outputs":[{"internalType":"uint128","name":"blockNumber","type":"uint128"},{"internalType":"uint128","name":"shares","type":"uint128"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"string[]","name":"trendsNames","type":"string[]"},{"internalType":"bytes32[]","name":"trendsHashes","type":"bytes32[]"}],"name":"enableTopTrends","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string[]","name":"trendsNames","type":"string[]"},{"internalType":"bytes32[]","name":"trendsHashes","type":"bytes32[]"}],"name":"enableTrends","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint128","name":"blockNumber","type":"uint128"},{"internalType":"uint128","name":"shares","type":"uint128"}],"name":"encodeCheckpoint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"gatekeepingEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"trend","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"getBuyPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"trend","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"getBuyPriceAfterFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"bytes32","name":"trend","type":"bytes32"},{"internalType":"uint256","name":"blockNumber","type":"uint256"}],"name":"getPastShares","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"blockNumber","type":"uint256"},{"internalType":"bytes32","name":"trend","type":"bytes32"}],"name":"getPastTotalSupply","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"supply","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"getPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes32","name":"trend","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"getSellPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"trend","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"getSellPriceAfterFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32[]","name":"trends","type":"bytes32[]"}],"name":"getShareSupplies","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"offChainReferralsEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes32","name":"txHash","type":"bytes32"}],"name":"payoutProcessed","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"protocolFeeDestination","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"protocolFeePercent","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"referralEarnings","outputs":[{"internalType":"uint256","name":"earnings","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"referralFeesEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"referralSystem","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"trend","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"offChainReferrer","type":"address"}],"name":"sellShares","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_feeDestination","type":"address"}],"name":"setDailyPotFeeDestination","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_feePercent","type":"uint256"}],"name":"setDailyPotFeePercent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_feeDestination","type":"address"}],"name":"setFeeDestination","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_feePercent","type":"uint256"}],"name":"setProtocolFeePercent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_referralSystem","type":"address"}],"name":"setReferralSystemAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"trend","type":"bytes32"},{"internalType":"address","name":"user","type":"address"}],"name":"sharesBalance","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"trend","type":"bytes32"}],"name":"sharesSupply","outputs":[{"internalType":"uint256","name":"supply","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"toggleGatekeeping","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"toggleOffChainReferrals","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"toggleReferralFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]