Skip to content
Verified contractPartialMIT

KiviEscrow

Address0xff81462821142ef053b9f29d3708a76222b3fab5
Balance

0 ETH

 

Transactions

5

 

Compiler

solc 0.8.20

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.20+commit.a1b79de6
Language
solidity
Optimization
Yes, 200 runs
EVM version
paris
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,366,983
Creation transaction
0x8f597b0338…96d17d3ca6

src/KiviEscrow.sol

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

import {Ownable, Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

/**
 * @title KiviEscrow
 * @notice P2P 稳定币托管:卖家把 USDT / USDC 存进合约挂单,买家用法币线下付款,卖家确认后放币。
 *
 * 角色与权限(谁都不能把资金转给自己以外的第三方):
 * - 卖家:存入、追加、取回未锁定的部分、关闭挂单;确认收款后放币;可对已付款订单发起申诉。
 * - 撮合服务 operator(Kivi 后端):替买家锁单、标记「已付款」、在买家要求时取消、替买家发起申诉;
 *   卖家在挂单上开启「自动放币」后,还可在买家付款经链下零知识证明验证时替卖家放币(资金去向同卖家放币)。
 *   买家因此不需要持有 Gas。operator 不能把币转给买家、卖家、Kivi 以外的任何人。
 * - 买家:有 Gas 时也可以自己标记已付款、取消、发起申诉,不依赖撮合服务在线。
 * - 仲裁人 arbitrator(建议多签):只能把有争议的订单判给买家或退回卖家。
 * - 管理员 owner(建议多签):只能改代币白名单、角色、手续费(上限 1%)、网络费、付款时限,以及暂停新挂单 / 新订单;
 *   碰不到任何资金,暂停也不影响放币、退款和取回。
 *
 * 网络费由卖家承担:撮合服务代发锁单和「已付款」的 Gas,按代币设定一个固定的网络费(稳定币计),
 * 锁单时从卖家挂单里一并锁定,成交(放币或仲裁判给买家)时转给 Kivi;订单取消或判回卖家时退还给卖家。
 * 每单网络费不超过订单金额的 2%(合约写死,管理员改不了)。放币交易由卖家自己发送、自己付 Gas。
 *
 * 订单状态:Locked(已锁定,等待买家付款)→ Paid(买家已付款)→ Released(已放币)
 *           Locked 超时或买家取消 → Cancelled(退回挂单);Paid → Disputed(申诉中)→ Resolved(仲裁完成)
 *
 * 代币转账一律按合约自身余额的变化核对,兼容不返回值或返回值异常的代币(例如 Tron 上的 USDT),
 * 并拒绝转账时扣费的代币。
 */
contract KiviEscrow is Ownable2Step, Pausable, ReentrancyGuard {
    enum Status {
        None,
        Locked,
        Paid,
        Released,
        Cancelled,
        Disputed,
        Resolved
    }

    struct Deposit {
        address seller;
        address token;
        uint128 available; // 可被锁单的余额
        uint128 locked; // 已锁定在进行中订单里的余额
        uint128 minOrder;
        uint128 maxOrder;
        bool closed;
    }

    /// 订单只占两个存储槽(锁单 Gas 的主要开销);链下条款哈希只记在 OrderLocked 事件里
    struct Order {
        uint32 depositId;
        uint64 expiresAt; // 买家付款截止时间(只约束 Locked 状态)
        uint16 feeBps; // 锁单时的手续费,之后改费率不影响已有订单
        Status status;
        uint128 networkFee; // 锁单时从卖家挂单里额外锁定的网络费
        address buyer;
        uint96 amount; // 买家应得的币(扣手续费前);上限约 7.9×10^28 个最小单位
    }

    uint16 public constant MAX_FEE_BPS = 100; // 1%
    uint16 public constant MAX_NETWORK_FEE_BPS = 200; // 网络费最多为订单金额的 2%
    uint64 public constant MIN_WINDOW = 5 minutes;
    uint64 public constant MAX_WINDOW = 2 hours;

    address public operator;
    address public arbitrator;
    address public feeRecipient;
    uint16 public feeBps;
    uint64 public paymentWindow;
    mapping(address => bool) public allowedToken;
    /// 每单网络费(按代币的最小单位,例如 6 位小数的 USDT:1e6 = 1 USDT)
    mapping(address => uint128) public networkFee;

    Deposit[] internal _deposits;
    Order[] internal _orders;
    /// 卖家对某个挂单的授权:买家付款经链下验证(零知识付款证明)后,允许撮合服务替卖家放币
    mapping(uint256 => bool) public autoRelease;

    event TokenAllowed(address indexed token, bool allowed);
    event RolesUpdated(address operator, address arbitrator, address feeRecipient);
    event FeeUpdated(uint16 feeBps);
    event PaymentWindowUpdated(uint64 window);
    event NetworkFeeUpdated(address indexed token, uint128 fee);
    event DepositCreated(uint256 indexed depositId, address indexed seller, address indexed token, uint256 amount, uint256 minOrder, uint256 maxOrder);
    event DepositIncreased(uint256 indexed depositId, uint256 amount);
    event DepositWithdrawn(uint256 indexed depositId, uint256 amount);
    event DepositLimitsUpdated(uint256 indexed depositId, uint256 minOrder, uint256 maxOrder);
    event DepositClosed(uint256 indexed depositId, uint256 returned);
    /// terms:链下条款(价格、法币金额、付款方式、收款账户)的哈希,申诉时作为证据
    event OrderLocked(uint256 indexed orderId, uint256 indexed depositId, address indexed buyer, uint256 amount, uint256 networkFee, uint64 expiresAt, bytes32 terms);
    event OrderPaid(uint256 indexed orderId);
    event OrderCancelled(uint256 indexed orderId, address by);
    event OrderReleased(uint256 indexed orderId, address by, uint256 toBuyer, uint256 fee, uint256 networkFee);
    event DisputeOpened(uint256 indexed orderId, address by);
    event DisputeResolved(uint256 indexed orderId, bool toBuyer);
    event AutoReleaseUpdated(uint256 indexed depositId, bool enabled);

    error NotAllowed();
    error BadAmount();
    error BadLimits();
    error BadState();
    error BadAddress();
    error TransferFailed();

    modifier onlyOperator() {
        if (msg.sender != operator) revert NotAllowed();
        _;
    }

    constructor(address owner_, address operator_, address arbitrator_, address feeRecipient_, uint16 feeBps_, uint64 window_) Ownable(owner_) {
        _setRoles(operator_, arbitrator_, feeRecipient_);
        _setFee(feeBps_);
        _setWindow(window_);
    }

    /* ---------------------------------------------------------------- 管理 */

    function setTokenAllowed(address token, bool allowed) external onlyOwner {
        if (token == address(0)) revert BadAddress();
        allowedToken[token] = allowed;
        emit TokenAllowed(token, allowed);
    }

    function setRoles(address operator_, address arbitrator_, address feeRecipient_) external onlyOwner {
        _setRoles(operator_, arbitrator_, feeRecipient_);
    }

    function setFee(uint16 feeBps_) external onlyOwner {
        _setFee(feeBps_);
    }

    /// @notice 设置某个代币每单的网络费(实际收取时不超过订单金额的 2%)
    function setNetworkFee(address token, uint128 fee) external onlyOwner {
        networkFee[token] = fee;
        emit NetworkFeeUpdated(token, fee);
    }

    function setPaymentWindow(uint64 window_) external onlyOwner {
        _setWindow(window_);
    }

    /// @notice 暂停只影响新挂单、追加和新订单;放币、取消、退款、取回始终可用
    function pause() external onlyOwner {
        _pause();
    }

    function unpause() external onlyOwner {
        _unpause();
    }

    /* ---------------------------------------------------------------- 卖家 */

    function createDeposit(address token, uint128 amount, uint128 minOrder, uint128 maxOrder) external nonReentrant whenNotPaused returns (uint256 id) {
        if (!allowedToken[token]) revert NotAllowed();
        if (amount == 0) revert BadAmount();
        _checkLimits(minOrder, maxOrder);
        _pull(token, msg.sender, amount);
        id = _deposits.length;
        _deposits.push(Deposit({seller: msg.sender, token: token, available: amount, locked: 0, minOrder: minOrder, maxOrder: maxOrder, closed: false}));
        emit DepositCreated(id, msg.sender, token, amount, minOrder, maxOrder);
    }

    function increaseDeposit(uint256 id, uint128 amount) external nonReentrant whenNotPaused {
        Deposit storage d = _sellerDeposit(id);
        if (d.closed) revert BadState();
        if (amount == 0) revert BadAmount();
        _pull(d.token, msg.sender, amount);
        d.available += amount;
        emit DepositIncreased(id, amount);
    }

    function withdraw(uint256 id, uint128 amount) external nonReentrant {
        Deposit storage d = _sellerDeposit(id);
        if (amount == 0 || amount > d.available) revert BadAmount();
        d.available -= amount;
        _push(d.token, d.seller, amount);
        emit DepositWithdrawn(id, amount);
    }

    function setLimits(uint256 id, uint128 minOrder, uint128 maxOrder) external {
        Deposit storage d = _sellerDeposit(id);
        _checkLimits(minOrder, maxOrder);
        d.minOrder = minOrder;
        d.maxOrder = maxOrder;
        emit DepositLimitsUpdated(id, minOrder, maxOrder);
    }

    /// @notice 关闭挂单:取回全部可用余额;进行中的订单照常完成,之后退回的部分直接转给卖家
    function closeDeposit(uint256 id) external nonReentrant {
        Deposit storage d = _sellerDeposit(id);
        if (d.closed) revert BadState();
        d.closed = true;
        uint128 amount = d.available;
        d.available = 0;
        if (amount > 0) _push(d.token, d.seller, amount);
        emit DepositClosed(id, amount);
    }

    /// @notice 卖家开启 / 关闭这个挂单的自动放币:开启后,撮合服务可在订单「已付款」且付款经链下验证后直接放币
    function setAutoRelease(uint256 id, bool enabled) external {
        _sellerDeposit(id);
        autoRelease[id] = enabled;
        emit AutoReleaseUpdated(id, enabled);
    }

    /* ---------------------------------------------------------------- 订单 */

    /// @notice 撮合服务替买家锁单:把卖家挂单里的一部分(加上网络费)锁定给买家,等待买家线下付款
    function lockOrder(uint256 depositId, address buyer, uint128 amount, bytes32 terms) external onlyOperator whenNotPaused returns (uint256 orderId) {
        Deposit storage d = _deposit(depositId);
        if (d.closed || depositId > type(uint32).max) revert BadState();
        if (buyer == address(0) || buyer == d.seller) revert BadAddress();
        if (amount < d.minOrder || amount > d.maxOrder || amount > type(uint96).max) revert BadAmount();
        uint128 net = networkFee[d.token];
        uint128 cap = uint128((uint256(amount) * MAX_NETWORK_FEE_BPS) / 10_000);
        if (net > cap) net = cap;
        uint128 total = amount + net;
        if (total > d.available) revert BadAmount();
        d.available -= total;
        d.locked += total;
        // forge-lint: disable-next-line(unsafe-typecast)
        uint64 expiresAt = uint64(block.timestamp) + paymentWindow; // 时间戳在 uint64 范围内
        orderId = _orders.length;
        _orders.push(
            Order({
                // forge-lint: disable-next-line(unsafe-typecast)
                depositId: uint32(depositId),
                expiresAt: expiresAt,
                feeBps: feeBps,
                status: Status.Locked,
                networkFee: net,
                buyer: buyer,
                // forge-lint: disable-next-line(unsafe-typecast)
                amount: uint96(amount)
            })
        );
        emit OrderLocked(orderId, depositId, buyer, amount, net, expiresAt, terms);
    }

    /// @notice 买家点了「我已付款」:订单不再会因超时被取消,只能由卖家放币或仲裁
    function markPaid(uint256 orderId) external {
        Order storage o = _order(orderId);
        if (msg.sender != operator && msg.sender != o.buyer) revert NotAllowed();
        if (o.status != Status.Locked || block.timestamp > o.expiresAt) revert BadState();
        o.status = Status.Paid;
        emit OrderPaid(orderId);
    }

    /**
     * @notice 取消未付款的订单,币退回挂单。
     * 撮合服务可随时取消(买家主动取消);付款时限过后任何人都可以取消,卖家的币不会被一直占着。
     */
    function cancelOrder(uint256 orderId) external nonReentrant {
        Order storage o = _order(orderId);
        if (o.status != Status.Locked) revert BadState();
        if (msg.sender != operator && msg.sender != o.buyer && block.timestamp <= o.expiresAt) revert NotAllowed();
        o.status = Status.Cancelled;
        _refund(o);
        emit OrderCancelled(orderId, msg.sender);
    }

    /// @notice 卖家确认收到法币后放币;申诉中卖家也可以直接放币结束争议
    function release(uint256 orderId) external nonReentrant {
        Order storage o = _order(orderId);
        Deposit storage d = _deposits[o.depositId];
        if (msg.sender != d.seller) revert NotAllowed();
        if (o.status != Status.Locked && o.status != Status.Paid && o.status != Status.Disputed) revert BadState();
        o.status = Status.Released;
        (uint256 toBuyer, uint256 fee) = _payBuyer(o, d);
        emit OrderReleased(orderId, msg.sender, toBuyer, fee, o.networkFee);
    }

    /**
     * @notice 撮合服务替卖家放币:仅限卖家开了自动放币的挂单、且订单已标记付款(买家的付款已由链下零知识证明验证)。
     * 资金去向和卖家自己放币完全一样:买家得 amount − 手续费,手续费和网络费给 Kivi。撮合服务拿不到任何资金。
     */
    function releaseVerified(uint256 orderId) external onlyOperator nonReentrant {
        Order storage o = _order(orderId);
        Deposit storage d = _deposits[o.depositId];
        if (!autoRelease[o.depositId]) revert NotAllowed();
        if (o.status != Status.Paid) revert BadState();
        o.status = Status.Released;
        (uint256 toBuyer, uint256 fee) = _payBuyer(o, d);
        emit OrderReleased(orderId, msg.sender, toBuyer, fee, o.networkFee);
    }

    /// @notice 已付款的订单出现争议:卖家没收到钱,或买家付了款卖家不放币(买家经撮合服务发起)
    function openDispute(uint256 orderId) external {
        Order storage o = _order(orderId);
        if (o.status != Status.Paid) revert BadState();
        if (msg.sender != operator && msg.sender != o.buyer && msg.sender != _deposits[o.depositId].seller) revert NotAllowed();
        o.status = Status.Disputed;
        emit DisputeOpened(orderId, msg.sender);
    }

    /// @notice 仲裁:只能判给买家(扣手续费后放币)或退回卖家
    function resolveDispute(uint256 orderId, bool toBuyer) external nonReentrant {
        if (msg.sender != arbitrator) revert NotAllowed();
        Order storage o = _order(orderId);
        if (o.status != Status.Disputed) revert BadState();
        o.status = Status.Resolved;
        if (toBuyer) _payBuyer(o, _deposits[o.depositId]);
        else _refund(o);
        emit DisputeResolved(orderId, toBuyer);
    }

    /* ---------------------------------------------------------------- 查询 */

    function depositCount() external view returns (uint256) {
        return _deposits.length;
    }

    function orderCount() external view returns (uint256) {
        return _orders.length;
    }

    function getDeposit(uint256 id) external view returns (Deposit memory) {
        return _deposit(id);
    }

    function getOrder(uint256 id) external view returns (Order memory) {
        return _order(id);
    }

    /* ---------------------------------------------------------------- 内部 */

    /// 成交:买家拿到 amount − 手续费;手续费和卖家承担的网络费一笔转给 Kivi
    function _payBuyer(Order storage o, Deposit storage d) internal returns (uint256 toBuyer, uint256 fee) {
        d.locked -= uint128(o.amount) + o.networkFee;
        fee = (uint256(o.amount) * o.feeBps) / 10_000;
        toBuyer = o.amount - fee;
        _push(d.token, o.buyer, toBuyer);
        uint256 toKivi = fee + o.networkFee;
        if (toKivi > 0) _push(d.token, feeRecipient, toKivi);
    }

    /// 未成交:订单金额和网络费都退回卖家(挂单已关闭时直接转回卖家钱包)
    function _refund(Order storage o) internal {
        Deposit storage d = _deposits[o.depositId];
        uint128 total = uint128(o.amount) + o.networkFee;
        d.locked -= total;
        if (d.closed) _push(d.token, d.seller, total);
        else d.available += total;
    }

    /// 转入:按本合约余额的实际增加核对,拒绝转账扣费的代币
    function _pull(address token, address from, uint256 amount) internal {
        uint256 before = IERC20(token).balanceOf(address(this));
        (bool ok,) = token.call(abi.encodeWithSelector(IERC20.transferFrom.selector, from, address(this), amount));
        if (!ok || IERC20(token).balanceOf(address(this)) - before != amount) revert TransferFailed();
    }

    /// 转出:同样按余额变化核对(Tron 上的 USDT 转账成功时返回值也可能不是 true,不能只看返回值)
    function _push(address token, address to, uint256 amount) internal {
        uint256 before = IERC20(token).balanceOf(address(this));
        (bool ok,) = token.call(abi.encodeWithSelector(IERC20.transfer.selector, to, amount));
        if (!ok || before - IERC20(token).balanceOf(address(this)) != amount) revert TransferFailed();
    }

    function _deposit(uint256 id) internal view returns (Deposit storage) {
        if (id >= _deposits.length) revert BadState();
        return _deposits[id];
    }

    function _sellerDeposit(uint256 id) internal view returns (Deposit storage d) {
        d = _deposit(id);
        if (msg.sender != d.seller) revert NotAllowed();
    }

    function _order(uint256 id) internal view returns (Order storage) {
        if (id >= _orders.length) revert BadState();
        return _orders[id];
    }

    function _checkLimits(uint128 minOrder, uint128 maxOrder) internal pure {
        if (minOrder == 0 || minOrder > maxOrder) revert BadLimits();
    }

    function _setRoles(address operator_, address arbitrator_, address feeRecipient_) internal {
        if (operator_ == address(0) || arbitrator_ == address(0) || feeRecipient_ == address(0)) revert BadAddress();
        operator = operator_;
        arbitrator = arbitrator_;
        feeRecipient = feeRecipient_;
        emit RolesUpdated(operator_, arbitrator_, feeRecipient_);
    }

    function _setFee(uint16 feeBps_) internal {
        if (feeBps_ > MAX_FEE_BPS) revert BadAmount();
        feeBps = feeBps_;
        emit FeeUpdated(feeBps_);
    }

    function _setWindow(uint64 window_) internal {
        if (window_ < MIN_WINDOW || window_ > MAX_WINDOW) revert BadAmount();
        paymentWindow = window_;
        emit PaymentWindowUpdated(window_);
    }
}

lib/openzeppelin-contracts/contracts/access/Ownable.sol

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

lib/openzeppelin-contracts/contracts/access/Ownable2Step.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/Ownable2Step.sol)

pragma solidity ^0.8.20;

import {Ownable} from "./Ownable.sol";

/**
 * @dev Contract module which provides access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * This extension of the {Ownable} contract includes a two-step mechanism to transfer
 * ownership, where the new owner must call {acceptOwnership} in order to replace the
 * old one. This can help prevent common mistakes, such as transfers of ownership to
 * incorrect accounts, or to contracts that are unable to interact with the
 * permission system.
 *
 * The initial owner is specified at deployment time in the constructor for `Ownable`. This
 * can later be changed with {transferOwnership} and {acceptOwnership}.
 *
 * This module is used through inheritance. It will make available all functions
 * from parent (Ownable).
 */
abstract contract Ownable2Step is Ownable {
    address private _pendingOwner;

    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Returns the address of the pending owner.
     */
    function pendingOwner() public view virtual returns (address) {
        return _pendingOwner;
    }

    /**
     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
     * Can only be called by the current owner.
     *
     * Setting `newOwner` to the zero address is allowed; this can be used to cancel an initiated ownership transfer.
     */
    function transferOwnership(address newOwner) public virtual override onlyOwner {
        _pendingOwner = newOwner;
        emit OwnershipTransferStarted(owner(), newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual override {
        delete _pendingOwner;
        super._transferOwnership(newOwner);
    }

    /**
     * @dev The new owner accepts the ownership transfer.
     */
    function acceptOwnership() public virtual {
        address sender = _msgSender();
        if (pendingOwner() != sender) {
            revert OwnableUnauthorizedAccount(sender);
        }
        _transferOwnership(sender);
    }
}

lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-20 standard as defined in the ERC.
 */
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);
}

lib/openzeppelin-contracts/contracts/utils/Context.sol

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

lib/openzeppelin-contracts/contracts/utils/Pausable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/Pausable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    bool private _paused;

    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    /**
     * @dev The operation failed because the contract is paused.
     */
    error EnforcedPause();

    /**
     * @dev The operation failed because the contract is not paused.
     */
    error ExpectedPause();

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        if (paused()) {
            revert EnforcedPause();
        }
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        if (!paused()) {
            revert ExpectedPause();
        }
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}

lib/openzeppelin-contracts/contracts/utils/ReentrancyGuard.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
 * consider using {ReentrancyGuardTransient} instead.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant NOT_ENTERED = 1;
    uint256 private constant ENTERED = 2;

    uint256 private _status;

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

    constructor() {
        _status = NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        if (_status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

        // Any calls to nonReentrant after this point will fail
        _status = ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == ENTERED;
    }
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "paris",
  "remappings": [
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "erc4626-tests/=/Users/kenyan/Projects/U Card/contracts/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-std/=/Users/kenyan/Projects/U Card/contracts/lib/forge-std/src/",
    "halmos-cheatcodes/=/Users/kenyan/Projects/U Card/contracts/lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "openzeppelin-contracts/=/Users/kenyan/Projects/U Card/contracts/lib/openzeppelin-contracts/contracts/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.