Перейти к содержимому
Проверенный контрактТочноеUNLICENSED

LicenseAuction

Адрес0xbb05fa84dbd820a39094286a44e9d760e585a349
Баланс

0 ETH

 

Транзакций

2

 

Компилятор

solc 0.8.26

 

Тот же код

Только этот контракт

 

Подробности

Компилятор
solc 0.8.26+commit.8a97fa7a
Язык
solidity
Оптимизация
Да, 200 прогонов
Версия EVM
cancun
Лицензия
UNLICENSED
Совпадение
Точноекод создания: да, код в сети: да
Проверен на Sourcify
Создан в блоке
26 143 731
Транзакция создания
0x93c1f09ee5…39dacb3b3b

src/ethereum/v3/LicenseAuction.sol

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;
import {AuctionBase, IAuctionBank} from "./AuctionBase.sol";

interface ILicenseCharterOwner { function ownerOf(uint256 id) external view returns (address); }

contract LicenseAuction is AuctionBase {
    error InvalidCount();
    error NotCharterOwner();
    error CharterDailyCapExceeded();
    error SessionCapExceeded();
    event FloorPaybackDaysSet(uint256 days_);
    event LicensesPerDaySet(uint256 count);
    event LicensesPurchased(uint256 indexed charterId, uint256 indexed day, uint256 count, uint256 price);
    event SessionPurchase(uint256 indexed session, uint256 indexed charterId, uint256 count, uint256 price);

    uint256 public constant SESSION_DURATION = 12 hours;
    uint256 public constant LICENSES_PER_DAY_MAX = 2000;
    uint256 public constant FLOOR_PAYBACK_DAYS_MIN = 1;
    uint256 public constant FLOOR_PAYBACK_DAYS_MAX = 45;
    uint256 public constant MAX_PER_CHARTER_PER_DAY = 3;
    uint256 public licensesPerDay = 10;
    uint256 public floorPaybackDays = 2;
    mapping(uint256 => mapping(uint256 => uint256)) public purchasedOnDay;
    mapping(uint256 => uint256) public soldInSession;

    constructor(address bank_, address initialOwner)
        AuctionBase(bank_, IAuctionBank(bank_).registry(), initialOwner, 2)
    {}

    function setFloorPaybackDays(uint256 days_) external onlyOwner onlyBeforeLaunch nonReentrant {
        if (days_ < FLOOR_PAYBACK_DAYS_MIN || days_ > FLOOR_PAYBACK_DAYS_MAX) revert OutOfBounds();
        floorPaybackDays = days_;
        emit FloorPaybackDaysSet(days_);
    }
    function setDecayHalfLife(uint256 halfLife) public override onlyOwner onlyBeforeLaunch nonReentrant {
        _setHalfLife(halfLife);
    }
    function DECAY_HALF_LIFE_MAX() public pure override returns (uint256) { return SESSION_DURATION; }
    function setLicensesPerDay(uint256 count) external onlyBeforeLaunch nonReentrant {
        if (msg.sender != owner && msg.sender != supplyController()) revert NotSupplyAuthority();
        if (count < 2 || count % 2 != 0 || count > LICENSES_PER_DAY_MAX) revert OutOfBounds();
        licensesPerDay = count;
        emit LicensesPerDaySet(count);
    }
    function buyLicenses(uint256 charterId, uint256 count, uint256 maxUnitPrice) external nonReentrant {
        if (paused()) revert ContractPaused();
        if (ILicenseCharterOwner(IAuctionBank(bank).charterNFT()).ownerOf(charterId) != msg.sender) {
            revert NotCharterOwner();
        }
        if (count == 0) revert InvalidCount();
        IAuctionBank(bank).rollover();
        _roll();
        if (count > dayCap - soldToday) revert DailyCapExceeded();
        uint256 session = currentSession();
        if (count > dayCap / 2 - soldInSession[session]) revert SessionCapExceeded();
        uint256 purchased = purchasedOnDay[charterId][currentDay];
        if (purchased + count > MAX_PER_CHARTER_PER_DAY) revert CharterDailyCapExceeded();
        uint256 price = currentPrice();
        if (price > maxUnitPrice) revert PriceAboveMax();
        purchasedOnDay[charterId][currentDay] = purchased + count;
        soldInSession[session] += count;
        _recordSale(price, count);
        IAuctionBank(bank).openBranches(charterId, count, price * count);
        emit LicensesPurchased(charterId, currentDay, count, price);
        emit SessionPurchase(session, charterId, count, price);
    }

    function currentSession() public view returns (uint256) {
        return started ? (block.timestamp - auctionAnchor) / SESSION_DURATION : 0;
    }
    function licensesPerSession() public view returns (uint256) {
        return (started && _day() == currentDay ? dayCap : licensesPerDay) / 2;
    }
    function remainingThisSession() public view returns (uint256) {
        if (!started) return 0;
        return licensesPerSession() - soldInSession[currentSession()];
    }

    function remainingToday() external view override returns (uint256) {
        if (!started) return 0;
        return remainingThisSession() + (currentSession() % 2 == 0 ? licensesPerSession() : 0);
    }

    function currentPrice() public view override returns (uint256) {
        return _priceForDuration(SESSION_DURATION);
    }
    function quote(uint256 count) external view returns (uint256 unitPrice, uint256 totalPrice) {
        unitPrice = currentPrice();
        totalPrice = unitPrice * count;
    }
    function configurationReady() public view override returns (bool) {
        return initialPriceConfigured && !paused() && licensesPerDay >= 2 && licensesPerDay % 2 == 0;
    }
    function _floorPrice() internal view override returns (uint256) {
        uint256 branches = IAuctionBank(bank).totalBranches();
        if (branches == 0) branches = 1;
        uint256 dailyShare = IAuctionBank(bank).multiplierWad()
            * IAuctionBank(bank).baseIssuancePerDay() / 1 ether / branches;
        uint256 floor = dailyShare * floorPaybackDays;
        return floor == 0 ? 1 : floor;
    }
    function _perDay() internal view override returns (uint256) { return licensesPerDay; }
}

src/ethereum/v3/AuctionBase.sol

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;

import {AuctionFixedPointMath as Math} from "./math/AuctionFixedPointMath.sol";
import {IAddressRegistry} from "./IAddressRegistry.sol";

interface IAuctionBank {
    function registry() external view returns (address);
    function emissionsStarted() external view returns (bool);
    function administrationFrozen() external view returns (bool);
    function charterNFT() external view returns (address);
    function totalBranches() external view returns (uint256);
    function multiplierWad() external view returns (uint256);
    function baseIssuancePerDay() external view returns (uint256);
    function rollover() external;
    function openBranches(uint256 charterId, uint256 count, uint256 cost) external;
    function createCharter(address to) external returns (uint256);
}

abstract contract AuctionBase {
    error Unauthorized();
    error InvalidOwner();
    error AlreadyStarted();
    error NotStarted();
    error EmissionsNotStarted();
    error AdministrationFrozen();
    error AuctionNotConfigured();
    error ContractPaused();
    error NotGuardian();
    error NotPaused();
    error NotSupplyAuthority();
    error OutOfBounds();
    error InvalidHalfLife();
    error DailyCapExceeded();
    error PriceAboveMax();
    error Reentrancy();

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
    event AuctionConfigured(uint256 initialPrice);
    event AuctionStarted(uint256 indexed day, uint256 startPrice);
    event DayRolled(uint256 indexed day, uint256 startPrice, uint256 floorPrice, uint256 cap);
    event DecayHalfLifeSet(uint256 halfLife);
    event SupplyControllerSet(address controller);
    event GuardianPaused(address indexed guardian);
    event GuardianUnpaused();

    uint256 public constant AUCTION_DAY = 1 days;

    function DECAY_HALF_LIFE_MAX() public pure virtual returns (uint256) { return 1 days; }
    address public immutable bank;
    address public immutable registry;
    uint256 public immutable startMultiplier;

    address public owner;
    address public pendingOwner;
    uint256 public auctionAnchor;
    uint256 public decayHalfLife;
    bool public started;
    uint256 public currentDay;
    uint256 public dayStartPrice;
    uint256 public dayFloorPrice;
    uint256 public dayHalfLife;
    uint256 public dayCap;
    uint256 public soldToday;
    uint256 public lastSalePrice;
    uint256 public lastSaleDay;
    uint256 public configuredInitialPrice;
    bool public initialPriceConfigured;
    uint256 private _guardStatus = 1;
    bool private _pausedFlag;
    address private _supplyController;

    constructor(address bank_, address registry_, address initialOwner, uint256 multiplier_) {
        if (initialOwner == address(0)) revert InvalidOwner();
        bank = bank_;
        registry = registry_;
        startMultiplier = multiplier_;
        owner = initialOwner;
        emit OwnershipTransferred(address(0), initialOwner);
    }

    modifier onlyOwner() { if (msg.sender != owner) revert Unauthorized(); _; }
    modifier onlyBeforeLaunch() {
        if (IAuctionBank(bank).administrationFrozen()) revert AdministrationFrozen();
        _;
    }
    modifier nonReentrant() {
        if (_guardStatus == 2) revert Reentrancy();
        _guardStatus = 2;
        _;
        _guardStatus = 1;
    }

    function transferOwnership(address next) external onlyOwner onlyBeforeLaunch {
        if (next == address(0)) revert InvalidOwner();
        pendingOwner = next;
        emit OwnershipTransferStarted(owner, next);
    }
    function acceptOwnership() external onlyBeforeLaunch {
        if (msg.sender != pendingOwner) revert Unauthorized();
        emit OwnershipTransferred(owner, msg.sender);
        owner = msg.sender;
        pendingOwner = address(0);
    }
    function renounceOwnership() external onlyOwner onlyBeforeLaunch {
        emit OwnershipTransferred(owner, address(0));
        owner = address(0);
        pendingOwner = address(0);
    }
    function pause() external onlyBeforeLaunch {
        if (msg.sender != _get("GUARDIAN")) revert NotGuardian();
        if (_pausedFlag) revert ContractPaused();
        _pausedFlag = true;
        emit GuardianPaused(msg.sender);
    }
    function unpause() external onlyOwner onlyBeforeLaunch {
        if (!_pausedFlag) revert NotPaused();
        _pausedFlag = false;
        emit GuardianUnpaused();
    }
    function setSupplyController(address controller) external onlyOwner onlyBeforeLaunch {
        _supplyController = controller;
        emit SupplyControllerSet(controller);
    }
    function setDecayHalfLife(uint256 halfLife) public virtual onlyOwner onlyBeforeLaunch {
        _setHalfLife(halfLife);
    }
    function configureInitialPrice(uint256 initialPrice) external onlyOwner onlyBeforeLaunch {
        if (started) revert AlreadyStarted();
        configuredInitialPrice = initialPrice;
        initialPriceConfigured = true;
        emit AuctionConfigured(initialPrice);
    }
    function activate() external nonReentrant {
        if (started) revert AlreadyStarted();
        if (!IAuctionBank(bank).emissionsStarted()) revert EmissionsNotStarted();
        if (!configurationReady()) revert AuctionNotConfigured();
        _start(configuredInitialPrice);
    }
    function paused() public view returns (bool) { return _pausedFlag; }
    function supplyController() public view returns (address) { return _supplyController; }
    function administrationFrozen() public view returns (bool) {
        return IAuctionBank(bank).administrationFrozen();
    }
    function remainingToday() external view virtual returns (uint256) {
        if (!started) return 0;
        if (_day() != currentDay) return _perDay();
        return dayCap - soldToday;
    }
    function currentPrice() public view virtual returns (uint256) {
        return _priceForDuration(AUCTION_DAY);
    }

    function _priceForDuration(uint256 duration) internal view returns (uint256) {
        if (!started) return 0;
        uint256 today = _day();
        uint256 start;
        uint256 floor;
        uint256 halfLife;
        if (today == currentDay) {
            start = dayStartPrice;
            floor = dayFloorPrice;
            halfLife = dayHalfLife;
        } else {
            (start, floor) = _nextDayPrices(today);
            halfLife = decayHalfLife;
        }
        if (start <= floor) return floor;
        uint256 elapsed = (block.timestamp - auctionAnchor) % duration;
        if (halfLife != 0) {
            uint256 halfLifeDecay = uint256(Math.powWad(int256(0.5 ether), int256(elapsed * 1 ether / halfLife)));
            return floor + (start - floor) * halfLifeDecay / 1 ether;
        }
        int256 ratio = int256(floor * 1 ether / start);
        if (ratio <= 0) return floor;
        uint256 decay = uint256(Math.powWad(ratio, int256(elapsed * 1 ether / duration)));
        uint256 price = start * decay / 1 ether;
        return price < floor ? floor : price;
    }

    function _setHalfLife(uint256 halfLife) internal {
        if (halfLife > DECAY_HALF_LIFE_MAX()) revert InvalidHalfLife();
        _rollIfStarted();
        decayHalfLife = halfLife;
        emit DecayHalfLifeSet(halfLife);
    }
    function _start(uint256 initialPrice) internal {
        auctionAnchor = block.timestamp;
        started = true;
        currentDay = 0;
        dayFloorPrice = _floorPrice();
        dayStartPrice = initialPrice > dayFloorPrice ? initialPrice : dayFloorPrice;
        dayHalfLife = decayHalfLife;
        dayCap = _perDay();
        emit AuctionStarted(0, dayStartPrice);
    }
    function _rollIfStarted() internal { if (started) _roll(); }
    function _roll() internal {
        if (!started) revert NotStarted();
        uint256 today = _day();
        if (today == currentDay) return;
        (uint256 start, uint256 floor) = _nextDayPrices(today);
        currentDay = today;
        dayStartPrice = start;
        dayFloorPrice = floor;
        dayHalfLife = decayHalfLife;
        dayCap = _perDay();
        soldToday = 0;
        emit DayRolled(today, start, floor, dayCap);
    }
    function _recordSale(uint256 price, uint256 count) internal {
        soldToday += count;
        lastSalePrice = price;
        lastSaleDay = currentDay;
    }
    function _nextDayPrices(uint256 day) internal view returns (uint256 start, uint256 floor) {
        floor = _floorPrice();
        bool previousDaySale = lastSalePrice != 0 && day == lastSaleDay + 1;
        start = (previousDaySale ? lastSalePrice : floor) * startMultiplier;
        if (start < floor) start = floor;
    }
    function _day() internal view returns (uint256) { return (block.timestamp - auctionAnchor) / AUCTION_DAY; }
    function _get(bytes32 key) internal view returns (address) {
        return IAddressRegistry(registry).get(key);
    }

    function configurationReady() public view virtual returns (bool);
    function _perDay() internal view virtual returns (uint256);
    function _floorPrice() internal view virtual returns (uint256);
}

src/ethereum/v3/IAddressRegistry.sol

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;

interface IAddressRegistry {
    error OwnableUnauthorizedAccount(address account);
    error OwnableInvalidOwner(address owner);
    error KeyIsLocked(bytes32 key);
    error KeyNotSet(bytes32 key);
    error KeyIsSet(bytes32 key);
    error AlreadyOpen();

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
    event AddressSet(bytes32 indexed key, address indexed value);
    event KeyLocked(bytes32 indexed key, address value);
    event ExecutionOpened();

    function owner() external view returns (address);
    function pendingOwner() external view returns (address);
    function transferOwnership(address newOwner) external;
    function acceptOwnership() external;
    function renounceOwnership() external;
    function get(bytes32 key) external view returns (address);
    function set(bytes32 key, address value) external;
    function locked(bytes32 key) external view returns (bool);
    function lock(bytes32 key) external;
    function lockDisabled(bytes32 key) external;
    function executionPermissionless() external view returns (bool);
    function openExecution() external;
}

src/ethereum/v3/math/AuctionFixedPointMath.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

/// @notice Solady fixed-point primitives selected to reproduce deployed auction arithmetic.
/// @dev Authored integration; these are upstream library functions, not recovered protocol Solidity.
/// @author Solady / Vectorized; exp/ln credit Remco Bloemen (MIT).
// Upstream: https://raw.githubusercontent.com/Vectorized/solady/9fe23ffdcd395c4169396064226ed27206b222c3/src/utils/FixedPointMathLib.sol
// Upstream file SHA256: d322e2a0b1f43dbd80a3cf26a40d1ca1cc19cf03737f1e8513485e266b47e9c3
library AuctionFixedPointMath {
    uint256 internal constant WAD = 1e18;

    function powWad(int256 x, int256 y) internal pure returns (int256) {
        // Using `ln(x)` means `x` must be greater than 0.
        return expWad((lnWad(x) * y) / int256(WAD));
    }

    function expWad(int256 x) internal pure returns (int256 r) {
        unchecked {
            // When the result is less than 0.5 we return zero.
            // This happens when `x <= (log(1e-18) * 1e18) ~ -4.15e19`.
            if (x <= -41446531673892822313) return r;

            /// @solidity memory-safe-assembly
            assembly {
                // When the result is greater than `(2**255 - 1) / 1e18` we can not represent it as
                // an int. This happens when `x >= floor(log((2**255 - 1) / 1e18) * 1e18) ≈ 135`.
                if iszero(slt(x, 135305999368893231589)) {
                    mstore(0x00, 0xa37bfec9) // `ExpOverflow()`.
                    revert(0x1c, 0x04)
                }
            }

            // `x` is now in the range `(-42, 136) * 1e18`. Convert to `(-42, 136) * 2**96`
            // for more intermediate precision and a binary basis. This base conversion
            // is a multiplication by 1e18 / 2**96 = 5**18 / 2**78.
            x = (x << 78) / 5 ** 18;

            // Reduce range of x to (-½ ln 2, ½ ln 2) * 2**96 by factoring out powers
            // of two such that exp(x) = exp(x') * 2**k, where k is an integer.
            // Solving this gives k = round(x / log(2)) and x' = x - k * log(2).
            int256 k = ((x << 96) / 54916777467707473351141471128 + 2 ** 95) >> 96;
            x = x - k * 54916777467707473351141471128;

            // `k` is in the range `[-61, 195]`.

            // Evaluate using a (6, 7)-term rational approximation.
            // `p` is made monic, we'll multiply by a scale factor later.
            int256 y = x + 1346386616545796478920950773328;
            y = ((y * x) >> 96) + 57155421227552351082224309758442;
            int256 p = y + x - 94201549194550492254356042504812;
            p = ((p * y) >> 96) + 28719021644029726153956944680412240;
            p = p * x + (4385272521454847904659076985693276 << 96);

            // We leave `p` in `2**192` basis so we don't need to scale it back up for the division.
            int256 q = x - 2855989394907223263936484059900;
            q = ((q * x) >> 96) + 50020603652535783019961831881945;
            q = ((q * x) >> 96) - 533845033583426703283633433725380;
            q = ((q * x) >> 96) + 3604857256930695427073651918091429;
            q = ((q * x) >> 96) - 14423608567350463180887372962807573;
            q = ((q * x) >> 96) + 26449188498355588339934803723976023;

            /// @solidity memory-safe-assembly
            assembly {
                // Div in assembly because solidity adds a zero check despite the unchecked.
                // The q polynomial won't have zeros in the domain as all its roots are complex.
                // No scaling is necessary because p is already `2**96` too large.
                r := sdiv(p, q)
            }

            // r should be in the range `(0.09, 0.25) * 2**96`.

            // We now need to multiply r by:
            // - The scale factor `s ≈ 6.031367120`.
            // - The `2**k` factor from the range reduction.
            // - The `1e18 / 2**96` factor for base conversion.
            // We do this all at once, with an intermediate result in `2**213`
            // basis, so the final right shift is always by a positive amount.
            r = int256((uint256(r) * 3822833074963236453042738258902158003155416615667) >> uint256(195 - k));
        }
    }

    function lnWad(int256 x) internal pure returns (int256 r) {
        /// @solidity memory-safe-assembly
        assembly {
            // We want to convert `x` from `10**18` fixed point to `2**96` fixed point.
            // We do this by multiplying by `2**96 / 10**18`. But since
            // `ln(x * C) = ln(x) + ln(C)`, we can simply do nothing here
            // and add `ln(2**96 / 10**18)` at the end.

            // Compute `k = log2(x) - 96`, `r = 159 - k = 255 - log2(x) = 255 ^ log2(x)`.
            r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
            r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
            r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
            r := or(r, shl(4, lt(0xffff, shr(r, x))))
            r := or(r, shl(3, lt(0xff, shr(r, x))))
            // We place the check here for more optimal stack operations.
            if iszero(sgt(x, 0)) {
                mstore(0x00, 0x1615e638) // `LnWadUndefined()`.
                revert(0x1c, 0x04)
            }
            // forgefmt: disable-next-item
            r := xor(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),
                0xf8f9f9faf9fdfafbf9fdfcfdfafbfcfef9fafdfafcfcfbfefafafcfbffffffff))

            // Reduce range of x to (1, 2) * 2**96
            // ln(2^k * x) = k * ln(2) + ln(x)
            x := shr(159, shl(r, x))

            // Evaluate using a (8, 8)-term rational approximation.
            // `p` is made monic, we will multiply by a scale factor later.
            // forgefmt: disable-next-item
            let p := sub( // This heavily nested expression is to avoid stack-too-deep for via-ir.
                sar(96, mul(add(43456485725739037958740375743393,
                sar(96, mul(add(24828157081833163892658089445524,
                sar(96, mul(add(3273285459638523848632254066296,
                    x), x))), x))), x)), 11111509109440967052023855526967)
            p := sub(sar(96, mul(p, x)), 45023709667254063763336534515857)
            p := sub(sar(96, mul(p, x)), 14706773417378608786704636184526)
            p := sub(mul(p, x), shl(96, 795164235651350426258249787498))
            // We leave `p` in `2**192` basis so we don't need to scale it back up for the division.

            // `q` is monic by convention.
            let q := add(5573035233440673466300451813936, x)
            q := add(71694874799317883764090561454958, sar(96, mul(x, q)))
            q := add(283447036172924575727196451306956, sar(96, mul(x, q)))
            q := add(401686690394027663651624208769553, sar(96, mul(x, q)))
            q := add(204048457590392012362485061816622, sar(96, mul(x, q)))
            q := add(31853899698501571402653359427138, sar(96, mul(x, q)))
            q := add(909429971244387300277376558375, sar(96, mul(x, q)))

            // `p / q` is in the range `(0, 0.125) * 2**96`.

            // Finalization, we need to:
            // - Multiply by the scale factor `s = 5.549…`.
            // - Add `ln(2**96 / 10**18)`.
            // - Add `k * ln(2)`.
            // - Multiply by `10**18 / 2**96 = 5**18 >> 78`.

            // The q polynomial is known not to have zeros in the domain.
            // No scaling required because p is already `2**96` too large.
            p := sdiv(p, q)
            // Multiply by the scaling factor: `s * 5**18 * 2**96`, base is now `5**18 * 2**192`.
            p := mul(1677202110996718588342820967067443963516166, p)
            // Add `ln(2) * k * 5**18 * 2**192`.
            // forgefmt: disable-next-item
            p := add(mul(16597577552685614221487285958193947469193820559219878177908093499208371, sub(159, r)), p)
            // Add `ln(2**96 / 10**18) * 5**18 * 2**192`.
            p := add(600920179829731861736702779321621459595472258049074101567377883020018308, p)
            // Base conversion: mul `2**18 / 2**192`.
            r := sar(174, p)
        }
    }
}
Настройки компилятораПоказать
{
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": []
}

Исходный код и метаданные: Sourcify.

Исходный код принадлежит авторам контракта.