Skip to content
Verified contractPartialMIT

FloorAmmCreateV2

Address0x649dc04e3715dea3aeec3e0ab3c256cb5dbd41c7
Balance

0 ETH

 

Transactions

0

 

Compiler

solc 0.8.28

 

Same code

1 more contract

 

Details

Compiler
solc 0.8.28+commit.7893614a
Language
solidity
Optimization
Yes, 1 runs
EVM version
cancun
Via IR
yes
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,451,285
Creation transaction
0x394f208e25…01a53e5327

50 files

The source code is large: one file is shown at a time. Choose a file in the list.

src/v2/FloorAmmCreateV2.sol

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

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
import {IFloorAmm} from "../interfaces/IFloorAmm.sol";
import {IRegistries} from "../interfaces/IRegistries.sol";
import {FloorStorage} from "../FloorStorage.sol";
import {FloorRewards as Rw} from "../libraries/FloorRewards.sol";
import {FloorToken} from "../token/FloorToken.sol";
import {FloorBookStorage as S} from "./storage/FloorBookStorage.sol";
import {IFloorBookEvents} from "./FloorBookTypes.sol";
import {PresetCodecV2 as C} from "./codec/PresetCodecV2.sol";
import {FloorCreateV2 as Cr} from "./math/FloorCreateV2.sol";
import {FloorCreditV2 as Cd} from "./engines/FloorCreditV2.sol";
import {FloorSqrtV2 as Q} from "./math/FloorSqrtV2.sol";
import {FloorBookWalk as W} from "./engines/book/FloorBookWalk.sol";
import {FloorBookStore as St} from "./engines/book/FloorBookStore.sol";
import {FloorSupplyV2 as Sup} from "./math/FloorSupplyV2.sol";
import {IFloorBookEngine, KIND_TEAM_BUY} from "./engines/IFloorBookEngine.sol";
import {FloorQuoteAlias} from "./FloorQuoteAlias.sol";

/// @title FloorAmmCreateV2 — the create hop.
/// DELEGATECALLed by FloorAmmV2's `fallback`; every selector it does not hold chains on to `nextModule`.
/// `createLaunch`: the row, the quote (listed / unlisted), the Team Slot rate, the create fee into the platform bucket,
/// the token (cloned, 1B to FloorAmm), the market, the row copied into `LaunchV2` for life, `RewardsV2`, then the
/// optional Team Buy (0 ..= the row's max, held for the creator, locked 1 day).
/// `noteBurn` / `noteDead`: a launch token's burn or dead balance lowers circulating supply; any other caller is `NotToken`.
contract FloorAmmCreateV2 is FloorStorage, IFloorBookEvents {
    using SafeERC20 for IERC20;

    /// Token chain units per math unit (18 − 6 decimals).
    uint256 internal constant TOKEN_SCALE = 1e12;
    uint256 internal constant TOKEN_DECIMALS = 18;
    uint256 internal constant NAME_MAX = 32;
    uint256 internal constant SYMBOL_MAX = 10;

    /// The `FloorTokenIndexed` implementation every launch token clones.
    address public immutable tokenImplV2;
    IFloorBookEngine public immutable createBookEngine;
    address public immutable nextModule;

    constructor(address tokenImpl_, IFloorBookEngine book_, address next_) {
        tokenImplV2 = tokenImpl_;
        createBookEngine = book_;
        nextModule = next_;
    }

    fallback() external payable {
        address m = nextModule;
        assembly ("memory-safe") {
            calldatacopy(0, 0, calldatasize())
            let ok := delegatecall(gas(), m, 0, calldatasize(), 0, 0)
            returndatacopy(0, 0, returndatasize())
            switch ok
            case 0 { revert(0, returndatasize()) }
            default { return(0, returndatasize()) }
        }
    }

    /// What one create fixed (kept in memory across the steps).
    struct Made {
        uint256 id;
        address token;
        address quote;
        bool listed;
        uint256 usd;
        uint256 fee;
        uint256 sqrtP0;
        uint256 raise;
        uint256 teamBuyMax;
        uint256 bondingTokens;
        uint256 creatorTokens;
    }

    // ================================================================================================================ create

    function createLaunch(IFloorAmm.CreateParams calldata p)
        external
        payable
        nonReentrant
        returns (uint256 id, address token, uint256 creatorTokens)
    {
        Layout storage s = _s();
        if (s.createPaused) revert IFloorAmm.CreatesPaused();
        if (bytes(p.name).length == 0 || bytes(p.symbol).length == 0) revert IFloorAmm.BadArgument();
        if (bytes(p.name).length > NAME_MAX || bytes(p.symbol).length > SYMBOL_MAX) revert IFloorAmm.BadArgument();
        if (s.metadataBaseLen == 0) revert IFloorAmm.MetadataBaseUnset();
        bytes memory rb = S.layout().presetRow[p.presetId];
        if (rb.length == 0) revert IFloorAmm.PresetInvalid();
        // the registry's listing state (`FloorAmmRegistryV2`)
        S.PresetMetaV2 storage pm = S.layout().presetMeta[p.presetId];
        if (pm.deleted) revert IFloorAmm.PresetDeleted();
        if (!pm.enabled) revert IFloorAmm.PresetDisabled();
        C.Row memory row = decodeRow(rb);
        // the rate is exactly the row's max, refused before anything is created (any other rate is `TeamSlotRateOverMax`)
        if (p.teamSlotRateBps != row.teamSlotMaxBps) revert IFloorAmm.TeamSlotRateOverMax();
        Made memory m;
        m.quote = p.quote;
        Cr.Ctx memory ctx = _quoteTerms(p, m);
        // √p0, the market (refused as `MathFailed(17)`), the Team Buy's bounds
        m.sqrtP0 = Cr.sqrtP0For(row.launchCapUsdCents, ctx);
        W.Book memory b;
        (b, m.raise) = Cr.createBook(row, m.sqrtP0);
        (, m.teamBuyMax) = Cr.teamBuyBounds(row, ctx);
        m.bondingTokens = b.ranges[0].tokens;
        S.Layout storage v = S.layout();
        id = ++v.launchCount;
        m.id = id;
        token = _token(p, id);
        m.token = token;
        uint256 x = _storeLaunch(v.launches[id], row, b, m, keccak256(rb), v.presetRowVersion[p.presetId], p.presetId);
        // the ranges' sqrtA / sqrtB / tokens, kind, theta, psi and Milestone cap live only in the launch's data contract
        St.deployData(v.launches[id], b, x);
        _rewards(id, p.teamSlotRateBps);
        creatorTokens = _teamBuy(id, p, m);
        m.creatorTokens = creatorTokens;
        _emitCreated(p, m);
    }

    /// The row from its canonical RowV2 bytes.
    function decodeRow(bytes memory rb) public pure returns (C.Row memory row) {
        row = C.decode(rb);
    }

    /// The quote's terms: listed iff the registry holds it (enabled, no declared price, the registry's price and fee);
    /// unlisted: the creator's declared price and the native create fee. The fee goes into the platform bucket. A native
    /// alias (`FloorQuoteAlias`) is refused, listed or not (EVM-1-8).
    function _quoteTerms(IFloorAmm.CreateParams calldata p, Made memory m) internal returns (Cr.Ctx memory ctx) {
        if (FloorQuoteAlias.refused(p.quote)) revert IFloorAmm.BadArgument();
        IRegistries.QuoteEntry storage E = _s().quotes[p.quote];
        bool listed = E.listed;
        uint256 dec;
        uint256 usd = p.quoteUsdCentsX64;
        uint256 fee;
        if (listed) {
            if (!E.enabled) revert IFloorAmm.QuoteDisabled();
            if (usd != 0) revert IFloorAmm.BadArgument();
            (dec, usd, fee) = (E.decimals, E.usdCentsX64, E.createFee);
            E.launches += 1;
        } else {
            if (usd == 0 || usd > type(uint128).max) revert IFloorAmm.BadArgument();
            dec = _decimalsOf(p.quote);
            fee = _s().nativeCreateFee;
        }
        if (!listed ? msg.value != fee : p.quote == NATIVE_QUOTE ? msg.value != fee + p.creatorBuy : msg.value != 0) {
            revert IFloorAmm.BadValue();
        }
        if (!listed || p.quote == NATIVE_QUOTE) {
            Rw.creditBucket(NATIVE_QUOTE, listed ? fee : fee);
        } else if (fee > 0) {
            Rw.creditBucket(p.quote, _pullIn(p.quote, msg.sender, fee));
        }
        (m.listed, m.usd, m.fee) = (listed, usd, fee);
        ctx = Cr.Ctx({quoteDecimals: dec, quoteUsdCentsX64: usd, tokenDecimals: TOKEN_DECIMALS});
    }

    function _decimalsOf(address t) internal view returns (uint256 dec) {
        if (t.code.length == 0) revert IFloorAmm.BadArgument();
        try IERC20Metadata(t).decimals() returns (uint8 d) {
            dec = d;
        } catch {
            revert IFloorAmm.BadArgument();
        }
        if (dec > 30) revert IFloorAmm.BadArgument();
    }

    /// The token a `sameAddressEverywhere` create by `creator` with `creatorSalt` deploys.
    function predictToken(address creator, bytes32 creatorSalt) external view returns (address) {
        return Clones.predictDeterministicAddress(tokenImplV2, keccak256(abi.encode(creator, creatorSalt)), address(this));
    }

    /// The token step: cloned, initialized in one call, 1B to FloorAmm, held.
    function _token(IFloorAmm.CreateParams calldata p, uint256 id) internal returns (address token) {
        bytes32 salt = p.sameAddressEverywhere
            ? keccak256(abi.encode(msg.sender, p.creatorSalt))
            : keccak256(abi.encode(block.chainid, id));
        token = Clones.cloneDeterministic(tokenImplV2, salt);
        FloorToken(token).initialize(p.name, p.symbol, id);
        if (IERC20(token).balanceOf(address(this)) != TOTAL_SUPPLY) revert IFloorAmm.BadArgument();
        S.Layout storage v = S.layout();
        v.launchOfToken[token] = id;
        v.launchOfPair[S.pairId(id)] = id;
        v.held[token] += TOTAL_SUPPLY;
    }

    /// The row copied for life and the fresh book (every range for sale, nothing settled, supply N0). Range asks, kind,
    /// theta, psi and Milestone cap are not stored here: they live in the data contract (`FloorBookStore.deployData`).
    function _storeLaunch(
        S.LaunchV2 storage L,
        C.Row memory row,
        W.Book memory b,
        Made memory m,
        bytes32 hash,
        uint32 version,
        uint8 presetId
    ) internal returns (uint256 x) {
        L.token = m.token;
        L.quote = m.quote;
        L.creator = msg.sender;
        L.presetId = presetId;
        L.presetVersion = version;
        L.presetHash = hash;
        L.createdAt = uint64(block.timestamp);
        L.createdBlock = uint64(_blockNumber());
        _storeRow(L, row);
        L.sqrtP0 = uint128(m.sqrtP0);
        L.sqrtP = uint128(b.sqrtP);
        L.feeStartPpm = b.feeStartPpm; // the fee curve on this quote
        L.sqrtFeeA = uint128(b.sqrtFeeA);
        L.sqrtFeeB = uint128(b.sqrtFeeB);
        L.supply = uint64(Cr.N0);
        uint256 n = b.nRanges;
        L.nRanges = uint8(n);
        if (n > 48) St.panic(0x32); // as the 48-element arrays' writes were
        assembly ("memory-safe") {
            x := mload(0x40)
            mstore(0x40, add(x, 0x180))
            for { let k := 0 } lt(k, 0x180) { k := add(k, 0x20) } { mstore(add(x, k), 0) }
        }
        for (uint256 i; i < n; ++i) {
            C.RangeRow memory g = row.ranges[i];
            L.rngClass[i] = g.class;
            uint256 th = g.thetaBps;
            uint256 ps = g.psiBps;
            uint256 cap = g.msCapPpm;
            assembly ("memory-safe") {
                let o := shl(5, shr(4, i)) // 16 16-bit elements a word
                let r := shl(4, and(i, 15))
                let q := add(x, o)
                mstore(q, or(mload(q), shl(r, th)))
                q := add(x, add(0x60, o))
                mstore(q, or(mload(q), shl(r, ps)))
                q := add(x, add(0xc0, shl(5, shr(3, i)))) // 8 32-bit elements a word
                mstore(q, or(mload(q), shl(shl(5, and(i, 7)), cap)))
            }
        }
    }

    /// Every row constant the engines and views read.
    function _storeRow(S.LaunchV2 storage L, C.Row memory row) internal {
        L.msClass = row.msClass;
        L.flags = row.flags;
        L.phiBps = row.phiBps;
        L.wcBps = row.wcBps;
        L.psiTailBps = row.psiTailBps;
        L.teamBuyShareBps = row.teamBuyShareBps;
        L.teamSlotMaxBps = row.teamSlotMaxBps;
        L.platformMsBps = row.platformMsBps;
        L.floorMsBps = row.floorMsBps;
        L.feePpm = row.feePpm;
        // the row's bands are not copied: nothing reads them
        L.ckBps = row.ckTargetBps; // the row's C + K target share, for life
        L.kpot.on = true; // C and K keep their own pots (`FloorCreateV2.empty`)
    }

    /// `RewardsV2`: the creator's referrers from its own link, fixed for life; the Team Slot opened with the creator at
    /// place 0 holding the whole weight, its rate recorded.
    function _rewards(uint256 id, uint16 rate) internal {
        S.RewardsV2 storage R = S.layout().rewards[id];
        R.creatorRef = Rw.store().traderRefs[msg.sender];
        R.slotMember[0] = msg.sender;
        R.slotWeightPpb[0] = 1e9;
        R.slotRateBps = rate;
        emit IFloorAmm.TeamSlotOpened(id, rate, 0);
    }

    /// The optional Team Buy: the whole offer pulled; above the row's max is refused (`CreatorBuyTooLarge`); it is bought
    /// on the fresh book for FloorAmm itself (`Trade.kind` 1), the walk's refund paid back; the tokens stay held, booked
    /// to the creator until `creatorUnlockAt` (set only when it bought tokens).
    function _teamBuy(uint256 id, IFloorAmm.CreateParams calldata p, Made memory m) internal returns (uint256 tokens) {
        if (p.creatorBuy == 0) {
            if (p.creatorBuyMinTokens != 0) revert IFloorAmm.SlippageExceeded();
            return 0;
        }
        uint256 got = m.quote == NATIVE_QUOTE ? p.creatorBuy : _pullIn(m.quote, msg.sender, p.creatorBuy);
        if (got > m.teamBuyMax) revert IFloorAmm.CreatorBuyTooLarge();
        uint256 back;
        if (got != 0) {
            bytes memory ret = _hop(
                address(createBookEngine),
                abi.encodeCall(IFloorBookEngine.buy, (id, got, p.creatorBuyMinTokens, address(this), msg.sender, KIND_TEAM_BUY))
            );
            IFloorBookEngine.BuyOut memory r = abi.decode(ret, (IFloorBookEngine.BuyOut));
            back += r.refund;
            tokens = r.tokensOut;
            S.layout().rewards[id].teamBuyOwed = uint64(tokens / TOKEN_SCALE);
            if (tokens != 0) S.layout().launches[id].creatorUnlockAt = uint64(block.timestamp + CREATOR_LOCK);
        } else if (p.creatorBuyMinTokens != 0) {
            revert IFloorAmm.SlippageExceeded();
        }
        _payQuote(m.quote, msg.sender, back);
    }

    function _emitCreated(IFloorAmm.CreateParams calldata p, Made memory m) internal {
        // the strings in memory and every derived word computed first (the event's 18 words are "too deep" otherwise)
        string memory name_ = p.name;
        string memory symbol_ = p.symbol;
        string memory uri = FloorToken(m.token).metadataURI();
        S.LaunchV2 storage L = S.layout().launches[m.id];
        m.sqrtP0 = Q.priceX64(m.sqrtP0) / TOKEN_SCALE; // re-used as p0X64 (chain units): √p0 is stored already
        m.bondingTokens *= TOKEN_SCALE;
        emit IFloorAmm.LaunchCreated(
            m.id,
            m.token,
            m.quote,
            msg.sender,
            L.presetId,
            L.presetVersion,
            L.presetHash,
            m.sqrtP0,
            m.raise,
            m.bondingTokens,
            m.creatorTokens,
            // the quote create fee; 0 on an unlisted create (its native fee is the last word)
            m.listed ? m.fee : 0,
            name_,
            symbol_,
            uri,
            m.listed,
            m.usd,
            m.listed ? 0 : m.fee
        );
    }

    // ================================================================================================================ burns

    /// A launch token reports a burn FloorAmm did not make; any other caller is `NotToken`. `launch.supply` becomes the
    /// token's live supply (⌊totalSupply ÷ 10¹²⌋) only when lower, the fall added to `incinerated`. `amount` is not
    /// trusted: the fall is read, so a burn applies once. Never reverts for the token. Nothing circulating sweeps the pots.
    function noteBurn(uint256) external {
        uint256 id = S.layout().launchOfToken[msg.sender];
        if (id == 0) revert NotToken();
        S.LaunchV2 storage L = S.layout().launches[id];
        uint256 live = IERC20(msg.sender).totalSupply() / TOKEN_SCALE;
        uint64 sup = L.supply;
        uint256 fall = live < sup ? sup - live : 0;
        if (fall != 0) (L.supply, L.incinerated) = (uint64(live), L.incinerated + uint64(fall));
        W.Book memory b = St.load(L);
        (bool ok, uint256 sc) = Sup.circulating(L.supply, 0, W.forSale(b), W.boughtBack(b), L.deadTokens);
        if (ok && sc == 0) {
            uint256 swept = _sweepAllBurned(id, L);
            if (swept > 0) emit IFloorAmm.PotsSwept(id, swept, 2);
        }
    }

    /// Nothing circulating → the vault (F + every C + K segment's money + the ranges' `place`) to the platform bucket,
    /// each set to 0. Prices, √f, the book's tokens and F's claims on them (`bandFClaim`, MATH-3-4) stay: trading stays
    /// open. `held` is unchanged.
    function _sweepAllBurned(uint256 id, S.LaunchV2 storage L) internal returns (uint256 moved) {
        uint256 nb = L.nBands;
        moved = L.f;
        for (uint256 i; i < nb; ++i) {
            moved += L.bandMoney[i];
            // F's claim on the tokens a segment still holds stays (MATH-3-4): their resale money returns to F
            (L.bandMoney[i], L.bandF[i]) = (0, 0);
        }
        (L.f, L.ckAtF, L.kpot.kAtF) = (0, 0, 0);
        uint256 nr = L.nRanges;
        uint256 place;
        for (uint256 i; i < nr; ++i) {
            place += L.rngPlace[i];
            L.rngPlace[i] = 0;
        }
        // the places swept, `l_max` rises to the price
        if (place != 0 && L.sqrtLMax < L.sqrtP) L.sqrtLMax = L.sqrtP;
        moved += place;
        if (moved == 0) return 0;
        S.RewardsV2 storage R = S.layout().rewards[id];
        R.platformOwed = Cd.add(R.platformOwed, moved);
    }

    // ========================================================================================================== withdrawals

    /// The authority moves each listed launch's whole platform bucket (`platformOwed`) plus its $FLOOR bucket (`cutOwed`)
    /// to `treasury`, in the launch's quote; one `PlatformWithdrawn` per launch paid. A launch owing neither is skipped;
    /// none paid is `NothingToDo`. `held` falls by what leaves, then the quote must still cover every book.
    function withdrawPlatformMany(uint256[] calldata launchIds) external onlyAuthority nonReentrant returns (uint256 paid) {
        address to = _s().treasury;
        if (to == address(0)) revert IFloorAmm.TreasuryUnset();
        S.Layout storage v = S.layout();
        for (uint256 i; i < launchIds.length; ++i) {
            uint256 id = launchIds[i];
            address q = v.launches[id].quote;
            if (v.launches[id].token == address(0)) revert IFloorAmm.UnknownLaunch();
            S.RewardsV2 storage R = v.rewards[id];
            uint256 amount = uint256(R.platformOwed) + R.cutOwed;
            if (amount == 0) continue;
            (R.platformOwed, R.cutOwed) = (0, 0);
            v.held[q] -= amount;
            paid += amount;
            emit IFloorAmm.PlatformWithdrawn(q, to, amount, 0);
            _pay(q, to, amount);
            _covered(q);
        }
        if (paid == 0) revert IFloorAmm.NothingToDo();
    }

    /// `withdrawPlatform` (the per-quote bucket: create fees); what stays must cover the books.
    function withdrawPlatform(address quote, uint256 amount) external onlyAuthority nonReentrant returns (uint256) {
        address to = _s().treasury;
        if (to == address(0)) revert IFloorAmm.TreasuryUnset();
        uint256 owed = Rw.store().bucket[quote];
        if (amount == 0) amount = owed;
        if (amount == 0) revert IFloorAmm.NothingToDo();
        if (amount > owed) revert IFloorAmm.OverOwed();
        Rw.debitBucket(quote, amount);
        emit IFloorAmm.PlatformWithdrawn(quote, to, amount, owed - amount);
        _pay(quote, to, amount);
        _covered(quote);
        return amount;
    }

    /// `withdrawHolder` (the per-quote holder bucket, to `holderPayout`); what stays must cover the books.
    function withdrawHolder(address quote, uint256 amount) external onlyAuthority nonReentrant returns (uint256) {
        Rw.Store storage r = Rw.store();
        address to = r.holderPayout;
        if (to == address(0)) revert IFloorAmm.HolderDestUnset();
        uint256 owed = r.holderBucket[quote];
        if (amount == 0) amount = owed;
        if (amount == 0) revert IFloorAmm.NothingToDo();
        if (amount > owed) revert IFloorAmm.OverOwed();
        Rw.debitHolderBucket(quote, amount);
        emit IFloorAmm.HolderWithdrawn(quote, to, amount, owed - amount);
        _pay(quote, to, amount);
        _covered(quote);
        return amount;
    }

    /// After a withdrawal the contract still holds every liability in `x` (`held[x]` + `_owedIn`), else `ClaimsShort`.
    function _covered(address x) internal view {
        uint256 need = S.layout().held[x] + _owedIn(x);
        uint256 bal = x == NATIVE_QUOTE ? address(this).balance : IERC20(x).balanceOf(address(this));
        if (bal < need) revert IFloorAmm.ClaimsShort();
    }

    function _pay(address q, address to, uint256 amount) internal {
        if (q == NATIVE_QUOTE) {
            (bool ok,) = to.call{value: amount}("");
            if (!ok) revert IFloorAmm.NativeTransferFailed();
        } else {
            IERC20(q).safeTransfer(to, amount);
        }
    }

    /// A launch token reports the summed balance of its dead, unburned addresses; `deadTokens` rises to its whole math
    /// units (a lower one adds nothing). Any other caller is `NotToken`. `DeadSynced` only when units are counted.
    function noteDead(uint256 balance) external {
        uint256 id = S.layout().launchOfToken[msg.sender];
        if (id == 0) revert NotToken();
        S.LaunchV2 storage L = S.layout().launches[id];
        uint256 units = balance / TOKEN_SCALE;
        uint256 was = L.deadTokens;
        if (units <= was) return;
        L.deadTokens = uint64(units);
        W.Book memory b = St.load(L);
        (bool ok, uint256 sc) = Sup.circulating(L.supply, 0, W.forSale(b), W.boughtBack(b), units);
        emit DeadSynced(id, (units - was) * TOKEN_SCALE, units * TOKEN_SCALE, ok ? sc * TOKEN_SCALE : 0);
        // dead tokens that leave nothing circulating sweep as a burn does
        if (ok && sc == 0) {
            uint256 swept = _sweepAllBurned(id, L);
            if (swept > 0) emit IFloorAmm.PotsSwept(id, swept, 2);
        }
    }

    // ================================================================================================================ money

    function _pullIn(address q, address from, uint256 amount) internal returns (uint256 got) {
        if (amount == 0) return 0;
        uint256 b0 = IERC20(q).balanceOf(address(this));
        IERC20(q).safeTransferFrom(from, address(this), amount);
        uint256 b1 = IERC20(q).balanceOf(address(this));
        got = b1 > b0 ? b1 - b0 : 0;
        if (got == 0) revert IFloorAmm.QuoteTransferShort();
        if (got < amount) ++_s().risk[q].shortIns;
    }

    /// A failed refund is OWED to `to` (claim bit 64).
    function _payQuote(address q, address to, uint256 amount) internal {
        if (amount == 0 || Rw.tryTransfer(q, to, amount)) return;
        Rw.owePayout(to, q, amount);
        QuoteRisk storage k = _s().risk[q];
        ++k.failedOuts;
        k.lastFailBlock = uint64(block.number);
    }

    function _hop(address mod, bytes memory data) internal returns (bytes memory ret) {
        bool ok;
        (ok, ret) = mod.delegatecall(data);
        if (!ok) {
            assembly ("memory-safe") {
                revert(add(ret, 32), mload(ret))
            }
        }
    }
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": false,
    "bytecodeHash": "none",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 1,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "forge-std/=lib/forge-std/src/",
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/:erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/:halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "lib/openzeppelin-contracts-upgradeable/:erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
    "lib/openzeppelin-contracts-upgradeable/:halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
    "lib/openzeppelin-contracts-upgradeable/:openzeppelin-contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/",
    "lib/openzeppelin-contracts/:erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/openzeppelin-contracts/:halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.