creation_sourcecode: {"BarkcoinControl.sol":{"content":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\nimport \"./IERC20Metadata.sol\";\nimport \"./Ownable.sol\";\nimport \"./IBarkcoin.sol\";\nimport \"./ITether.sol\";\n\ncontract BarkcoinControl is Ownable {\n\n    struct StablecoinConfig {\n        uint16 exchangeRate; // BARK to stablecoin exchange rate (in basis points)\n        uint8 decimals; // Stablecoin decimals\n        uint16[4] bonus; // Bonus percentages for four tiers\n        bool isConfigured; // Check if the stablecoin is configured\n    }\n\n    uint8 private constant Decimals = 18;\n    uint32[4] public tiers = [1000, 10000, 100000, 1000000];\n\n    bool public isActive;\n    address private USDT;\n    address public recipient;\n    IBarkcoin public barkToken;\n    mapping(address =\u003e StablecoinConfig) private stablecoinInfo;\n\n    event StablecoinConfigured(address indexed stablecoin, uint16 exchangeRate, uint8 decimals, uint16[4] bonus, bool isConfigured);\n    event BarkExchanged(address stablecoin, uint256 tierIndex, address indexed buyer, uint256 stablecoinAmount, uint256 barkAmount);\n    event ChangeRecipient(address newRecipient);\n    event StateChanged(bool isActive);\n\n    modifier onlyWhenActive() {\n        require(isActive, \"Contract is not active\");\n        _;\n    }\n\n    constructor(address _barkToken, address _recipient, address _USDT, address _DAI) Ownable(msg.sender) {\n        require(_barkToken != address(0), \"Invalid BARK token address\");\n        require(_recipient != address(0), \"Invalid recipient address\");\n\n        barkToken = IBarkcoin(_barkToken);\n        recipient = _recipient;\n\n        //set USDT\n        USDT = _USDT;\n        setStablecoin(_USDT, 100, [0, 100, 200, 400], true);\n\n        //set DAI\n        setStablecoin(_DAI, 100, [0, 200, 400, 600], true);\n    }\n\n    function setStablecoin(address stablecoin, uint16 exchangeRate, uint16[4] memory bonus, bool isConfigured) internal {\n        stablecoinInfo[stablecoin] = StablecoinConfig({\n            exchangeRate : exchangeRate,\n            decimals : IERC20Metadata(stablecoin).decimals(),\n            bonus : bonus,\n            isConfigured : isConfigured\n        });\n    }\n\n    function configureStablecoin(address stablecoin, uint16 exchangeRate, uint16[4] calldata bonus, bool isConfigured) external onlyOwner {\n        require(stablecoin != address(0), \"Invalid stablecoin address\");\n        require(exchangeRate \u003e 0, \"Invalid exchange rate\");\n\n        setStablecoin(stablecoin, exchangeRate, bonus, isConfigured);\n\n        emit StablecoinConfigured(stablecoin, exchangeRate, stablecoinInfo[stablecoin].decimals, bonus, isConfigured);\n    }\n\n    function exchangeBark(address stablecoin, uint256 tierIndex) external onlyWhenActive {\n        StablecoinConfig memory config = stablecoinInfo[stablecoin];\n        require(config.isConfigured, \"Stablecoin not configured\");\n        require(tierIndex \u003c tiers.length, \"Invalid tier index\");\n\n        uint256 barkAmount = tiers[tierIndex];\n        uint256 stablecoinAmount = (barkAmount * config.exchangeRate) / 10000;\n        stablecoinAmount = stablecoinAmount * (10 ** uint256(config.decimals));\n\n        uint256 bonusAmount = (barkAmount * config.bonus[tierIndex]) / 10000;\n        uint256 totalBark = (barkAmount + bonusAmount) * (10 ** uint256(Decimals));\n\n        require(barkToken.balanceOf(address(this)) \u003e= totalBark, \"Insufficient BARK in contract\");\n\n        // Transfer stablecoin\n        if (stablecoin == USDT) {\n            ITether token = ITether(stablecoin);\n            token.transferFrom(msg.sender, recipient, stablecoinAmount);\n        } else {\n            IERC20Metadata token = IERC20Metadata(stablecoin);\n            token.transferFrom(msg.sender, recipient, stablecoinAmount);\n        }\n\n        // Transfer BARK\n        barkToken.exchangeTransfer(msg.sender, totalBark);\n\n        emit BarkExchanged(stablecoin, tierIndex, msg.sender, stablecoinAmount, totalBark);\n    }\n\n    function changeRecipient(address newRecipient) external onlyOwner {\n        require(newRecipient != address(0), \"Invalid recipient\");\n        recipient = newRecipient;\n        emit ChangeRecipient(newRecipient);\n    }\n\n    function changeActivate(bool state) external onlyOwner {\n        isActive = state;\n        emit StateChanged(state);\n    }\n\n    function getBarkBalance() external view returns (uint256) {\n        return barkToken.balanceOf(address(this));\n    }\n\n    function getStablecoinInfo(address token) external view\n    returns\n    (\n        uint16 exchangeRate,\n        uint8 decimals,\n        uint16[4] memory bonus,\n        bool isConfigured\n    ) {\n        StablecoinConfig memory s = stablecoinInfo[token];\n        exchangeRate = s.exchangeRate;\n        decimals = s.decimals;\n        bonus = s.bonus;\n        isConfigured = s.isConfigured;\n    }\n}\n"},"Context.sol":{"content":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    function _contextSuffixLength() internal view virtual returns (uint256) {\n        return 0;\n    }\n}\n"},"IBarkcoin.sol":{"content":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\nimport \"./IERC20.sol\";\n\ninterface IBarkcoin is IERC20 {\n\n    function exchangeTransfer(address recipient, uint256 amount) external;\n\n}\n"},"IERC20.sol":{"content":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n    /**\n     * @dev Emitted when `value` tokens are moved from one account (`from`) to\n     * another (`to`).\n     *\n     * Note that `value` may be zero.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /**\n     * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n     * a call to {approve}. `value` is the new allowance.\n     */\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n\n    /**\n     * @dev Returns the value of tokens in existence.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns the value of tokens owned by `account`.\n     */\n    function balanceOf(address account) external view returns (uint256);\n\n    /**\n     * @dev Moves a `value` amount of tokens from the caller\u0027s account to `to`.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transfer(address to, uint256 value) external returns (bool);\n\n    /**\n     * @dev Returns the remaining number of tokens that `spender` will be\n     * allowed to spend on behalf of `owner` through {transferFrom}. This is\n     * zero by default.\n     *\n     * This value changes when {approve} or {transferFrom} are called.\n     */\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /**\n     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n     * caller\u0027s tokens.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * IMPORTANT: Beware that changing an allowance with this method brings the risk\n     * that someone may use both the old and the new allowance by unfortunate\n     * transaction ordering. One possible solution to mitigate this race\n     * condition is to first reduce the spender\u0027s allowance to 0 and set the\n     * desired value afterwards:\n     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address spender, uint256 value) external returns (bool);\n\n    /**\n     * @dev Moves a `value` amount of tokens from `from` to `to` using the\n     * allowance mechanism. `value` is then deducted from the caller\u0027s\n     * allowance.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(address from, address to, uint256 value) external returns (bool);\n}\n"},"IERC20Metadata.sol":{"content":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"./IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n */\ninterface IERC20Metadata is IERC20 {\n    /**\n     * @dev Returns the name of the token.\n     */\n    function name() external view returns (string memory);\n\n    /**\n     * @dev Returns the symbol of the token.\n     */\n    function symbol() external view returns (string memory);\n\n    /**\n     * @dev Returns the decimals places of the token.\n     */\n    function decimals() external view returns (uint8);\n}\n"},"ITether.sol":{"content":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface ITether {\n    function transferFrom(address from, address to, uint value) external;\n}\n"},"Ownable.sol":{"content":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)\n\npragma solidity ^0.8.20;\n\nimport {Context} from \"./Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * The initial owner is set to the address provided by the deployer. This can\n * later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n    address private _owner;\n\n    /**\n     * @dev The caller account is not authorized to perform an operation.\n     */\n    error OwnableUnauthorizedAccount(address account);\n\n    /**\n     * @dev The owner is not a valid owner account. (eg. `address(0)`)\n     */\n    error OwnableInvalidOwner(address owner);\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.\n     */\n    constructor(address initialOwner) {\n        if (initialOwner == address(0)) {\n            revert OwnableInvalidOwner(address(0));\n        }\n        _transferOwnership(initialOwner);\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        if (owner() != _msgSender()) {\n            revert OwnableUnauthorizedAccount(_msgSender());\n        }\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        if (newOwner == address(0)) {\n            revert OwnableInvalidOwner(address(0));\n        }\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n}\n"}}