contract FundsBucketPET {

  /// @notice address of the maintainer
  address public deployer;

  /// @notice address of Era Swap ERC20 Smart Contract
  ERC20 public token;

  /// @notice address of PET Smart Contract
  address public petContract;

  /// @notice event schema for monitoring funds added by donors
  event FundsDeposited(
    address _depositer,
    uint256 _depositAmount
  );

  /// @notice event schema for monitoring unallocated fund withdrawn by deployer
  event FundsWithdrawn(
    address _withdrawer,
    uint256 _withdrawAmount
  );

  /// @notice restricting access to some functionalities to deployer
  modifier onlyDeployer() {
    require(msg.sender == deployer, 'only deployer can call');
    _;
  }

  /// @notice this function is used to deploy FundsBucket Smart Contract
  ///   the same time while deploying PET Smart Contract
  /// @dev this smart contract is deployed by PET Smart Contract while being set up
  /// @param _token: is EraSwap ERC20 Smart Contract Address
  /// @param _deployer: is address of the deployer of PET Smart Contract
  constructor(ERC20 _token, address _deployer) public {
    token = _token;
    deployer = _deployer;
    petContract = msg.sender;
  }

  /// @notice this function is used by well wishers to add funds to the fund bucket of PET
  /// @dev ERC20 approve is required to be done for this contract earlier
  /// @param _depositAmount: amount in exaES to deposit
  function addFunds(uint256 _depositAmount) public {
    token.transferFrom(msg.sender, address(this), _depositAmount);

    /// @dev approving the PET Smart Contract in advance
    token.approve(petContract, _depositAmount);

    emit FundsDeposited(msg.sender, _depositAmount);
  }

  /// @notice this function makes it possible for deployer to withdraw unallocated ES
  function withdrawFunds(bool _withdrawEverything, uint256 _withdrawlAmount) public onlyDeployer {
    if(_withdrawEverything) {
      _withdrawlAmount = token.balanceOf(address(this));
    }

    token.transfer(msg.sender, _withdrawlAmount);

    emit FundsWithdrawn(msg.sender, _withdrawlAmount);
  }
}
/// @title Fund Bucket of TimeAlly Personal EraSwap Teller
/// @author The EraSwap Team
/// @notice The returns for PET Smart Contract are transparently stored in advance in this contract
function withdrawFunds(bool _withdrawEverything, uint256 _withdrawlAmount) public onlyDeployer {
  if(_withdrawEverything) {
    _withdrawlAmount = token.balanceOf(address(this));
  }

  token.transfer(msg.sender, _withdrawlAmount);

  emit FundsWithdrawn(msg.sender, _withdrawlAmount);
}

/// @notice this function makes it possible for deployer to withdraw unallocated ES