ETH Price: $2,950.97 (-0.06%)

Contract

0x7D6857b6303e39a532482ec89409D9bca7B06f67

Overview

ETH Balance

0 ETH

ETH Value

$0.00

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Block
From
To

There are no matching entries

Please try again later

View more zero value Internal Transactions in Advanced View mode

Advanced mode:

Cross-Chain Transactions
Loading...
Loading

Similar Match Source Code
This contract matches the deployed Bytecode of the Source Code for Contract 0xDa4cf387...4A7008A4d
The constructor portion of the code might be different and could alter the actual behaviour of the contract

Contract Name:
VestingCalculator

Compiler Version
v0.8.27+commit.40a35a09

Optimization Enabled:
Yes with 5 runs

Other Settings:
paris EvmVersion

Contract Source Code (Solidity Standard Json-Input format)

// SPDX-License-Identifier: UNLICENSED
// ALL RIGHTS RESERVED
// UNCX by SDDTech reserves all rights on this code. You may not copy these contracts.

pragma solidity ^0.8.27;

import "@openzeppelin/contracts/utils/math/Math.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./interfaces/IVestingCalculator.sol";

/**
 * @title VestingCalculator
 * @dev Contract for calculating vesting schedules with different vesting types (linear, exponential, interval)
 * @notice This contract handles the logic for computing vested token amounts based on various vesting schedules
 */
contract VestingCalculator is IVestingCalculator {
    using Math for uint256;

   

    constructor() {
       
    }

     


    /**
     * @dev Validates the time-amount pairs for a vesting schedule
     * @param tranches Array of time-amount pairs to validate
     */
    function _validateTranches(TimeAmount[] calldata tranches) internal pure {
        // First check if we have at least 2 tranches
        if (tranches.length < 2) revert InvalidTranches();


        // Then validate the sequence
        for (uint256 i = 1; i < tranches.length; i++) {
            if (tranches[i].time <= tranches[i-1].time) {
                revert TimesMustBeInAscendingOrder();
            }
            if (tranches[i].amount < tranches[i-1].amount) {
                revert AmountsMustBeIncreasing();
            }
        }
    }


    /**
     * @dev Calculates the vested amount at a specific time
     * @param tranches Array of time-amount pairs defining the vesting schedule
     * @param currentTime The timestamp to calculate vested amount for
     * @return The amount vested at the specified time
     */
    function calculateVestedAmount(
        TimeAmount[] calldata tranches,
        uint256 currentTime
    ) public view returns (uint256) {
        // Then validate other tranche properties
        _validateTranches(tranches);

        // Before first tranche
        if (currentTime <= tranches[0].time) {
            return 0;
        }

        // After last tranche
        if (currentTime >= tranches[tranches.length - 1].time) {
            return tranches[tranches.length - 1].amount;
        }

        return _calculateVestingForPeriod(tranches, currentTime);
    }

    /**
     * @dev Internal function to calculate vesting amount for a specific period
     * @param tranches Array of time-amount pairs
     * @param currentTime The timestamp to calculate vested amount for
     * @return The vested amount for the period
     */
    function _calculateVestingForPeriod(
        TimeAmount[] calldata tranches,
        uint256 currentTime
    ) internal view returns (uint256) {
        // Find the relevant tranche
        uint256 i;
        for (i = 1; i < tranches.length; i++) {
            if (currentTime <= tranches[i].time) {
                break;
            }
        }

        uint256 startTime = tranches[i - 1].time;
        uint256 endTime = tranches[i].time;
        uint256 startAmount = tranches[i - 1].amount;
        uint256 endAmount = tranches[i].amount;
        EquationType eqType = tranches[i - 1].eqType;

        if (eqType == EquationType.LINEAR) {
            return _calculateLinearVesting(
                startTime,
                endTime,
                startAmount,
                endAmount,
                currentTime
            );
        } else if (eqType == EquationType.EXPONENTIAL) {
            return _calculateExponentialVesting(
                startTime,
                endTime,
                startAmount,
                endAmount,
                currentTime,
                2e18
            );
        } else if (eqType == EquationType.INTERVAL) {
            return endAmount;
        } else if (eqType == EquationType.QUADRATIC) {
            return _calculateQuadraticVesting(
                startTime,
                endTime,
                startAmount,
                endAmount,
                currentTime
            );
        } else {
            revert InvalidEquationType();
        }
    }

    /**
     * @dev Calculates vested amount using linear vesting formula
     * @param startTime Start time of the vesting period
     * @param endTime End time of the vesting period
     * @param startAmount Amount at start of period
     * @param endAmount Amount at end of period
     * @param currentTime Current timestamp
     * @return The linearly vested amount
     */
    function _calculateLinearVesting(
        uint256 startTime,
        uint256 endTime,
        uint256 startAmount,
        uint256 endAmount,
        uint256 currentTime
    ) internal pure returns (uint256) {
        uint256 timeElapsed = currentTime - startTime;
        uint256 totalDuration = endTime - startTime;
        uint256 amountDiff = endAmount - startAmount;

        // Calculate progress with 1e18 precision
        uint256 progress = (timeElapsed * 1e18) / totalDuration;
        
        // Calculate vested amount using the high precision progress
        uint256 vestedDiff = (amountDiff * progress) / 1e18;
        
        return startAmount + vestedDiff;
    }

    /**
     * @dev Calculates vested amount using exponential vesting formula
     * @param startTime Start time of the vesting period
     * @param endTime End time of the vesting period
     * @param startAmount Amount at start of period
     * @param endAmount Amount at end of period
     * @param currentTime Current timestamp
     * @param exponent Exponent for the vesting curve
     * @return The exponentially vested amount
     */
    function _calculateExponentialVesting(
        uint256 startTime,
        uint256 endTime,
        uint256 startAmount,
        uint256 endAmount,
        uint256 currentTime,
        uint256 exponent
    ) internal pure returns (uint256) {
        uint256 timeElapsed = currentTime - startTime;
        uint256 totalDuration = endTime - startTime;
        uint256 amountDiff = endAmount - startAmount;

        uint256 timeProgress = (timeElapsed * 1e18) / totalDuration;
        
        // Calculate timeProgress^exponent with better precision
        uint256 expProgress = timeProgress;
        uint256 scaledExponent = exponent / 1e18;
        
        // Handle exponent = 1 case separately
        if (scaledExponent == 1) {
            return startAmount + (amountDiff * timeProgress) / 1e18;
        }
        
        // For exponents > 1, calculate power iteratively
        for (uint256 i = 1; i < scaledExponent; i++) {
            expProgress = (expProgress * timeProgress) / 1e18;
        }

        return startAmount + (amountDiff * expProgress) / 1e18;
    }

    /**
     * @dev Calculates vested amount using quadratic vesting formula
     * @param startTime Start time of the vesting period
     * @param endTime End time of the vesting period
     * @param startAmount Amount at start of period
     * @param endAmount Amount at end of period
     * @param currentTime Current timestamp
     * @return The quadratically vested amount
     */
    function _calculateQuadraticVesting(
        uint256 startTime,
        uint256 endTime,
        uint256 startAmount,
        uint256 endAmount,
        uint256 currentTime
    ) internal pure returns (uint256) {
        // Redirect to exponential with n=2
        return _calculateExponentialVesting(
            startTime,
            endTime,
            startAmount,
            endAmount,
            currentTime,
            2e18  // Quadratic is just exponential with n=2
        );
    }

    /**
     * @dev Gets the total amount to be vested
     * @param tranches Array of time-amount pairs defining the vesting schedule
     * @return The total amount to be vested
     */
    function getTotalAmount(TimeAmount[] calldata tranches) public pure returns (uint256) {
        _validateTranches(tranches);
        return tranches[tranches.length - 1].amount;
    }
}

// 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) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @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 value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the value of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` 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 value) external returns (bool);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (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;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

// 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;
    }
}

File 6 of 7 : IVesting.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IVesting {
    enum VestingType {
        NORMAL
        // Removed DAILY_SOFT, WEEKLY_SOFT, MONTHLY_SOFT since they're just NORMAL with specific tranches
    }
    
    error NoTokensToRelease();
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;

import "./IVesting.sol";

interface IVestingCalculator {
    enum EquationType {
        LINEAR,      // Linear release between points
        EXPONENTIAL, // Exponential curve between points
        INTERVAL,    // Immediate release at each point (same as STEPWISE)
        QUADRATIC    // Quadratic curve between points
    }

    struct TimeAmount {
        uint256 time;        // Unix timestamp
        uint256 amount;      // Cumulative amount of tokens until this time
        EquationType eqType; // Equation type for calculation until next point
    }
    
    error InvalidTranches();
    error TimesMustBeInAscendingOrder();
    error AmountsMustBeIncreasing();
    error InvalidEquationType();
    error InvalidParameters();
    error VestingTypeNotEnabled();

    function calculateVestedAmount(
        TimeAmount[] calldata tranches,
        uint256 currentTime
    ) external view returns (uint256);

    function getTotalAmount(TimeAmount[] calldata tranches) external pure returns (uint256);

}

Settings
{
  "viaIR": true,
  "optimizer": {
    "enabled": true,
    "runs": 5
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "paris",
  "libraries": {}
}

Contract Security Audit

Contract ABI

API
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AmountsMustBeIncreasing","type":"error"},{"inputs":[],"name":"InvalidEquationType","type":"error"},{"inputs":[],"name":"InvalidParameters","type":"error"},{"inputs":[],"name":"InvalidTranches","type":"error"},{"inputs":[],"name":"TimesMustBeInAscendingOrder","type":"error"},{"inputs":[],"name":"VestingTypeNotEnabled","type":"error"},{"inputs":[{"components":[{"internalType":"uint256","name":"time","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"enum IVestingCalculator.EquationType","name":"eqType","type":"uint8"}],"internalType":"struct IVestingCalculator.TimeAmount[]","name":"tranches","type":"tuple[]"},{"internalType":"uint256","name":"currentTime","type":"uint256"}],"name":"calculateVestedAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"time","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"enum IVestingCalculator.EquationType","name":"eqType","type":"uint8"}],"internalType":"struct IVestingCalculator.TimeAmount[]","name":"tranches","type":"tuple[]"}],"name":"getTotalAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"}]

0x608080604052346015576104ac908161001b8239f35b600080fdfe6080604052600436101561001257600080fd5b60003560e01c806314f2a3f61461007d5763eaa904851461003257600080fd5b34610078576040366003190112610078576004356001600160401b0381116100785761007061006760209236906004016100f2565b60243591610155565b604051908152f35b600080fd5b34610078576020366003190112610078576004356001600160401b038111610078576100ad9036906004016100f2565b6100b781836101b7565b6000198101918183116100dc5760209283926100d29261012f565b0135604051908152f35b634e487b7160e01b600052601160045260246000fd5b9181601f84011215610078578235916001600160401b038311610078576020808501946060850201011161007857565b919082039182116100dc57565b919081101561013f576060020190565b634e487b7160e01b600052603260045260246000fd5b919061016181846101b7565b801561013f5782358211156101af5760001981018181116100dc5761018781838661012f565b3583101561019c575061019992610258565b90565b906101aa925060209361012f565b013590565b505050600090565b600282106102475760015b8281106101ce57505050565b6101d981848461012f565b600019820190358282116100dc576101f282868661012f565b35101561023657602061020683868661012f565b01356020610217600093878761012f565b01351161022757506001016101c2565b6370c0fcdd60e11b8152600490fd5b630bc7fb5960e21b60005260046000fd5b6304be90a960e51b60005260046000fd5b916001915b808310610388575b6000198301918383116100dc5760406102ba848460206102b2816102a885856102a18f9d8f909d8f9e8f908261029a9261012f565b359e61012f565b359c61012f565b013599838c61012f565b01359861012f565b013560048110156100785760008161032f5750506102e0826102e06102e6948794610122565b94610122565b92670de0b6b3a7640000820291808304670de0b6b3a764000014901517156100dc576101999361032261032892670de0b6b3a7640000946103be565b906103ab565b04906103de565b5094909390929091600186036103495761019995506103eb565b9392946000600282146000146103625750505050505090565b509394929360030361037757610199946103eb565b630ffe8c8f60e31b60005260046000fd5b9161039481848661012f565b358211156103a5576001019161025d565b91610265565b818102929181159184041417156100dc57565b81156103c8570490565b634e487b7160e01b600052601260045260246000fd5b919082018092116100dc57565b916103ff836102e061040594958498610122565b93610122565b91670de0b6b3a7640000820291808304670de0b6b3a764000014901517156100dc57610430916103be565b906001825b600282106104565750506103286101999392670de0b6b3a7640000926103ab565b9092670de0b6b3a764000061046d836001936103ab565b0493019061043556fea2646970667358221220e392db226fb7c6d5c18ac936a02781890f9996bd1d5d753e45af28b700458a0f64736f6c634300081b0033

Deployed Bytecode

0x6080604052600436101561001257600080fd5b60003560e01c806314f2a3f61461007d5763eaa904851461003257600080fd5b34610078576040366003190112610078576004356001600160401b0381116100785761007061006760209236906004016100f2565b60243591610155565b604051908152f35b600080fd5b34610078576020366003190112610078576004356001600160401b038111610078576100ad9036906004016100f2565b6100b781836101b7565b6000198101918183116100dc5760209283926100d29261012f565b0135604051908152f35b634e487b7160e01b600052601160045260246000fd5b9181601f84011215610078578235916001600160401b038311610078576020808501946060850201011161007857565b919082039182116100dc57565b919081101561013f576060020190565b634e487b7160e01b600052603260045260246000fd5b919061016181846101b7565b801561013f5782358211156101af5760001981018181116100dc5761018781838661012f565b3583101561019c575061019992610258565b90565b906101aa925060209361012f565b013590565b505050600090565b600282106102475760015b8281106101ce57505050565b6101d981848461012f565b600019820190358282116100dc576101f282868661012f565b35101561023657602061020683868661012f565b01356020610217600093878761012f565b01351161022757506001016101c2565b6370c0fcdd60e11b8152600490fd5b630bc7fb5960e21b60005260046000fd5b6304be90a960e51b60005260046000fd5b916001915b808310610388575b6000198301918383116100dc5760406102ba848460206102b2816102a885856102a18f9d8f909d8f9e8f908261029a9261012f565b359e61012f565b359c61012f565b013599838c61012f565b01359861012f565b013560048110156100785760008161032f5750506102e0826102e06102e6948794610122565b94610122565b92670de0b6b3a7640000820291808304670de0b6b3a764000014901517156100dc576101999361032261032892670de0b6b3a7640000946103be565b906103ab565b04906103de565b5094909390929091600186036103495761019995506103eb565b9392946000600282146000146103625750505050505090565b509394929360030361037757610199946103eb565b630ffe8c8f60e31b60005260046000fd5b9161039481848661012f565b358211156103a5576001019161025d565b91610265565b818102929181159184041417156100dc57565b81156103c8570490565b634e487b7160e01b600052601260045260246000fd5b919082018092116100dc57565b916103ff836102e061040594958498610122565b93610122565b91670de0b6b3a7640000820291808304670de0b6b3a764000014901517156100dc57610430916103be565b906001825b600282106104565750506103286101999392670de0b6b3a7640000926103ab565b9092670de0b6b3a764000061046d836001936103ab565b0493019061043556fea2646970667358221220e392db226fb7c6d5c18ac936a02781890f9996bd1d5d753e45af28b700458a0f64736f6c634300081b0033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading

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.