Skip to content
Verified contractExactMIT

QorpoBuyBattlePass

Address0x2cf4239c1fbed534325e6829b5ed2df1ff8e7bd4
Balance

0 ETH

 

Transactions

4

 

Compiler

solc 0.8.28

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.28+commit.7893614a
Language
solidity
Optimization
Yes, 200 runs
EVM version
paris
Via IR
yes
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
21,185,002
Creation transaction
0x664ab556dc…f2a7aedf20

src/citizen-conflict/interaction/QorpoBuyBattlePass.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "src/utils/TokenAccessControl.sol";


contract QorpoBuyBattlePass is TokenAccessControl {

    struct battlePass {
        uint256 id;
        uint256 price;
        address paymentTokenAddress;
        address treasuryAddress;
    }

    mapping(uint256 => battlePass) public battlePasses;

    constructor() {}

    event BuyBattlePass(address indexed toAddress, uint256 id);
    event BuyBattlePassCustomPrice(address indexed toAddress, uint256 id, uint256 customPrice);

    function setBattlePass(
        uint256 _id,
        uint256 _price,
        address _paymentTokenAddress,
        address _treasuryAddress) public onlyOwner {
        battlePasses[_id] = battlePass(_id, _price, _paymentTokenAddress, _treasuryAddress);
    }

    function buyBattlePass(uint256 _id, address _toAddress) public ifNotPaused{
        IERC20 paymentToken = IERC20(battlePasses[_id].paymentTokenAddress);
        require(paymentToken.transferFrom(msg.sender, battlePasses[_id].treasuryAddress, battlePasses[_id].price), "QorpoBuyBattlePass: transfer failed");
        // Since BattlePass is not on chain asset, the assignment of BattlePass is done off-chain based on the emitted event
        emit BuyBattlePass(_toAddress, _id);
    }

    function buyBattlePassCustomPrice(uint256 _id, address _toAddress, uint256 _customPrice) public ifNotPaused{
        IERC20 paymentToken = IERC20(battlePasses[_id].paymentTokenAddress);
        require(paymentToken.transferFrom(msg.sender, battlePasses[_id].treasuryAddress, _customPrice), "QorpoBuyBattlePass: transfer failed");
        // Since BattlePass is not on chain asset, the assignment of BattlePass is done off-chain based on the emitted event
        // Check if user is eligible for custom price is also done off-chain and if not, BattlePass will not be assigned
        emit BuyBattlePassCustomPrice(_toAddress, _id, _customPrice);
    }
    
}

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

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

pragma solidity ^0.8.20;

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

src/utils/TokenAccessControl.sol

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

contract TokenAccessControl {
    bool public paused = false;
    address public owner;
    address public newContractOwner;
    mapping(address => bool) public authorizedContracts;

    event SetPause(bool pause);
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
    event AuthorizedUserSet(address indexed operator, bool approve);

    constructor() {
        owner = msg.sender;
    }

    modifier ifNotPaused() {
        require(!paused, "contract is paused");
        _;
    }

    modifier onlyOwner() {
        require(msg.sender == owner, "caller is not an owner");
        _;
    }

    modifier onlyAuthorizedUser() {
        require(authorizedContracts[msg.sender], "caller is not an authorized user");
        _;
    }

    modifier onlyOwnerOrAuthorizedUser() {
        require(authorizedContracts[msg.sender] || msg.sender == owner, "caller is not an authorized user or an owner");
        _;
    }

    function renounceOwnership() public virtual onlyOwner {
        emit OwnershipTransferred(owner, address(0));
        owner = address(0);
    }

    function transferOwnership(address _newOwner) public onlyOwner {
        require(_newOwner != address(0));
        newContractOwner = _newOwner;
    }

    function acceptOwnership() public ifNotPaused {
        require(msg.sender == newContractOwner);
        emit OwnershipTransferred(owner, newContractOwner);
        owner = newContractOwner;
        newContractOwner = address(0);
    }

    function setAuthorizedUser(address _operator, bool _approve) public onlyOwner {
        if (_approve) {
            authorizedContracts[_operator] = true;
        } else {
            delete authorizedContracts[_operator];
        }
        emit AuthorizedUserSet(_operator, _approve);
    }

    function setPause(bool _paused) public onlyOwner {
        paused = _paused;
        if (paused) {
            emit SetPause(paused);
        }
    }
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "paris",
  "remappings": [
    "@openzeppelin/=lib/openzeppelin-contracts/",
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-std/=lib/openzeppelin-contracts/lib/forge-std/src/",
    "halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.