// SPDX-License-Identifier: AGPL-3.0-or-later pragma solidity ^0.8.16; /// @dev Core dependencies. import {BadgerMintHook} from "../types/BadgerMintHook.sol"; /** * @dev Mint module that enforces self-operation logic only preventing * a user from minting a token to another address. * @author CHANCE (@nftchance) * @author masonthechain (@masonthechain) */ contract BadgerMintSelf is BadgerMintHook { //////////////////////////////////////////////////////// /// STATE /// //////////////////////////////////////////////////////// /// @dev The schema used for the config method. string public constant override CONFIG_SCHEMA = "uint256,bool"; /// @dev Mapping of token addresses to accountBound status. mapping(address => mapping(uint256 => bool)) public selfOperated; //////////////////////////////////////////////////////// /// SETTERS /// //////////////////////////////////////////////////////// /** * See {IBadgerHook-config}. */ function config(bytes calldata _data) public virtual override { /// @dev Decode the configuration data forwarded from the Organization. (uint256 _id, bool _selfOperated) = abi.decode(_data, (uint256, bool)); /// @dev Set the state of self-operation only for the token. selfOperated[msg.sender][_id] = _selfOperated; } /** * See {IBadgerHook-execute}. */ function execute(bytes calldata _data) public virtual override { /// @dev Decode the transfer data forwarded from the Organization. (address _operator, address _to, uint256 _id, , ) = abi.decode( _data, (address, address, uint256, uint256, bytes) ); /// @dev Ensure the token is not being minted to another address /// if self-operation is enabled. require( _operator == _to || !selfOperated[msg.sender][_id], "BadgerMintSelfOperated::execute: Only mint to self" ); } }