ETH Price: $2,246.06 (-1.24%)

Transaction Decoder

Block:
19616654 at Apr-09-2024 07:39:23 AM +UTC
Transaction Fee:
0.00199228779180666 ETH $4.47
Gas Used:
87,966 Gas / 22.64838451 Gwei

Emitted Events:

192 ERC315Token.Transfer( from=[Sender] 0x38d35b5c5c6a48d90bd43caaa9920269a9d63766, to=[Receiver] ERC315Token, value=46564110439825563301397 )
193 ERC315Token.RSwap( sender=[Sender] 0x38d35b5c5c6a48d90bd43caaa9920269a9d63766, amount0In=0, amount1In=46564110439825563301397, amount0Out=45226508268562407, amount1Out=0 )
194 ERC315LPToken.DividendsDistributed( from=[Receiver] ERC315Token, weiAmount=135679524805687 )

Account State Difference:

  Address   Before After State Difference Code
0x2A760D56...41dc9A020 16.75099793435341642 Eth16.705771426084854013 Eth0.045226508268562407
0x38d35b5C...9A9d63766
0.059439221813433645 Eth
Nonce: 352
0.101180967517326833 Eth
Nonce: 353
0.041741745703893188
0x62153f2E...638d2BEce 24.531824272458115796 Eth24.533181067706172668 Eth0.001356795248056872
0x6F295FC0...89f3512bE 2.319538901814977401 Eth2.319674581339783088 Eth0.000135679524805687
(beaverbuild)
5.523981999051431556 Eth5.523990707685431556 Eth0.000008708634

Execution Trace

ERC315Token.transfer( to=0x2A760D56Fa7aB2ebeFe5991dC44e82B41dc9A020, value=46564110439825563301397 ) => ( True )
  • ETH 0.001356795248056872 0x62153f2e24fb1472d35968c2e262375638d2bece.CALL( )
  • ETH 0.000135679524805687 ERC315LPToken.CALL( )
  • ETH 0.043734033495699848 0x38d35b5c5c6a48d90bd43caaa9920269a9d63766.CALL( )
    File 1 of 2: ERC315Token
    // 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);
        }
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
    pragma solidity ^0.8.20;
    /**
     * @dev Standard ERC20 Errors
     * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens.
     */
    interface IERC20Errors {
        /**
         * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
         * @param sender Address whose tokens are being transferred.
         * @param balance Current balance for the interacting account.
         * @param needed Minimum amount required to perform a transfer.
         */
        error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
        /**
         * @dev Indicates a failure with the token `sender`. Used in transfers.
         * @param sender Address whose tokens are being transferred.
         */
        error ERC20InvalidSender(address sender);
        /**
         * @dev Indicates a failure with the token `receiver`. Used in transfers.
         * @param receiver Address to which tokens are being transferred.
         */
        error ERC20InvalidReceiver(address receiver);
        /**
         * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
         * @param spender Address that may be allowed to operate on tokens without being their owner.
         * @param allowance Amount of tokens a `spender` is allowed to operate with.
         * @param needed Minimum amount required to perform a transfer.
         */
        error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
        /**
         * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
         * @param approver Address initiating an approval operation.
         */
        error ERC20InvalidApprover(address approver);
        /**
         * @dev Indicates a failure with the `spender` to be approved. Used in approvals.
         * @param spender Address that may be allowed to operate on tokens without being their owner.
         */
        error ERC20InvalidSpender(address spender);
    }
    /**
     * @dev Standard ERC721 Errors
     * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
     */
    interface IERC721Errors {
        /**
         * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20.
         * Used in balance queries.
         * @param owner Address of the current owner of a token.
         */
        error ERC721InvalidOwner(address owner);
        /**
         * @dev Indicates a `tokenId` whose `owner` is the zero address.
         * @param tokenId Identifier number of a token.
         */
        error ERC721NonexistentToken(uint256 tokenId);
        /**
         * @dev Indicates an error related to the ownership over a particular token. Used in transfers.
         * @param sender Address whose tokens are being transferred.
         * @param tokenId Identifier number of a token.
         * @param owner Address of the current owner of a token.
         */
        error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
        /**
         * @dev Indicates a failure with the token `sender`. Used in transfers.
         * @param sender Address whose tokens are being transferred.
         */
        error ERC721InvalidSender(address sender);
        /**
         * @dev Indicates a failure with the token `receiver`. Used in transfers.
         * @param receiver Address to which tokens are being transferred.
         */
        error ERC721InvalidReceiver(address receiver);
        /**
         * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
         * @param operator Address that may be allowed to operate on tokens without being their owner.
         * @param tokenId Identifier number of a token.
         */
        error ERC721InsufficientApproval(address operator, uint256 tokenId);
        /**
         * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
         * @param approver Address initiating an approval operation.
         */
        error ERC721InvalidApprover(address approver);
        /**
         * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
         * @param operator Address that may be allowed to operate on tokens without being their owner.
         */
        error ERC721InvalidOperator(address operator);
    }
    /**
     * @dev Standard ERC1155 Errors
     * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens.
     */
    interface IERC1155Errors {
        /**
         * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
         * @param sender Address whose tokens are being transferred.
         * @param balance Current balance for the interacting account.
         * @param needed Minimum amount required to perform a transfer.
         * @param tokenId Identifier number of a token.
         */
        error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
        /**
         * @dev Indicates a failure with the token `sender`. Used in transfers.
         * @param sender Address whose tokens are being transferred.
         */
        error ERC1155InvalidSender(address sender);
        /**
         * @dev Indicates a failure with the token `receiver`. Used in transfers.
         * @param receiver Address to which tokens are being transferred.
         */
        error ERC1155InvalidReceiver(address receiver);
        /**
         * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
         * @param operator Address that may be allowed to operate on tokens without being their owner.
         * @param owner Address of the current owner of a token.
         */
        error ERC1155MissingApprovalForAll(address operator, address owner);
        /**
         * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
         * @param approver Address initiating an approval operation.
         */
        error ERC1155InvalidApprover(address approver);
        /**
         * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
         * @param operator Address that may be allowed to operate on tokens without being their owner.
         */
        error ERC1155InvalidOperator(address operator);
        /**
         * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
         * Used in batch transfers.
         * @param idsLength Length of the array of token identifiers
         * @param valuesLength Length of the array of token amounts
         */
        error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/ERC20.sol)
    pragma solidity ^0.8.20;
    import {IERC20} from "./IERC20.sol";
    import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
    import {Context} from "../../utils/Context.sol";
    import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";
    /**
     * @dev Implementation of the {IERC20} interface.
     *
     * This implementation is agnostic to the way tokens are created. This means
     * that a supply mechanism has to be added in a derived contract using {_mint}.
     *
     * TIP: For a detailed writeup see our guide
     * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
     * to implement supply mechanisms].
     *
     * The default value of {decimals} is 18. To change this, you should override
     * this function so it returns a different value.
     *
     * We have followed general OpenZeppelin Contracts guidelines: functions revert
     * instead returning `false` on failure. This behavior is nonetheless
     * conventional and does not conflict with the expectations of ERC20
     * applications.
     *
     * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
     * This allows applications to reconstruct the allowance for all accounts just
     * by listening to said events. Other implementations of the EIP may not emit
     * these events, as it isn't required by the specification.
     */
    abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
        mapping(address account => uint256) private _balances;
        mapping(address account => mapping(address spender => uint256)) private _allowances;
        uint256 private _totalSupply;
        string private _name;
        string private _symbol;
        /**
         * @dev Sets the values for {name} and {symbol}.
         *
         * All two of these values are immutable: they can only be set once during
         * construction.
         */
        constructor(string memory name_, string memory symbol_) {
            _name = name_;
            _symbol = symbol_;
        }
        /**
         * @dev Returns the name of the token.
         */
        function name() public view virtual returns (string memory) {
            return _name;
        }
        /**
         * @dev Returns the symbol of the token, usually a shorter version of the
         * name.
         */
        function symbol() public view virtual returns (string memory) {
            return _symbol;
        }
        /**
         * @dev Returns the number of decimals used to get its user representation.
         * For example, if `decimals` equals `2`, a balance of `505` tokens should
         * be displayed to a user as `5.05` (`505 / 10 ** 2`).
         *
         * Tokens usually opt for a value of 18, imitating the relationship between
         * Ether and Wei. This is the default value returned by this function, unless
         * it's overridden.
         *
         * NOTE: This information is only used for _display_ purposes: it in
         * no way affects any of the arithmetic of the contract, including
         * {IERC20-balanceOf} and {IERC20-transfer}.
         */
        function decimals() public view virtual returns (uint8) {
            return 18;
        }
        /**
         * @dev See {IERC20-totalSupply}.
         */
        function totalSupply() public view virtual returns (uint256) {
            return _totalSupply;
        }
        /**
         * @dev See {IERC20-balanceOf}.
         */
        function balanceOf(address account) public view virtual returns (uint256) {
            return _balances[account];
        }
        /**
         * @dev See {IERC20-transfer}.
         *
         * Requirements:
         *
         * - `to` cannot be the zero address.
         * - the caller must have a balance of at least `value`.
         */
        function transfer(address to, uint256 value) public virtual returns (bool) {
            address owner = _msgSender();
            _transfer(owner, to, value);
            return true;
        }
        /**
         * @dev See {IERC20-allowance}.
         */
        function allowance(address owner, address spender) public view virtual returns (uint256) {
            return _allowances[owner][spender];
        }
        /**
         * @dev See {IERC20-approve}.
         *
         * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
         * `transferFrom`. This is semantically equivalent to an infinite approval.
         *
         * Requirements:
         *
         * - `spender` cannot be the zero address.
         */
        function approve(address spender, uint256 value) public virtual returns (bool) {
            address owner = _msgSender();
            _approve(owner, spender, value);
            return true;
        }
        /**
         * @dev See {IERC20-transferFrom}.
         *
         * Emits an {Approval} event indicating the updated allowance. This is not
         * required by the EIP. See the note at the beginning of {ERC20}.
         *
         * NOTE: Does not update the allowance if the current allowance
         * is the maximum `uint256`.
         *
         * Requirements:
         *
         * - `from` and `to` cannot be the zero address.
         * - `from` must have a balance of at least `value`.
         * - the caller must have allowance for ``from``'s tokens of at least
         * `value`.
         */
        function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
            address spender = _msgSender();
            _spendAllowance(from, spender, value);
            _transfer(from, to, value);
            return true;
        }
        /**
         * @dev Moves a `value` amount of tokens from `from` to `to`.
         *
         * This internal function is equivalent to {transfer}, and can be used to
         * e.g. implement automatic token fees, slashing mechanisms, etc.
         *
         * Emits a {Transfer} event.
         *
         * NOTE: This function is not virtual, {_update} should be overridden instead.
         */
        function _transfer(address from, address to, uint256 value) internal {
            if (from == address(0)) {
                revert ERC20InvalidSender(address(0));
            }
            if (to == address(0)) {
                revert ERC20InvalidReceiver(address(0));
            }
            _update(from, to, value);
        }
        /**
         * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
         * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
         * this function.
         *
         * Emits a {Transfer} event.
         */
        function _update(address from, address to, uint256 value) internal virtual {
            if (from == address(0)) {
                // Overflow check required: The rest of the code assumes that totalSupply never overflows
                _totalSupply += value;
            } else {
                uint256 fromBalance = _balances[from];
                if (fromBalance < value) {
                    revert ERC20InsufficientBalance(from, fromBalance, value);
                }
                unchecked {
                    // Overflow not possible: value <= fromBalance <= totalSupply.
                    _balances[from] = fromBalance - value;
                }
            }
            if (to == address(0)) {
                unchecked {
                    // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
                    _totalSupply -= value;
                }
            } else {
                unchecked {
                    // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
                    _balances[to] += value;
                }
            }
            emit Transfer(from, to, value);
        }
        /**
         * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
         * Relies on the `_update` mechanism
         *
         * Emits a {Transfer} event with `from` set to the zero address.
         *
         * NOTE: This function is not virtual, {_update} should be overridden instead.
         */
        function _mint(address account, uint256 value) internal {
            if (account == address(0)) {
                revert ERC20InvalidReceiver(address(0));
            }
            _update(address(0), account, value);
        }
        /**
         * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
         * Relies on the `_update` mechanism.
         *
         * Emits a {Transfer} event with `to` set to the zero address.
         *
         * NOTE: This function is not virtual, {_update} should be overridden instead
         */
        function _burn(address account, uint256 value) internal {
            if (account == address(0)) {
                revert ERC20InvalidSender(address(0));
            }
            _update(account, address(0), value);
        }
        /**
         * @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
         *
         * This internal function is equivalent to `approve`, and can be used to
         * e.g. set automatic allowances for certain subsystems, etc.
         *
         * Emits an {Approval} event.
         *
         * Requirements:
         *
         * - `owner` cannot be the zero address.
         * - `spender` cannot be the zero address.
         *
         * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
         */
        function _approve(address owner, address spender, uint256 value) internal {
            _approve(owner, spender, value, true);
        }
        /**
         * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
         *
         * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
         * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
         * `Approval` event during `transferFrom` operations.
         *
         * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
         * true using the following override:
         * ```
         * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
         *     super._approve(owner, spender, value, true);
         * }
         * ```
         *
         * Requirements are the same as {_approve}.
         */
        function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
            if (owner == address(0)) {
                revert ERC20InvalidApprover(address(0));
            }
            if (spender == address(0)) {
                revert ERC20InvalidSpender(address(0));
            }
            _allowances[owner][spender] = value;
            if (emitEvent) {
                emit Approval(owner, spender, value);
            }
        }
        /**
         * @dev Updates `owner` s allowance for `spender` based on spent `value`.
         *
         * Does not update the allowance value in case of infinite allowance.
         * Revert if not enough allowance is available.
         *
         * Does not emit an {Approval} event.
         */
        function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
            uint256 currentAllowance = allowance(owner, spender);
            if (currentAllowance != type(uint256).max) {
                if (currentAllowance < value) {
                    revert ERC20InsufficientAllowance(spender, currentAllowance, value);
                }
                unchecked {
                    _approve(owner, spender, currentAllowance - value, false);
                }
            }
        }
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)
    pragma solidity ^0.8.20;
    import {IERC20} from "../IERC20.sol";
    /**
     * @dev Interface for the optional metadata functions from the ERC20 standard.
     */
    interface IERC20Metadata is IERC20 {
        /**
         * @dev Returns the name of the token.
         */
        function name() external view returns (string memory);
        /**
         * @dev Returns the symbol of the token.
         */
        function symbol() external view returns (string memory);
        /**
         * @dev Returns the decimals places of the token.
         */
        function decimals() external view returns (uint8);
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
    pragma solidity ^0.8.20;
    /**
     * @dev Interface of the ERC20 standard as defined in the EIP.
     */
    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);
    }
    // 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;
        }
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts (last updated v5.0.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 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;
        }
    }
    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.23;
    import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
    import {IDividendTracker} from "./interfaces/IDividendTracker.sol";
    import {SafeMath, SafeMathUint, SafeMathInt} from "./libs/SafeMath.sol";
    abstract contract DividendTracker is ERC20, IDividendTracker {
        using SafeMath for uint256;
        using SafeMathUint for uint256;
        using SafeMathInt for int256;
        // With `magnitude`, we can properly distribute dividends even if the amount of received ether is small.
        // For more discussion about choosing the value of `magnitude`,
        //  see https://github.com/ethereum/EIPs/issues/1726#issuecomment-472352728
        uint256 internal constant magnitude = 2 ** 128;
        uint256 internal magnifiedDividendPerShare;
        // About dividendCorrection:
        // If the token balance of a `_user` is never changed, the dividend of `_user` can be computed with:
        //   `dividendOf(_user) = dividendPerShare * balanceOf(_user)`.
        // When `balanceOf(_user)` is changed (via minting/burning/transferring tokens),
        //   `dividendOf(_user)` should not be changed,
        //   but the computed value of `dividendPerShare * balanceOf(_user)` is changed.
        // To keep the `dividendOf(_user)` unchanged, we add a correction term:
        //   `dividendOf(_user) = dividendPerShare * balanceOf(_user) + dividendCorrectionOf(_user)`,
        //   where `dividendCorrectionOf(_user)` is updated whenever `balanceOf(_user)` is changed:
        //   `dividendCorrectionOf(_user) = dividendPerShare * (old balanceOf(_user)) - (new balanceOf(_user))`.
        // So now `dividendOf(_user)` returns the same value before and after `balanceOf(_user)` is changed.
        mapping(address => int256) internal magnifiedDividendCorrections;
        mapping(address => uint256) internal withdrawnDividends;
        uint256 public totalDividendsDistributed;
        uint256 public totalDividendsWithdrawn;
        constructor(
            string memory _name,
            string memory _symbol
        ) ERC20(_name, _symbol) {}
        function _distribute(uint256 amount) internal virtual {
            require(totalSupply() > 0);
            if (amount > 0) {
                magnifiedDividendPerShare = magnifiedDividendPerShare.add(
                    (amount).mul(magnitude) / totalSupply()
                );
                emit DividendsDistributed(msg.sender, amount);
                totalDividendsDistributed = totalDividendsDistributed.add(amount);
            }
        }
        /// @notice Withdraws the ether distributed to the sender.
        /// @dev It emits a `DividendWithdrawn` event if the amount of withdrawn ether is greater than 0.
        function _withdrawDividendOfUser(
            address payable user
        ) internal returns (uint256) {
            uint256 _withdrawableDividend = withdrawableDividendOf(user);
            if (_withdrawableDividend > 0) {
                withdrawnDividends[user] = withdrawnDividends[user].add(
                    _withdrawableDividend
                );
                totalDividendsWithdrawn += _withdrawableDividend;
                emit DividendWithdrawn(user, _withdrawableDividend);
                (bool success, ) = user.call{value: _withdrawableDividend}("");
                if (!success) {
                    withdrawnDividends[user] = withdrawnDividends[user].sub(
                        _withdrawableDividend
                    );
                    totalDividendsWithdrawn -= _withdrawableDividend;
                    return 0;
                }
                return _withdrawableDividend;
            }
            return 0;
        }
        /// @notice View the amount of dividend in wei that an address can withdraw.
        /// @param _owner The address of a token holder.
        /// @return The amount of dividend in wei that `_owner` can withdraw.
        function dividendOf(address _owner) public view override returns (uint256) {
            return withdrawableDividendOf(_owner);
        }
        /// @notice View the amount of dividend in wei that an address can withdraw.
        /// @param _owner The address of a token holder.
        /// @return The amount of dividend in wei that `_owner` can withdraw.
        function withdrawableDividendOf(
            address _owner
        ) public view override returns (uint256) {
            return accumulativeDividendOf(_owner).sub(withdrawnDividends[_owner]);
        }
        /// @notice View the amount of dividend in wei that an address has withdrawn.
        /// @param _owner The address of a token holder.
        /// @return The amount of dividend in wei that `_owner` has withdrawn.
        function withdrawnDividendOf(
            address _owner
        ) public view override returns (uint256) {
            return withdrawnDividends[_owner];
        }
        /// @notice View the amount of dividend in wei that an address has earned in total.
        /// @dev accumulativeDividendOf(_owner) = withdrawableDividendOf(_owner) + withdrawnDividendOf(_owner)
        /// = (magnifiedDividendPerShare * balanceOf(_owner) + magnifiedDividendCorrections[_owner]) / magnitude
        /// @param _owner The address of a token holder.
        /// @return The amount of dividend in wei that `_owner` has earned in total.
        function accumulativeDividendOf(
            address _owner
        ) public view override returns (uint256) {
            return
                magnifiedDividendPerShare
                    .mul(balanceOf(_owner))
                    .toInt256Safe()
                    .add(magnifiedDividendCorrections[_owner])
                    .toUint256Safe() / magnitude;
        }
        function transfer(
            address to,
            uint256 value
        ) public override returns (bool) {
            super.transfer(to, value);
            address from = _msgSender();
            int256 _magCorrection = magnifiedDividendPerShare
                .mul(value)
                .toInt256Safe();
            magnifiedDividendCorrections[from] = magnifiedDividendCorrections[from]
                .add(_magCorrection);
            magnifiedDividendCorrections[to] = magnifiedDividendCorrections[to].sub(
                _magCorrection
            );
            return true;
        }
        function transferFrom(
            address from,
            address to,
            uint256 value
        ) public override returns (bool) {
            super.transferFrom(from, to, value);
            int256 _magCorrection = magnifiedDividendPerShare
                .mul(value)
                .toInt256Safe();
            magnifiedDividendCorrections[from] = magnifiedDividendCorrections[from]
                .add(_magCorrection);
            magnifiedDividendCorrections[to] = magnifiedDividendCorrections[to].sub(
                _magCorrection
            );
            return true;
        }
        function mint(address account, uint256 value) public virtual {
            super._mint(account, value);
            magnifiedDividendCorrections[account] = magnifiedDividendCorrections[
                account
            ].sub((magnifiedDividendPerShare.mul(value)).toInt256Safe());
        }
        function burn(address account, uint256 value) public virtual {
            super._burn(account, value);
            magnifiedDividendCorrections[account] = magnifiedDividendCorrections[
                account
            ].add((magnifiedDividendPerShare.mul(value)).toInt256Safe());
        }
    }
    // SPDX-License-Identifier: UNLICENSED
    // The RefinERC represents an endeavor aimed at developing the Ethereum ecosystem through the implementation of the innovative ERC-315 standard.
    pragma solidity ^0.8.23;
    import {Context} from "@openzeppelin/contracts/utils/Context.sol";
    import {IERC315} from "./interfaces/IERC315.sol";
    import {ERC315LPToken} from "./ERC315LPToken.sol";
    abstract contract ERC315 is IERC315, Context {
        uint256 private _totalSupply;
        string private _name;
        string private _symbol;
        address payable public lp;
        uint256 public X;
        mapping(address account => uint256) private _balances;
        mapping(address account => uint32) private lastTransaction;
        constructor(
            string memory name_,
            string memory symbol_,
            uint256 totalSupply_,
            address _initTransferAddr
        ) {
            _name = name_;
            _symbol = symbol_;
            _totalSupply = totalSupply_;
            _balances[_initTransferAddr] = totalSupply_;
            emit Transfer(address(0), _initTransferAddr, totalSupply_);
        }
        function name() public view virtual returns (string memory) {
            return _name;
        }
        function symbol() public view virtual returns (string memory) {
            return _symbol;
        }
        function decimals() public view virtual returns (uint8) {
            return 18;
        }
        function totalSupply() public view virtual returns (uint256) {
            return _totalSupply;
        }
        function balanceOf(address account) public view virtual returns (uint256) {
            return _balances[account];
        }
        function transfer(address to, uint256 value) public virtual returns (bool) {
            require(value > 0, "invalid amount");
            _transfer(_msgSender(), to, value);
            return true;
        }
        function _transfer(
            address from,
            address to,
            uint256 value
        ) internal virtual {
            require(
                lastTransaction[_msgSender()] != block.number,
                "You can't make two transactions in the same block"
            );
            lastTransaction[_msgSender()] = uint32(block.number);
            require(
                _balances[from] >= value,
                "ERC20: transfer amount exceeds balance"
            );
            unchecked {
                _balances[from] = _balances[from] - value;
            }
            if (to == address(0)) {
                unchecked {
                    _totalSupply -= value;
                }
            } else {
                unchecked {
                    _balances[to] += value;
                }
            }
            emit Transfer(from, to, value);
        }
        function getReserves() public view returns (uint256, uint256) {
            return (address(this).balance, _balances[address(this)]);
        }
        function _getAmountOut(
            uint256 value,
            bool isbuy,
            uint256 msgValue
        ) internal view returns (uint256) {
            require(X > 0, "Liquidity not init");
            (uint256 reserveETH, uint256 reserveToken) = getReserves();
            reserveETH = reserveETH - msgValue;
            if (isbuy) {
                return (value * reserveToken) / (X * value + X * reserveETH);
            } else {
                return (value * X * reserveETH) / (value + reserveToken);
            }
        }
        function _getEthLPInitAmount(
            uint256 tokenAmount,
            uint256 tokenEthPrice
        ) internal pure returns (uint256) {
            return (tokenAmount / tokenEthPrice);
        }
        function _getLPAmount(
            uint256 amountTokenIn
        ) internal view returns (uint256 liquidity) {
            liquidity =
                (amountTokenIn * ERC315LPToken(lp).totalSupply()) /
                _balances[address(this)];
        }
        function initiateLiquidity(
            uint256 _tokenAmount,
            uint256 _tokenEthPrice,
            uint256 _x
        ) public payable virtual {
            require(_x > 0, "Invalid X");
            require(X == 0, "Liquidity already initiated");
            require(_tokenAmount > 0, "Invalid token amount");
            require(_tokenEthPrice > 0, "Invalid token price");
            _transfer(_msgSender(), address(this), _tokenAmount);
            X = _x;
            uint256 ethAmount = _getEthLPInitAmount(_tokenAmount, _tokenEthPrice);
            require(msg.value >= ethAmount, "Invalid ETH amount");
            if (msg.value > ethAmount) {
                _safeTransferETH(_msgSender(), msg.value - ethAmount);
            }
            lp = payable(address(new ERC315LPToken()));
            ERC315LPToken(lp).mint(_msgSender(), _tokenAmount);
        }
        function getETHInputAddLP(
            uint256 tokenAmount
        ) public view returns (uint256) {
            return _getETHInputAddLP(tokenAmount, 0);
        }
        function _getETHInputAddLP(
            uint256 tokenAmount,
            uint256 msgValue
        ) internal view returns (uint256) {
            (uint256 reserveETH, uint256 reserveToken) = getReserves();
            reserveETH = reserveETH - msgValue;
            return (tokenAmount * reserveETH) / reserveToken;
        }
        function getOutputRemoveLP(
            uint256 lpAmount
        ) public view returns (uint256 token, uint256 eth) {
            (uint256 reserveETH, uint256 reserveToken) = getReserves();
            token = (lpAmount * reserveToken) / ERC315LPToken(lp).totalSupply();
            eth = (lpAmount * reserveETH) / ERC315LPToken(lp).totalSupply();
        }
        function addLiquidity(
            uint256 _tokenAmount,
            uint256 _amountOutMin
        ) public payable virtual {
            require(X > 0, "Liquidity not initiated");
            require(_tokenAmount > 0, "Invalid token amount");
            uint256 ethRequired = _getETHInputAddLP(_tokenAmount, msg.value);
            require(
                msg.value > 0 && msg.value >= ethRequired,
                "invalid ETH amount"
            );
            uint256 amountLp = _getLPAmount(_tokenAmount);
            _transfer(_msgSender(), address(this), _tokenAmount);
            if (_amountOutMin > 0) {
                require(amountLp >= _amountOutMin, "Slippage limit exceeded");
            }
            ERC315LPToken(lp).mint(_msgSender(), amountLp);
            if (msg.value > ethRequired) {
                _safeTransferETH(_msgSender(), msg.value - ethRequired);
            }
            emit RAddLiquidity(_msgSender(), _tokenAmount, ethRequired, amountLp);
        }
        function removeLiquidity(
            uint256 _lpAmount,
            uint256 _amountTokenMin,
            uint256 _amountEthMin
        ) public virtual {
            require(X > 0, "Liquidity not initiated");
            require(_lpAmount > 0, "Invalid LP amount");
            (uint256 amountToken, uint256 amountEth) = getOutputRemoveLP(_lpAmount);
            if (_amountTokenMin > 0) {
                require(
                    amountToken >= _amountTokenMin,
                    "Slippage limit exceeded Token amount"
                );
            }
            if (_amountEthMin > 0) {
                require(
                    amountEth >= _amountEthMin,
                    "Slippage limit exceeded ETH amount"
                );
            }
            ERC315LPToken(lp).burn(_msgSender(), _lpAmount);
            _transfer(address(this), _msgSender(), amountToken);
            _safeTransferETH(_msgSender(), amountEth);
            emit RRemoveLiquidity(_msgSender(), _lpAmount, amountToken, amountEth);
        }
        function _buy(uint256 _amountEth, address _to) internal virtual {
            require(_amountEth > 0, "eth amount too low");
            uint256 token_amount = _getAmountOut(_amountEth, true, _amountEth);
            _transfer(address(this), _to, token_amount);
            emit RSwap(_to, _amountEth, 0, 0, token_amount);
        }
        function _sell(uint256 _amountToken, address _to) internal virtual {
            require(_amountToken > 0, "token amount too low");
            uint256 ethAmount = _getAmountOut(_amountToken, false, 0);
            require(ethAmount > 0, "Sell amount too low");
            require(
                address(this).balance >= ethAmount,
                "Insufficient ETH in reserves"
            );
            _transfer(_to, address(this), _amountToken);
            _safeTransferETH(_to, ethAmount);
            emit RSwap(_to, 0, _amountToken, ethAmount, 0);
        }
        function _safeTransferETH(address to, uint256 amount) internal {
            (bool sent, ) = payable(to).call{value: amount}("");
            require(sent, "Failed to send Ether");
        }
    }
    // SPDX-License-Identifier: UNLICENSED
    pragma solidity ^0.8.23;
    import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
    import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
    import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
    import {DividendTracker} from "./DividendTracker.sol";
    contract ERC315LPToken is DividendTracker, Ownable {
        event Claim(address indexed account, uint256 amount);
        struct AccountInfo {
            address account;
            uint256 withdrawableDividends;
            uint256 totalDividends;
            uint256 lastClaimTime;
        }
        constructor()
            DividendTracker("Liquidity Provide ERC315s", "LP-ERC315")
            Ownable(_msgSender())
        {}
        mapping(address => uint256) public lastClaimTimes;
        uint private unlocked = 1;
        modifier lock() {
            require(unlocked == 1, "LPToken: LOCKED");
            unlocked = 0;
            _;
            unlocked = 1;
        }
        function claimRewards() external {
            uint256 amount = _withdrawDividendOfUser(payable(_msgSender()));
            if (amount > 0) {
                lastClaimTimes[_msgSender()] = block.timestamp;
                emit Claim(_msgSender(), amount);
            }
        }
        function getAccount(
            address account
        ) public view returns (address, uint256, uint256, uint256, uint256) {
            AccountInfo memory info;
            info.account = account;
            info.withdrawableDividends = withdrawableDividendOf(account);
            info.totalDividends = accumulativeDividendOf(account);
            info.lastClaimTime = lastClaimTimes[account];
            return (
                info.account,
                info.withdrawableDividends,
                info.totalDividends,
                info.lastClaimTime,
                totalDividendsWithdrawn
            );
        }
        function mint(address to, uint256 amount) public override lock onlyOwner {
            super.mint(to, amount);
        }
        function burn(address from, uint256 amount) public override lock onlyOwner {
            super.burn(from, amount);
        }
        function burnLP(uint256 amount) public lock {
            super.burn(_msgSender(), amount);
        }
        receive() external payable {
            uint256 totalAmount = msg.value;
            if (totalSupply() > 0) {
                _distribute(totalAmount);
            }
        }
    }
    // The RefinERC represents an endeavor aimed at developing the Ethereum ecosystem through the implementation of the innovative ERC-315 standard.
    // Website: https://refinerc.com
    // Docs: https://docs.refinerc.com
    // Twitter: https://x.com/refinerc
    // Telegram: https://t.me/Refinerc
    // Mail: [email protected]
    // SPDX-License-Identifier: UNLICENSED
    pragma solidity ^0.8.23;
    import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
    import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
    import {ERC315} from "./ERC315.sol";
    contract ERC315Token is ERC315, Ownable, ReentrancyGuard {
        event FeeAddressChanged(address newAddress);
        event LimitRemoved();
        // ERC315 publicly opens the "addLiquidity" function to all liquidity providers (an improvement to ERC314).
        // Liquidity providers will receive LP-ERC315 tokens when addLiquidity,
        // it is like dividend tokens so 0.3% trading fee can be easily allocated,
        // liquidity providers receive this fee by calling the function collect fees.
        uint256 public constant LIQUIDITY_PROVIDE_SHARE = 300; // 0.3%
        uint256 public immutable TOTAL_SUPPLY;
        uint256 public immutable BUY_TAX;
        uint256 public immutable SELL_TAX;
        uint256 public MAX_WALLET;
        mapping(address => bool) private _isExcludedFromFees;
        address public feeAddress;
        constructor(
            uint256 _buyTax,
            uint256 _sellTax,
            string memory _name,
            string memory _symbol,
            uint256 _initSupply,
            address _initOwner,
            uint256 _maxBuyAmount
        ) ERC315(_name, _symbol, _initSupply, _initOwner) Ownable(_initOwner) {
            require(_buyTax <= 5, "Buy tax too high");
            require(_sellTax <= 5, "Sell tax too high");
            feeAddress = _initOwner;
            BUY_TAX = _buyTax;
            SELL_TAX = _sellTax;
            TOTAL_SUPPLY = _initSupply;
            MAX_WALLET = _maxBuyAmount;
        }
        function excludedFromFees(
            address _address,
            bool _value
        ) external onlyOwner {
            _isExcludedFromFees[_address] = _value;
        }
        function removeLimits() external onlyOwner {
            require(MAX_WALLET != TOTAL_SUPPLY, "Limits already removed");
            MAX_WALLET = TOTAL_SUPPLY;
            emit LimitRemoved();
        }
        function getExcludedFromFees(address _address) public view returns (bool) {
            return _isExcludedFromFees[_address];
        }
        function getEthLPInitAmount(
            uint256 tokenAmount,
            uint256 tokenEthPrice
        ) public pure returns (uint256) {
            return _getEthLPInitAmount(tokenAmount, tokenEthPrice);
        }
        function getAmountOut(
            uint256 value,
            bool isbuy
        ) public view returns (uint256) {
            return _getAmountOut(value, isbuy, 0);
        }
        function getLPAmount(uint256 amountTokenIn) public view returns (uint256) {
            return _getLPAmount(amountTokenIn);
        }
        function initiateLiquidity(
            uint256 _tokenAmount,
            uint256 _tokenEthPrice,
            uint256 _x
        ) public payable override onlyOwner {
            super.initiateLiquidity(_tokenAmount, _tokenEthPrice, _x);
        }
        function addLiquidity(
            uint256 _tokenAmount,
            uint256 _amountOutMin
        ) public payable override nonReentrant {
            super.addLiquidity(_tokenAmount, _amountOutMin);
        }
        function removeLiquidity(
            uint256 _lpAmount,
            uint256 _tokenAmountMin,
            uint256 _ethAmountMin
        ) public override nonReentrant {
            super.removeLiquidity(_lpAmount, _tokenAmountMin, _ethAmountMin);
        }
        function sellAntiBot(
            uint256 _amountToken,
            uint256 _amountOutMin
        ) external nonReentrant {
            uint256 ethAmount = _getAmountOut(_amountToken, false, 0);
            if (_amountOutMin > 0) {
                require(ethAmount >= _amountOutMin, "Slippage limit exceeded");
            }
            _sell(_amountToken, _msgSender());
        }
        function buyAntiBot(uint256 _amountOutMin) external payable nonReentrant {
            require(X > 0, "Liquidity not initiated");
            uint256 token_amount = _getAmountOut(msg.value, true, msg.value);
            if (_amountOutMin > 0) {
                require(token_amount >= _amountOutMin, "Slippage limit exceeded");
            }
            _buy(msg.value, _msgSender());
        }
        function _transfer(
            address from,
            address to,
            uint256 value
        ) internal override {
            if (from == address(this)) {
                require(value + balanceOf(to) < MAX_WALLET, "Max amount exceeded");
            }
            super._transfer(from, to, value);
        }
        function _buy(uint256 ethAmount, address to) internal override {
            if (!_isExcludedFromFees[to] && BUY_TAX > 0) {
                uint256 fee = (ethAmount * BUY_TAX) / 100;
                if (fee > 0) {
                    _safeTransferETH(feeAddress, fee);
                }
                uint256 LPS = (ethAmount * LIQUIDITY_PROVIDE_SHARE) / 100000;
                if (LPS > 0) {
                    _safeTransferETH(lp, LPS);
                }
                ethAmount = ethAmount - fee - LPS;
            }
            super._buy(ethAmount, to);
        }
        function _sell(uint256 tokenAmount, address to) internal override {
            require(tokenAmount > 0, "token amount too low");
            _transfer(to, address(this), tokenAmount);
            uint256 ethAmount = _getAmountOut(tokenAmount, false, 0);
            require(ethAmount > 0, "Sell amount too low");
            if (address(this).balance < ethAmount) {
                ethAmount = address(this).balance;
            }
            emit RSwap(to, 0, tokenAmount, ethAmount, 0);
            if (!_isExcludedFromFees[to] && SELL_TAX > 0) {
                uint256 fee = (ethAmount * SELL_TAX) / 100;
                if (fee > 0) {
                    _safeTransferETH(feeAddress, fee);
                }
                uint256 LPS = (ethAmount * LIQUIDITY_PROVIDE_SHARE) / 100000;
                if (LPS > 0) {
                    _safeTransferETH(lp, LPS);
                }
                ethAmount = ethAmount - fee - LPS;
            }
            _safeTransferETH(to, ethAmount);
        }
        function transfer(
            address to,
            uint256 value
        ) public override returns (bool) {
            if (to == address(this)) {
                _sell(value, _msgSender());
            } else {
                super.transfer(to, value);
            }
            return true;
        }
        function changeFeeAddress(address _newAddress) external {
            require(
                _msgSender() == owner() || _msgSender() == feeAddress,
                "caller is not the owner"
            );
            feeAddress = _newAddress;
            emit FeeAddressChanged(_newAddress);
        }
        receive() external payable {
            uint256 ethAmount = msg.value;
            _buy(ethAmount, _msgSender());
        }
    }
    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.23;
    interface IDividendTracker {
        /// @notice View the amount of dividend in wei that an address can withdraw.
        /// @param _owner The address of a token holder.
        /// @return The amount of dividend in wei that `_owner` can withdraw.
        function dividendOf(address _owner) external view returns (uint256);
        /// @notice View the amount of dividend in wei that an address can withdraw.
        /// @param _owner The address of a token holder.
        /// @return The amount of dividend in wei that `_owner` can withdraw.
        function withdrawableDividendOf(
            address _owner
        ) external view returns (uint256);
        /// @notice View the amount of dividend in wei that an address has withdrawn.
        /// @param _owner The address of a token holder.
        /// @return The amount of dividend in wei that `_owner` has withdrawn.
        function withdrawnDividendOf(
            address _owner
        ) external view returns (uint256);
        /// @notice View the amount of dividend in wei that an address has earned in total.
        /// @dev accumulativeDividendOf(_owner) = withdrawableDividendOf(_owner) + withdrawnDividendOf(_owner)
        /// @param _owner The address of a token holder.
        /// @return The amount of dividend in wei that `_owner` has earned in total.
        function accumulativeDividendOf(
            address _owner
        ) external view returns (uint256);
        /// @dev This event MUST emit when ether is distributed to token holders.
        /// @param from The address which sends ether to this contract.
        /// @param weiAmount The amount of distributed ether in wei.
        event DividendsDistributed(address indexed from, uint256 weiAmount);
        /// @dev This event MUST emit when an address withdraws their dividend.
        /// @param to The address which withdraws ether from this contract.
        /// @param weiAmount The amount of withdrawn ether in wei.
        event DividendWithdrawn(address indexed to, uint256 weiAmount);
    }
    // SPDX-License-Identifier: UNLICENSED
    pragma solidity ^0.8.23;
    interface IERC315 {
        event Transfer(address indexed from, address indexed to, uint256 value);
        event RAddLiquidity(
            address indexed from,
            uint256 token,
            uint256 eth,
            uint256 liquidity
        );
        event RRemoveLiquidity(
            address indexed from,
            uint256 token,
            uint256 eth,
            uint256 liquidity
        );
        event RSwap(
            address indexed sender,
            uint amount0In,
            uint amount1In,
            uint amount0Out,
            uint amount1Out
        );
    }
    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.6;
    library SafeMath {
        /**
         * @dev Returns the addition of two unsigned integers, reverting on
         * overflow.
         *
         * Counterpart to Solidity's `+` operator.
         *
         * Requirements:
         *
         * - Addition cannot overflow.
         */
        function add(uint256 a, uint256 b) internal pure returns (uint256) {
            uint256 c = a + b;
            require(c >= a, "SafeMath: addition overflow");
            return c;
        }
        /**
         * @dev Returns the subtraction of two unsigned integers, reverting on
         * overflow (when the result is negative).
         *
         * Counterpart to Solidity's `-` operator.
         *
         * Requirements:
         *
         * - Subtraction cannot overflow.
         */
        function sub(uint256 a, uint256 b) internal pure returns (uint256) {
            return sub(a, b, "SafeMath: subtraction overflow");
        }
        /**
         * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
         * overflow (when the result is negative).
         *
         * Counterpart to Solidity's `-` operator.
         *
         * Requirements:
         *
         * - Subtraction cannot overflow.
         */
        function sub(
            uint256 a,
            uint256 b,
            string memory errorMessage
        ) internal pure returns (uint256) {
            require(b <= a, errorMessage);
            uint256 c = a - b;
            return c;
        }
        /**
         * @dev Returns the multiplication of two unsigned integers, reverting on
         * overflow.
         *
         * Counterpart to Solidity's `*` operator.
         *
         * Requirements:
         *
         * - Multiplication cannot overflow.
         */
        function mul(uint256 a, uint256 b) internal pure returns (uint256) {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) {
                return 0;
            }
            uint256 c = a * b;
            require(c / a == b, "SafeMath: multiplication overflow");
            return c;
        }
        /**
         * @dev Returns the integer division of two unsigned integers. Reverts on
         * division by zero. The result is rounded towards zero.
         *
         * Counterpart to Solidity's `/` operator. Note: this function uses a
         * `revert` opcode (which leaves remaining gas untouched) while Solidity
         * uses an invalid opcode to revert (consuming all remaining gas).
         *
         * Requirements:
         *
         * - The divisor cannot be zero.
         */
        function div(uint256 a, uint256 b) internal pure returns (uint256) {
            return div(a, b, "SafeMath: division by zero");
        }
        /**
         * @dev Returns the integer division of two unsigned integers. Reverts with custom message on
         * division by zero. The result is rounded towards zero.
         *
         * Counterpart to Solidity's `/` operator. Note: this function uses a
         * `revert` opcode (which leaves remaining gas untouched) while Solidity
         * uses an invalid opcode to revert (consuming all remaining gas).
         *
         * Requirements:
         *
         * - The divisor cannot be zero.
         */
        function div(
            uint256 a,
            uint256 b,
            string memory errorMessage
        ) internal pure returns (uint256) {
            require(b > 0, errorMessage);
            uint256 c = a / b;
            // assert(a == b * c + a % b); // There is no case in which this doesn't hold
            return c;
        }
        /**
         * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
         * Reverts when dividing by zero.
         *
         * Counterpart to Solidity's `%` operator. This function uses a `revert`
         * opcode (which leaves remaining gas untouched) while Solidity uses an
         * invalid opcode to revert (consuming all remaining gas).
         *
         * Requirements:
         *
         * - The divisor cannot be zero.
         */
        function mod(uint256 a, uint256 b) internal pure returns (uint256) {
            return mod(a, b, "SafeMath: modulo by zero");
        }
        /**
         * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
         * Reverts with custom message when dividing by zero.
         *
         * Counterpart to Solidity's `%` operator. This function uses a `revert`
         * opcode (which leaves remaining gas untouched) while Solidity uses an
         * invalid opcode to revert (consuming all remaining gas).
         *
         * Requirements:
         *
         * - The divisor cannot be zero.
         */
        function mod(
            uint256 a,
            uint256 b,
            string memory errorMessage
        ) internal pure returns (uint256) {
            require(b != 0, errorMessage);
            return a % b;
        }
    }
    /**
     * @title SafeMathInt
     * @dev Math operations for int256 with overflow safety checks.
     */
    library SafeMathInt {
        int256 private constant MIN_INT256 = int256(1) << 255;
        int256 private constant MAX_INT256 = ~(int256(1) << 255);
        /**
         * @dev Multiplies two int256 variables and fails on overflow.
         */
        function mul(int256 a, int256 b) internal pure returns (int256) {
            int256 c = a * b;
            // Detect overflow when multiplying MIN_INT256 with -1
            require(c != MIN_INT256 || (a & MIN_INT256) != (b & MIN_INT256));
            require((b == 0) || (c / b == a));
            return c;
        }
        /**
         * @dev Division of two int256 variables and fails on overflow.
         */
        function div(int256 a, int256 b) internal pure returns (int256) {
            // Prevent overflow when dividing MIN_INT256 by -1
            require(b != -1 || a != MIN_INT256);
            // Solidity already throws when dividing by 0.
            return a / b;
        }
        /**
         * @dev Subtracts two int256 variables and fails on overflow.
         */
        function sub(int256 a, int256 b) internal pure returns (int256) {
            int256 c = a - b;
            require((b >= 0 && c <= a) || (b < 0 && c > a));
            return c;
        }
        /**
         * @dev Adds two int256 variables and fails on overflow.
         */
        function add(int256 a, int256 b) internal pure returns (int256) {
            int256 c = a + b;
            require((b >= 0 && c >= a) || (b < 0 && c < a));
            return c;
        }
        /**
         * @dev Converts to absolute value, and fails on overflow.
         */
        function abs(int256 a) internal pure returns (int256) {
            require(a != MIN_INT256);
            return a < 0 ? -a : a;
        }
        function toUint256Safe(int256 a) internal pure returns (uint256) {
            require(a >= 0);
            return uint256(a);
        }
    }
    /**
     * @title SafeMathUint
     * @dev Math operations with safety checks that revert on error
     */
    library SafeMathUint {
        function toInt256Safe(uint256 a) internal pure returns (int256) {
            int256 b = int256(a);
            require(b >= 0);
            return b;
        }
    }
    

    File 2 of 2: ERC315LPToken
    // 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);
        }
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
    pragma solidity ^0.8.20;
    /**
     * @dev Standard ERC20 Errors
     * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens.
     */
    interface IERC20Errors {
        /**
         * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
         * @param sender Address whose tokens are being transferred.
         * @param balance Current balance for the interacting account.
         * @param needed Minimum amount required to perform a transfer.
         */
        error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
        /**
         * @dev Indicates a failure with the token `sender`. Used in transfers.
         * @param sender Address whose tokens are being transferred.
         */
        error ERC20InvalidSender(address sender);
        /**
         * @dev Indicates a failure with the token `receiver`. Used in transfers.
         * @param receiver Address to which tokens are being transferred.
         */
        error ERC20InvalidReceiver(address receiver);
        /**
         * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
         * @param spender Address that may be allowed to operate on tokens without being their owner.
         * @param allowance Amount of tokens a `spender` is allowed to operate with.
         * @param needed Minimum amount required to perform a transfer.
         */
        error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
        /**
         * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
         * @param approver Address initiating an approval operation.
         */
        error ERC20InvalidApprover(address approver);
        /**
         * @dev Indicates a failure with the `spender` to be approved. Used in approvals.
         * @param spender Address that may be allowed to operate on tokens without being their owner.
         */
        error ERC20InvalidSpender(address spender);
    }
    /**
     * @dev Standard ERC721 Errors
     * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
     */
    interface IERC721Errors {
        /**
         * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20.
         * Used in balance queries.
         * @param owner Address of the current owner of a token.
         */
        error ERC721InvalidOwner(address owner);
        /**
         * @dev Indicates a `tokenId` whose `owner` is the zero address.
         * @param tokenId Identifier number of a token.
         */
        error ERC721NonexistentToken(uint256 tokenId);
        /**
         * @dev Indicates an error related to the ownership over a particular token. Used in transfers.
         * @param sender Address whose tokens are being transferred.
         * @param tokenId Identifier number of a token.
         * @param owner Address of the current owner of a token.
         */
        error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
        /**
         * @dev Indicates a failure with the token `sender`. Used in transfers.
         * @param sender Address whose tokens are being transferred.
         */
        error ERC721InvalidSender(address sender);
        /**
         * @dev Indicates a failure with the token `receiver`. Used in transfers.
         * @param receiver Address to which tokens are being transferred.
         */
        error ERC721InvalidReceiver(address receiver);
        /**
         * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
         * @param operator Address that may be allowed to operate on tokens without being their owner.
         * @param tokenId Identifier number of a token.
         */
        error ERC721InsufficientApproval(address operator, uint256 tokenId);
        /**
         * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
         * @param approver Address initiating an approval operation.
         */
        error ERC721InvalidApprover(address approver);
        /**
         * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
         * @param operator Address that may be allowed to operate on tokens without being their owner.
         */
        error ERC721InvalidOperator(address operator);
    }
    /**
     * @dev Standard ERC1155 Errors
     * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens.
     */
    interface IERC1155Errors {
        /**
         * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
         * @param sender Address whose tokens are being transferred.
         * @param balance Current balance for the interacting account.
         * @param needed Minimum amount required to perform a transfer.
         * @param tokenId Identifier number of a token.
         */
        error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
        /**
         * @dev Indicates a failure with the token `sender`. Used in transfers.
         * @param sender Address whose tokens are being transferred.
         */
        error ERC1155InvalidSender(address sender);
        /**
         * @dev Indicates a failure with the token `receiver`. Used in transfers.
         * @param receiver Address to which tokens are being transferred.
         */
        error ERC1155InvalidReceiver(address receiver);
        /**
         * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
         * @param operator Address that may be allowed to operate on tokens without being their owner.
         * @param owner Address of the current owner of a token.
         */
        error ERC1155MissingApprovalForAll(address operator, address owner);
        /**
         * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
         * @param approver Address initiating an approval operation.
         */
        error ERC1155InvalidApprover(address approver);
        /**
         * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
         * @param operator Address that may be allowed to operate on tokens without being their owner.
         */
        error ERC1155InvalidOperator(address operator);
        /**
         * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
         * Used in batch transfers.
         * @param idsLength Length of the array of token identifiers
         * @param valuesLength Length of the array of token amounts
         */
        error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/ERC20.sol)
    pragma solidity ^0.8.20;
    import {IERC20} from "./IERC20.sol";
    import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
    import {Context} from "../../utils/Context.sol";
    import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";
    /**
     * @dev Implementation of the {IERC20} interface.
     *
     * This implementation is agnostic to the way tokens are created. This means
     * that a supply mechanism has to be added in a derived contract using {_mint}.
     *
     * TIP: For a detailed writeup see our guide
     * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
     * to implement supply mechanisms].
     *
     * The default value of {decimals} is 18. To change this, you should override
     * this function so it returns a different value.
     *
     * We have followed general OpenZeppelin Contracts guidelines: functions revert
     * instead returning `false` on failure. This behavior is nonetheless
     * conventional and does not conflict with the expectations of ERC20
     * applications.
     *
     * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
     * This allows applications to reconstruct the allowance for all accounts just
     * by listening to said events. Other implementations of the EIP may not emit
     * these events, as it isn't required by the specification.
     */
    abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
        mapping(address account => uint256) private _balances;
        mapping(address account => mapping(address spender => uint256)) private _allowances;
        uint256 private _totalSupply;
        string private _name;
        string private _symbol;
        /**
         * @dev Sets the values for {name} and {symbol}.
         *
         * All two of these values are immutable: they can only be set once during
         * construction.
         */
        constructor(string memory name_, string memory symbol_) {
            _name = name_;
            _symbol = symbol_;
        }
        /**
         * @dev Returns the name of the token.
         */
        function name() public view virtual returns (string memory) {
            return _name;
        }
        /**
         * @dev Returns the symbol of the token, usually a shorter version of the
         * name.
         */
        function symbol() public view virtual returns (string memory) {
            return _symbol;
        }
        /**
         * @dev Returns the number of decimals used to get its user representation.
         * For example, if `decimals` equals `2`, a balance of `505` tokens should
         * be displayed to a user as `5.05` (`505 / 10 ** 2`).
         *
         * Tokens usually opt for a value of 18, imitating the relationship between
         * Ether and Wei. This is the default value returned by this function, unless
         * it's overridden.
         *
         * NOTE: This information is only used for _display_ purposes: it in
         * no way affects any of the arithmetic of the contract, including
         * {IERC20-balanceOf} and {IERC20-transfer}.
         */
        function decimals() public view virtual returns (uint8) {
            return 18;
        }
        /**
         * @dev See {IERC20-totalSupply}.
         */
        function totalSupply() public view virtual returns (uint256) {
            return _totalSupply;
        }
        /**
         * @dev See {IERC20-balanceOf}.
         */
        function balanceOf(address account) public view virtual returns (uint256) {
            return _balances[account];
        }
        /**
         * @dev See {IERC20-transfer}.
         *
         * Requirements:
         *
         * - `to` cannot be the zero address.
         * - the caller must have a balance of at least `value`.
         */
        function transfer(address to, uint256 value) public virtual returns (bool) {
            address owner = _msgSender();
            _transfer(owner, to, value);
            return true;
        }
        /**
         * @dev See {IERC20-allowance}.
         */
        function allowance(address owner, address spender) public view virtual returns (uint256) {
            return _allowances[owner][spender];
        }
        /**
         * @dev See {IERC20-approve}.
         *
         * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
         * `transferFrom`. This is semantically equivalent to an infinite approval.
         *
         * Requirements:
         *
         * - `spender` cannot be the zero address.
         */
        function approve(address spender, uint256 value) public virtual returns (bool) {
            address owner = _msgSender();
            _approve(owner, spender, value);
            return true;
        }
        /**
         * @dev See {IERC20-transferFrom}.
         *
         * Emits an {Approval} event indicating the updated allowance. This is not
         * required by the EIP. See the note at the beginning of {ERC20}.
         *
         * NOTE: Does not update the allowance if the current allowance
         * is the maximum `uint256`.
         *
         * Requirements:
         *
         * - `from` and `to` cannot be the zero address.
         * - `from` must have a balance of at least `value`.
         * - the caller must have allowance for ``from``'s tokens of at least
         * `value`.
         */
        function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
            address spender = _msgSender();
            _spendAllowance(from, spender, value);
            _transfer(from, to, value);
            return true;
        }
        /**
         * @dev Moves a `value` amount of tokens from `from` to `to`.
         *
         * This internal function is equivalent to {transfer}, and can be used to
         * e.g. implement automatic token fees, slashing mechanisms, etc.
         *
         * Emits a {Transfer} event.
         *
         * NOTE: This function is not virtual, {_update} should be overridden instead.
         */
        function _transfer(address from, address to, uint256 value) internal {
            if (from == address(0)) {
                revert ERC20InvalidSender(address(0));
            }
            if (to == address(0)) {
                revert ERC20InvalidReceiver(address(0));
            }
            _update(from, to, value);
        }
        /**
         * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
         * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
         * this function.
         *
         * Emits a {Transfer} event.
         */
        function _update(address from, address to, uint256 value) internal virtual {
            if (from == address(0)) {
                // Overflow check required: The rest of the code assumes that totalSupply never overflows
                _totalSupply += value;
            } else {
                uint256 fromBalance = _balances[from];
                if (fromBalance < value) {
                    revert ERC20InsufficientBalance(from, fromBalance, value);
                }
                unchecked {
                    // Overflow not possible: value <= fromBalance <= totalSupply.
                    _balances[from] = fromBalance - value;
                }
            }
            if (to == address(0)) {
                unchecked {
                    // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
                    _totalSupply -= value;
                }
            } else {
                unchecked {
                    // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
                    _balances[to] += value;
                }
            }
            emit Transfer(from, to, value);
        }
        /**
         * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
         * Relies on the `_update` mechanism
         *
         * Emits a {Transfer} event with `from` set to the zero address.
         *
         * NOTE: This function is not virtual, {_update} should be overridden instead.
         */
        function _mint(address account, uint256 value) internal {
            if (account == address(0)) {
                revert ERC20InvalidReceiver(address(0));
            }
            _update(address(0), account, value);
        }
        /**
         * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
         * Relies on the `_update` mechanism.
         *
         * Emits a {Transfer} event with `to` set to the zero address.
         *
         * NOTE: This function is not virtual, {_update} should be overridden instead
         */
        function _burn(address account, uint256 value) internal {
            if (account == address(0)) {
                revert ERC20InvalidSender(address(0));
            }
            _update(account, address(0), value);
        }
        /**
         * @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
         *
         * This internal function is equivalent to `approve`, and can be used to
         * e.g. set automatic allowances for certain subsystems, etc.
         *
         * Emits an {Approval} event.
         *
         * Requirements:
         *
         * - `owner` cannot be the zero address.
         * - `spender` cannot be the zero address.
         *
         * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
         */
        function _approve(address owner, address spender, uint256 value) internal {
            _approve(owner, spender, value, true);
        }
        /**
         * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
         *
         * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
         * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
         * `Approval` event during `transferFrom` operations.
         *
         * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
         * true using the following override:
         * ```
         * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
         *     super._approve(owner, spender, value, true);
         * }
         * ```
         *
         * Requirements are the same as {_approve}.
         */
        function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
            if (owner == address(0)) {
                revert ERC20InvalidApprover(address(0));
            }
            if (spender == address(0)) {
                revert ERC20InvalidSpender(address(0));
            }
            _allowances[owner][spender] = value;
            if (emitEvent) {
                emit Approval(owner, spender, value);
            }
        }
        /**
         * @dev Updates `owner` s allowance for `spender` based on spent `value`.
         *
         * Does not update the allowance value in case of infinite allowance.
         * Revert if not enough allowance is available.
         *
         * Does not emit an {Approval} event.
         */
        function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
            uint256 currentAllowance = allowance(owner, spender);
            if (currentAllowance != type(uint256).max) {
                if (currentAllowance < value) {
                    revert ERC20InsufficientAllowance(spender, currentAllowance, value);
                }
                unchecked {
                    _approve(owner, spender, currentAllowance - value, false);
                }
            }
        }
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)
    pragma solidity ^0.8.20;
    import {IERC20} from "../IERC20.sol";
    /**
     * @dev Interface for the optional metadata functions from the ERC20 standard.
     */
    interface IERC20Metadata is IERC20 {
        /**
         * @dev Returns the name of the token.
         */
        function name() external view returns (string memory);
        /**
         * @dev Returns the symbol of the token.
         */
        function symbol() external view returns (string memory);
        /**
         * @dev Returns the decimals places of the token.
         */
        function decimals() external view returns (uint8);
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
    pragma solidity ^0.8.20;
    /**
     * @dev Interface of the ERC20 standard as defined in the EIP.
     */
    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);
    }
    // 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;
        }
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts (last updated v5.0.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 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;
        }
    }
    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.23;
    import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
    import {IDividendTracker} from "./interfaces/IDividendTracker.sol";
    import {SafeMath, SafeMathUint, SafeMathInt} from "./libs/SafeMath.sol";
    abstract contract DividendTracker is ERC20, IDividendTracker {
        using SafeMath for uint256;
        using SafeMathUint for uint256;
        using SafeMathInt for int256;
        // With `magnitude`, we can properly distribute dividends even if the amount of received ether is small.
        // For more discussion about choosing the value of `magnitude`,
        //  see https://github.com/ethereum/EIPs/issues/1726#issuecomment-472352728
        uint256 internal constant magnitude = 2 ** 128;
        uint256 internal magnifiedDividendPerShare;
        // About dividendCorrection:
        // If the token balance of a `_user` is never changed, the dividend of `_user` can be computed with:
        //   `dividendOf(_user) = dividendPerShare * balanceOf(_user)`.
        // When `balanceOf(_user)` is changed (via minting/burning/transferring tokens),
        //   `dividendOf(_user)` should not be changed,
        //   but the computed value of `dividendPerShare * balanceOf(_user)` is changed.
        // To keep the `dividendOf(_user)` unchanged, we add a correction term:
        //   `dividendOf(_user) = dividendPerShare * balanceOf(_user) + dividendCorrectionOf(_user)`,
        //   where `dividendCorrectionOf(_user)` is updated whenever `balanceOf(_user)` is changed:
        //   `dividendCorrectionOf(_user) = dividendPerShare * (old balanceOf(_user)) - (new balanceOf(_user))`.
        // So now `dividendOf(_user)` returns the same value before and after `balanceOf(_user)` is changed.
        mapping(address => int256) internal magnifiedDividendCorrections;
        mapping(address => uint256) internal withdrawnDividends;
        uint256 public totalDividendsDistributed;
        uint256 public totalDividendsWithdrawn;
        constructor(
            string memory _name,
            string memory _symbol
        ) ERC20(_name, _symbol) {}
        function _distribute(uint256 amount) internal virtual {
            require(totalSupply() > 0);
            if (amount > 0) {
                magnifiedDividendPerShare = magnifiedDividendPerShare.add(
                    (amount).mul(magnitude) / totalSupply()
                );
                emit DividendsDistributed(msg.sender, amount);
                totalDividendsDistributed = totalDividendsDistributed.add(amount);
            }
        }
        /// @notice Withdraws the ether distributed to the sender.
        /// @dev It emits a `DividendWithdrawn` event if the amount of withdrawn ether is greater than 0.
        function _withdrawDividendOfUser(
            address payable user
        ) internal returns (uint256) {
            uint256 _withdrawableDividend = withdrawableDividendOf(user);
            if (_withdrawableDividend > 0) {
                withdrawnDividends[user] = withdrawnDividends[user].add(
                    _withdrawableDividend
                );
                totalDividendsWithdrawn += _withdrawableDividend;
                emit DividendWithdrawn(user, _withdrawableDividend);
                (bool success, ) = user.call{value: _withdrawableDividend}("");
                if (!success) {
                    withdrawnDividends[user] = withdrawnDividends[user].sub(
                        _withdrawableDividend
                    );
                    totalDividendsWithdrawn -= _withdrawableDividend;
                    return 0;
                }
                return _withdrawableDividend;
            }
            return 0;
        }
        /// @notice View the amount of dividend in wei that an address can withdraw.
        /// @param _owner The address of a token holder.
        /// @return The amount of dividend in wei that `_owner` can withdraw.
        function dividendOf(address _owner) public view override returns (uint256) {
            return withdrawableDividendOf(_owner);
        }
        /// @notice View the amount of dividend in wei that an address can withdraw.
        /// @param _owner The address of a token holder.
        /// @return The amount of dividend in wei that `_owner` can withdraw.
        function withdrawableDividendOf(
            address _owner
        ) public view override returns (uint256) {
            return accumulativeDividendOf(_owner).sub(withdrawnDividends[_owner]);
        }
        /// @notice View the amount of dividend in wei that an address has withdrawn.
        /// @param _owner The address of a token holder.
        /// @return The amount of dividend in wei that `_owner` has withdrawn.
        function withdrawnDividendOf(
            address _owner
        ) public view override returns (uint256) {
            return withdrawnDividends[_owner];
        }
        /// @notice View the amount of dividend in wei that an address has earned in total.
        /// @dev accumulativeDividendOf(_owner) = withdrawableDividendOf(_owner) + withdrawnDividendOf(_owner)
        /// = (magnifiedDividendPerShare * balanceOf(_owner) + magnifiedDividendCorrections[_owner]) / magnitude
        /// @param _owner The address of a token holder.
        /// @return The amount of dividend in wei that `_owner` has earned in total.
        function accumulativeDividendOf(
            address _owner
        ) public view override returns (uint256) {
            return
                magnifiedDividendPerShare
                    .mul(balanceOf(_owner))
                    .toInt256Safe()
                    .add(magnifiedDividendCorrections[_owner])
                    .toUint256Safe() / magnitude;
        }
        function transfer(
            address to,
            uint256 value
        ) public override returns (bool) {
            super.transfer(to, value);
            address from = _msgSender();
            int256 _magCorrection = magnifiedDividendPerShare
                .mul(value)
                .toInt256Safe();
            magnifiedDividendCorrections[from] = magnifiedDividendCorrections[from]
                .add(_magCorrection);
            magnifiedDividendCorrections[to] = magnifiedDividendCorrections[to].sub(
                _magCorrection
            );
            return true;
        }
        function transferFrom(
            address from,
            address to,
            uint256 value
        ) public override returns (bool) {
            super.transferFrom(from, to, value);
            int256 _magCorrection = magnifiedDividendPerShare
                .mul(value)
                .toInt256Safe();
            magnifiedDividendCorrections[from] = magnifiedDividendCorrections[from]
                .add(_magCorrection);
            magnifiedDividendCorrections[to] = magnifiedDividendCorrections[to].sub(
                _magCorrection
            );
            return true;
        }
        function mint(address account, uint256 value) public virtual {
            super._mint(account, value);
            magnifiedDividendCorrections[account] = magnifiedDividendCorrections[
                account
            ].sub((magnifiedDividendPerShare.mul(value)).toInt256Safe());
        }
        function burn(address account, uint256 value) public virtual {
            super._burn(account, value);
            magnifiedDividendCorrections[account] = magnifiedDividendCorrections[
                account
            ].add((magnifiedDividendPerShare.mul(value)).toInt256Safe());
        }
    }
    // SPDX-License-Identifier: UNLICENSED
    pragma solidity ^0.8.23;
    import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
    import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
    import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
    import {DividendTracker} from "./DividendTracker.sol";
    contract ERC315LPToken is DividendTracker, Ownable {
        event Claim(address indexed account, uint256 amount);
        struct AccountInfo {
            address account;
            uint256 withdrawableDividends;
            uint256 totalDividends;
            uint256 lastClaimTime;
        }
        constructor()
            DividendTracker("Liquidity Provide ERC315s", "LP-ERC315")
            Ownable(_msgSender())
        {}
        mapping(address => uint256) public lastClaimTimes;
        uint private unlocked = 1;
        modifier lock() {
            require(unlocked == 1, "LPToken: LOCKED");
            unlocked = 0;
            _;
            unlocked = 1;
        }
        function claimRewards() external {
            uint256 amount = _withdrawDividendOfUser(payable(_msgSender()));
            if (amount > 0) {
                lastClaimTimes[_msgSender()] = block.timestamp;
                emit Claim(_msgSender(), amount);
            }
        }
        function getAccount(
            address account
        ) public view returns (address, uint256, uint256, uint256, uint256) {
            AccountInfo memory info;
            info.account = account;
            info.withdrawableDividends = withdrawableDividendOf(account);
            info.totalDividends = accumulativeDividendOf(account);
            info.lastClaimTime = lastClaimTimes[account];
            return (
                info.account,
                info.withdrawableDividends,
                info.totalDividends,
                info.lastClaimTime,
                totalDividendsWithdrawn
            );
        }
        function mint(address to, uint256 amount) public override lock onlyOwner {
            super.mint(to, amount);
        }
        function burn(address from, uint256 amount) public override lock onlyOwner {
            super.burn(from, amount);
        }
        function burnLP(uint256 amount) public lock {
            super.burn(_msgSender(), amount);
        }
        receive() external payable {
            uint256 totalAmount = msg.value;
            if (totalSupply() > 0) {
                _distribute(totalAmount);
            }
        }
    }
    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.23;
    interface IDividendTracker {
        /// @notice View the amount of dividend in wei that an address can withdraw.
        /// @param _owner The address of a token holder.
        /// @return The amount of dividend in wei that `_owner` can withdraw.
        function dividendOf(address _owner) external view returns (uint256);
        /// @notice View the amount of dividend in wei that an address can withdraw.
        /// @param _owner The address of a token holder.
        /// @return The amount of dividend in wei that `_owner` can withdraw.
        function withdrawableDividendOf(
            address _owner
        ) external view returns (uint256);
        /// @notice View the amount of dividend in wei that an address has withdrawn.
        /// @param _owner The address of a token holder.
        /// @return The amount of dividend in wei that `_owner` has withdrawn.
        function withdrawnDividendOf(
            address _owner
        ) external view returns (uint256);
        /// @notice View the amount of dividend in wei that an address has earned in total.
        /// @dev accumulativeDividendOf(_owner) = withdrawableDividendOf(_owner) + withdrawnDividendOf(_owner)
        /// @param _owner The address of a token holder.
        /// @return The amount of dividend in wei that `_owner` has earned in total.
        function accumulativeDividendOf(
            address _owner
        ) external view returns (uint256);
        /// @dev This event MUST emit when ether is distributed to token holders.
        /// @param from The address which sends ether to this contract.
        /// @param weiAmount The amount of distributed ether in wei.
        event DividendsDistributed(address indexed from, uint256 weiAmount);
        /// @dev This event MUST emit when an address withdraws their dividend.
        /// @param to The address which withdraws ether from this contract.
        /// @param weiAmount The amount of withdrawn ether in wei.
        event DividendWithdrawn(address indexed to, uint256 weiAmount);
    }
    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.6;
    library SafeMath {
        /**
         * @dev Returns the addition of two unsigned integers, reverting on
         * overflow.
         *
         * Counterpart to Solidity's `+` operator.
         *
         * Requirements:
         *
         * - Addition cannot overflow.
         */
        function add(uint256 a, uint256 b) internal pure returns (uint256) {
            uint256 c = a + b;
            require(c >= a, "SafeMath: addition overflow");
            return c;
        }
        /**
         * @dev Returns the subtraction of two unsigned integers, reverting on
         * overflow (when the result is negative).
         *
         * Counterpart to Solidity's `-` operator.
         *
         * Requirements:
         *
         * - Subtraction cannot overflow.
         */
        function sub(uint256 a, uint256 b) internal pure returns (uint256) {
            return sub(a, b, "SafeMath: subtraction overflow");
        }
        /**
         * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
         * overflow (when the result is negative).
         *
         * Counterpart to Solidity's `-` operator.
         *
         * Requirements:
         *
         * - Subtraction cannot overflow.
         */
        function sub(
            uint256 a,
            uint256 b,
            string memory errorMessage
        ) internal pure returns (uint256) {
            require(b <= a, errorMessage);
            uint256 c = a - b;
            return c;
        }
        /**
         * @dev Returns the multiplication of two unsigned integers, reverting on
         * overflow.
         *
         * Counterpart to Solidity's `*` operator.
         *
         * Requirements:
         *
         * - Multiplication cannot overflow.
         */
        function mul(uint256 a, uint256 b) internal pure returns (uint256) {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) {
                return 0;
            }
            uint256 c = a * b;
            require(c / a == b, "SafeMath: multiplication overflow");
            return c;
        }
        /**
         * @dev Returns the integer division of two unsigned integers. Reverts on
         * division by zero. The result is rounded towards zero.
         *
         * Counterpart to Solidity's `/` operator. Note: this function uses a
         * `revert` opcode (which leaves remaining gas untouched) while Solidity
         * uses an invalid opcode to revert (consuming all remaining gas).
         *
         * Requirements:
         *
         * - The divisor cannot be zero.
         */
        function div(uint256 a, uint256 b) internal pure returns (uint256) {
            return div(a, b, "SafeMath: division by zero");
        }
        /**
         * @dev Returns the integer division of two unsigned integers. Reverts with custom message on
         * division by zero. The result is rounded towards zero.
         *
         * Counterpart to Solidity's `/` operator. Note: this function uses a
         * `revert` opcode (which leaves remaining gas untouched) while Solidity
         * uses an invalid opcode to revert (consuming all remaining gas).
         *
         * Requirements:
         *
         * - The divisor cannot be zero.
         */
        function div(
            uint256 a,
            uint256 b,
            string memory errorMessage
        ) internal pure returns (uint256) {
            require(b > 0, errorMessage);
            uint256 c = a / b;
            // assert(a == b * c + a % b); // There is no case in which this doesn't hold
            return c;
        }
        /**
         * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
         * Reverts when dividing by zero.
         *
         * Counterpart to Solidity's `%` operator. This function uses a `revert`
         * opcode (which leaves remaining gas untouched) while Solidity uses an
         * invalid opcode to revert (consuming all remaining gas).
         *
         * Requirements:
         *
         * - The divisor cannot be zero.
         */
        function mod(uint256 a, uint256 b) internal pure returns (uint256) {
            return mod(a, b, "SafeMath: modulo by zero");
        }
        /**
         * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
         * Reverts with custom message when dividing by zero.
         *
         * Counterpart to Solidity's `%` operator. This function uses a `revert`
         * opcode (which leaves remaining gas untouched) while Solidity uses an
         * invalid opcode to revert (consuming all remaining gas).
         *
         * Requirements:
         *
         * - The divisor cannot be zero.
         */
        function mod(
            uint256 a,
            uint256 b,
            string memory errorMessage
        ) internal pure returns (uint256) {
            require(b != 0, errorMessage);
            return a % b;
        }
    }
    /**
     * @title SafeMathInt
     * @dev Math operations for int256 with overflow safety checks.
     */
    library SafeMathInt {
        int256 private constant MIN_INT256 = int256(1) << 255;
        int256 private constant MAX_INT256 = ~(int256(1) << 255);
        /**
         * @dev Multiplies two int256 variables and fails on overflow.
         */
        function mul(int256 a, int256 b) internal pure returns (int256) {
            int256 c = a * b;
            // Detect overflow when multiplying MIN_INT256 with -1
            require(c != MIN_INT256 || (a & MIN_INT256) != (b & MIN_INT256));
            require((b == 0) || (c / b == a));
            return c;
        }
        /**
         * @dev Division of two int256 variables and fails on overflow.
         */
        function div(int256 a, int256 b) internal pure returns (int256) {
            // Prevent overflow when dividing MIN_INT256 by -1
            require(b != -1 || a != MIN_INT256);
            // Solidity already throws when dividing by 0.
            return a / b;
        }
        /**
         * @dev Subtracts two int256 variables and fails on overflow.
         */
        function sub(int256 a, int256 b) internal pure returns (int256) {
            int256 c = a - b;
            require((b >= 0 && c <= a) || (b < 0 && c > a));
            return c;
        }
        /**
         * @dev Adds two int256 variables and fails on overflow.
         */
        function add(int256 a, int256 b) internal pure returns (int256) {
            int256 c = a + b;
            require((b >= 0 && c >= a) || (b < 0 && c < a));
            return c;
        }
        /**
         * @dev Converts to absolute value, and fails on overflow.
         */
        function abs(int256 a) internal pure returns (int256) {
            require(a != MIN_INT256);
            return a < 0 ? -a : a;
        }
        function toUint256Safe(int256 a) internal pure returns (uint256) {
            require(a >= 0);
            return uint256(a);
        }
    }
    /**
     * @title SafeMathUint
     * @dev Math operations with safety checks that revert on error
     */
    library SafeMathUint {
        function toInt256Safe(uint256 a) internal pure returns (int256) {
            int256 b = int256(a);
            require(b >= 0);
            return b;
        }
    }