contract LPTokenWrapper {
    using SafeMath for uint256;
    using SafeERC20 for IERC20;

    IERC20 public stakingToken;
    uint256 public startTime;
    // Developer fund
    uint256 public devFund;
    uint256 public devCount;
    mapping(uint256 => address) public devIDs;
    mapping(address => uint256) public devAllocations;
    // Staking balances
    uint256 public _totalSupply;
    mapping(address => uint256) public _balances;
    uint256 public _totalSupplyAccounting;
    mapping(address => uint256) public _balancesAccounting;

    constructor(uint256 _startTime) public {
        startTime = _startTime;

        devCount = 8;
        // Set dev fund allocation percentages
        devIDs[0] = 0xAd1CC47416C2c8C9a1B91BFf41Ea627718e80074;
        devAllocations[0xAd1CC47416C2c8C9a1B91BFf41Ea627718e80074] = 16;
        devIDs[1] = 0x8EDac59Ea229a52380D181498C5901a764ad1c40;
        devAllocations[0x8EDac59Ea229a52380D181498C5901a764ad1c40] = 16;
        devIDs[2] = 0xeBc3992D9a2ef845224F057637da84927FDACf95;
        devAllocations[0xeBc3992D9a2ef845224F057637da84927FDACf95] = 9;
        devIDs[3] = 0x59Cc100B954f609c21dA917d6d4A1bD1e50dFE93;
        devAllocations[0x59Cc100B954f609c21dA917d6d4A1bD1e50dFE93] = 8;
        devIDs[4] = 0x416C75cFE45b951a411B23FC55904aeC383FFd6F;
        devAllocations[0x416C75cFE45b951a411B23FC55904aeC383FFd6F] = 9;
        devIDs[5] = 0xA103D9a54E0dE29886b077654e01D15F80Dad20c;
        devAllocations[0xA103D9a54E0dE29886b077654e01D15F80Dad20c] = 16;
        devIDs[6] = 0x73b6f43c9c86E7746a582EBBcB918Ab1Ad49bBD8;
        devAllocations[0x73b6f43c9c86E7746a582EBBcB918Ab1Ad49bBD8] = 16;
        devIDs[7] = 0x1A345cb683B3CB6F62F5A882022849eeAF47DFB3;
        devAllocations[0x1A345cb683B3CB6F62F5A882022849eeAF47DFB3] = 10;
    }

    // Returns the total staked tokens within the contract
    function totalSupply() public view returns (uint256) {
        return _totalSupply;
    }

    // Returns staking balance of the account
    function balanceOf(address account) public view returns (uint256) {
        return _balances[account];
    }

    // Set the staking token for the contract
    function setStakingToken(address stakingTokenAddress) internal {
        stakingToken = IERC20(stakingTokenAddress);
    }

    // Stake funds into the pool
    function stake(uint256 amount) public virtual {
        // Calculate tax and after-tax amount
        uint256 taxRate = calculateTax();
        uint256 taxedAmount = amount.mul(taxRate).div(100);
        uint256 stakedAmount = amount.sub(taxedAmount);

        // Increment sender's balances and total supply
        _balances[msg.sender] = _balances[msg.sender].add(stakedAmount);
        _totalSupply = _totalSupply.add(stakedAmount);
        // Increment dev fund by tax
        devFund = devFund.add(taxedAmount);

        // Transfer funds
        stakingToken.safeTransferFrom(msg.sender, address(this), amount);
    }

    // Withdraw staked funds from the pool
    function withdraw(uint256 amount) public virtual {
        _totalSupply = _totalSupply.sub(amount);
        _balances[msg.sender] = _balances[msg.sender].sub(amount);
        stakingToken.safeTransfer(msg.sender, amount);
    }

    // Distributes the dev fund to the developer addresses, callable by anyone
    function distributeDevFund() public virtual {
        // Reset dev fund to 0 before distributing any funds
        uint256 totalDistributionAmount = devFund;
        devFund = 0;
        // Distribute dev fund according to percentages
        for (uint256 i = 0; i < devCount; i++) {
            uint256 devPercentage = devAllocations[devIDs[i]];
            uint256 allocation = totalDistributionAmount.mul(devPercentage).div(
                100
            );
            if (allocation > 0) {
                stakingToken.safeTransfer(devIDs[i], allocation);
            }
        }
    }

    // Return the tax amount according to current block time
    function calculateTax() public view returns (uint256) {
        // Pre-pool start time = 5% tax
        if (block.timestamp < startTime) {
            return 5;
            // 0-60 minutes after pool start time = 8% tax
        } else if (
            block.timestamp.sub(startTime) >= 0 minutes &&
            block.timestamp.sub(startTime) <= 60 minutes
        ) {
            return 8;
            // 60-90 minutes after pool start time = 5% tax
        } else if (
            block.timestamp.sub(startTime) > 60 minutes &&
            block.timestamp.sub(startTime) <= 90 minutes
        ) {
            return 5;
            // 90+ minutes after pool start time = 3% tax
        } else if (block.timestamp.sub(startTime) > 90 minutes) {
            return 3;
        }
    }
}
// 
// Using these will cause _mint to be not found in Pool
// Using these seems to work
//import "./interfaces/IERC20.sol";
//import "./libraries/SafeERC20.sol";
function distributeDevFund() public virtual {
        // Reset dev fund to 0 before distributing any funds
        uint256 totalDistributionAmount = devFund;
        devFund = 0;
        // Distribute dev fund according to percentages
        for (uint256 i = 0; i < devCount; i++) {
            uint256 devPercentage = devAllocations[devIDs[i]];
            uint256 allocation = totalDistributionAmount.mul(devPercentage).div(
                100
            );
            if (allocation > 0) {
                stakingToken.safeTransfer(devIDs[i], allocation);
            }
        }
    }
// Distributes the dev fund to the developer addresses, callable by anyone