contract PaymentSplitter {
    using SafeERC20Upgradeable for IERC20Upgradeable;

    address payable constant TREASURY = payable(0x0bA6585009c2E275CdE3Ede4Ab086d2c8b71b155);
    address payable constant UWULABS = payable(0x354A70969F0b4a4C994403051A81C2ca45db3615);
    address payable constant CM = payable(0xD80b6996C73BA77FF96FF2ADA982eBA1cb73d387);
    address payable constant CA = payable(0xFeB95163E713ADa2594Fe50CA0462a89db32cCa8);
    address payable constant MOD = payable(0xfd45CD3ACa3c21e1600f07eA60CAA96B2d6d3D05);
    address payable constant WEBDEV = payable(0x06046310B5483d4c185D9d87933D944405Ceb981);
    address payable constant WRITER = payable(0x118B91e2F362D5B3ecb7a6bebce08Ea617c659E9);
    address payable constant ARTIST = payable(0x8C0dd928691113D5C91D678aE7c7818F6a036E04);
    address payable constant NIKHIMA = payable(0xb304b3205862dF57e1718FFE0A1E7165c89c1482);

    /**
     * @dev The Ether received will be logged with {PaymentReceived} events. Note that these events are not fully
     * reliable: it's possible for a contract to receive Ether without triggering this function. This only affects the
     * reliability of the events, and not the actual splitting of Ether.
     *
     * To learn more about this see the Solidity documentation for
     * https://solidity.readthedocs.io/en/latest/contracts.html#fallback-function[fallback
     * functions].
     */
    receive() external payable virtual {
        uint256 totalBalance = address(this).balance;
        sendValue(TREASURY, percentOfTotal(totalBalance, 0.30 gwei)); // 1.5%/5% - 30% of royalties
        sendValue(UWULABS, percentOfTotal(totalBalance, 0.10 gwei)); // 0.5%/5% - 10% of royalties
        sendValue(CM, percentOfTotal(totalBalance, 0.03 gwei)); // 0.15%/5% - 3% of royalties
        sendValue(CA, percentOfTotal(totalBalance, 0.03 gwei)); // 0.15%/5% - 3% of royalties
        sendValue(MOD, percentOfTotal(totalBalance, 0.03 gwei)); // 0.15%/5% - 3% of royalties
        sendValue(WEBDEV, percentOfTotal(totalBalance, 0.03 gwei)); // 0.15%/5% - 3% of royalties
        sendValue(WRITER, percentOfTotal(totalBalance, 0.03 gwei)); // 0.15%/5% - 3% of royalties
        sendValue(ARTIST, percentOfTotal(totalBalance, 0.15 gwei)); // 0.75%/5% - 15% of royalties
        sendValue(NIKHIMA, address(this).balance); // 1.5%/5% - 30% of royalties
    }

    function percentOfTotal(uint256 total, uint256 percentInGwei) internal pure returns (uint256) {
        return (total * percentInGwei) / 1 gwei;
    }

    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    function rescue(address token) external {
        if (token == address(0)) {
            uint256 totalBalance = address(this).balance;
            sendValue(TREASURY, percentOfTotal(totalBalance, 0.30 gwei)); // 1.5%/5% - 30% of royalties
            sendValue(UWULABS, percentOfTotal(totalBalance, 0.10 gwei)); // 0.5%/5% - 10% of royalties
            sendValue(CM, percentOfTotal(totalBalance, 0.03 gwei)); // 0.15%/5% - 3% of royalties
            sendValue(CA, percentOfTotal(totalBalance, 0.03 gwei)); // 0.15%/5% - 3% of royalties
            sendValue(MOD, percentOfTotal(totalBalance, 0.03 gwei)); // 0.15%/5% - 3% of royalties
            sendValue(WEBDEV, percentOfTotal(totalBalance, 0.03 gwei)); // 0.15%/5% - 3% of royalties
            sendValue(WRITER, percentOfTotal(totalBalance, 0.03 gwei)); // 0.15%/5% - 3% of royalties
            sendValue(ARTIST, percentOfTotal(totalBalance, 0.15 gwei)); // 0.75%/5% - 15% of royalties
            sendValue(NIKHIMA, address(this).balance); // 1.5%/5% - 30% of royalties
        } else {
            uint256 totalBalance = IERC20Upgradeable(token).balanceOf(address(this));
            IERC20Upgradeable(token).safeTransfer(TREASURY, percentOfTotal(totalBalance, 0.30 gwei)); // 1.5%/5% - 30% of royalties
            IERC20Upgradeable(token).safeTransfer(UWULABS, percentOfTotal(totalBalance, 0.10 gwei)); // 0.5%/5% - 10% of royalties
            IERC20Upgradeable(token).safeTransfer(CM, percentOfTotal(totalBalance, 0.03 gwei)); // 0.15%/5% - 3% of royalties
            IERC20Upgradeable(token).safeTransfer(CA, percentOfTotal(totalBalance, 0.03 gwei)); // 0.15%/5% - 3% of royalties
            IERC20Upgradeable(token).safeTransfer(MOD, percentOfTotal(totalBalance, 0.03 gwei)); // 0.15%/5% - 3% of royalties
            IERC20Upgradeable(token).safeTransfer(WEBDEV, percentOfTotal(totalBalance, 0.03 gwei)); // 0.15%/5% - 3% of royalties
            IERC20Upgradeable(token).safeTransfer(WRITER, percentOfTotal(totalBalance, 0.03 gwei)); // 0.15%/5% - 3% of royalties
            IERC20Upgradeable(token).safeTransfer(ARTIST, percentOfTotal(totalBalance, 0.15 gwei)); // 0.75%/5% - 15% of royalties
            IERC20Upgradeable(token).safeTransfer(NIKHIMA, IERC20Upgradeable(token).balanceOf(address(this))); // 1.5%/5% - 30% of royalties
        }
    }
}
/**
 * @dev The Ether received will be logged with {PaymentReceived} events. Note that these events are not fully
 * reliable: it's possible for a contract to receive Ether without triggering this function. This only affects the
 * reliability of the events, and not the actual splitting of Ether.
 *
 * To learn more about this see the Solidity documentation for
 * https://solidity.readthedocs.io/en/latest/contracts.html#fallback-function[fallback
 * functions].
 */