// File: Context.sol



// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @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;
	}
}

// File: ERC20.sol



// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./IERC20Metadata.sol";
import "./Context.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}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * 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.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20, IERC20Metadata {
	mapping(address => uint256) private _balances;

	mapping(address => mapping(address => uint256)) private _allowances;

	uint256 private _totalSupply;

	string private _name;
	string private _symbol;

	/**
	 * @dev Sets the values for {name} and {symbol}.
	 *
	 * The default value of {decimals} is 18. To select a different value for
	 * {decimals} you should overload it.
	 *
	 * 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 override returns (string memory) {
		return _name;
	}

	/**
	 * @dev Returns the symbol of the token, usually a shorter version of the
	 * name.
	 */
	function symbol() public view virtual override 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 value {ERC20} uses, unless this function is
	 * 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 override returns (uint8) {
		return 18;
	}

	/**
	 * @dev See {IERC20-totalSupply}.
	 */
	function totalSupply() public view virtual override returns (uint256) {
		return _totalSupply;
	}

	/**
	 * @dev See {IERC20-balanceOf}.
	 */
	function balanceOf(address account) public view virtual override returns (uint256) {
		return _balances[account];
	}

	/**
	 * @dev See {IERC20-transfer}.
	 *
	 * Requirements:
	 *
	 * - `recipient` cannot be the zero address.
	 * - the caller must have a balance of at least `amount`.
	 */
	function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
		_transfer(_msgSender(), recipient, amount);
		return true;
	}

	/**
	 * @dev See {IERC20-allowance}.
	 */
	function allowance(address owner, address spender) public view virtual override returns (uint256) {
		return _allowances[owner][spender];
	}

	/**
	 * @dev See {IERC20-approve}.
	 *
	 * Requirements:
	 *
	 * - `spender` cannot be the zero address.
	 */
	function approve(address spender, uint256 amount) public virtual override returns (bool) {
		_approve(_msgSender(), spender, amount);
		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}.
	 *
	 * Requirements:
	 *
	 * - `sender` and `recipient` cannot be the zero address.
	 * - `sender` must have a balance of at least `amount`.
	 * - the caller must have allowance for ``sender``'s tokens of at least
	 * `amount`.
	 */
	function transferFrom(
		address sender,
		address recipient,
		uint256 amount
	) public virtual override returns (bool) {
		_transfer(sender, recipient, amount);

		uint256 currentAllowance = _allowances[sender][_msgSender()];
		require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
		unchecked {
			_approve(sender, _msgSender(), currentAllowance - amount);
		}

		return true;
	}

	/**
	 * @dev Atomically increases the allowance granted to `spender` by the caller.
	 *
	 * This is an alternative to {approve} that can be used as a mitigation for
	 * problems described in {IERC20-approve}.
	 *
	 * Emits an {Approval} event indicating the updated allowance.
	 *
	 * Requirements:
	 *
	 * - `spender` cannot be the zero address.
	 */
	function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
		_approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
		return true;
	}

	/**
	 * @dev Atomically decreases the allowance granted to `spender` by the caller.
	 *
	 * This is an alternative to {approve} that can be used as a mitigation for
	 * problems described in {IERC20-approve}.
	 *
	 * Emits an {Approval} event indicating the updated allowance.
	 *
	 * Requirements:
	 *
	 * - `spender` cannot be the zero address.
	 * - `spender` must have allowance for the caller of at least
	 * `subtractedValue`.
	 */
	function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
		uint256 currentAllowance = _allowances[_msgSender()][spender];
		require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
		unchecked {
			_approve(_msgSender(), spender, currentAllowance - subtractedValue);
		}

		return true;
	}

	/**
	 * @dev Moves `amount` of tokens from `sender` to `recipient`.
	 *
	 * 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.
	 *
	 * Requirements:
	 *
	 * - `sender` cannot be the zero address.
	 * - `recipient` cannot be the zero address.
	 * - `sender` must have a balance of at least `amount`.
	 */
	function _transfer(
		address sender,
		address recipient,
		uint256 amount
	) internal virtual {
		require(sender != address(0), "ERC20: transfer from the zero address");
		require(recipient != address(0), "ERC20: transfer to the zero address");

		_beforeTokenTransfer(sender, recipient, amount);

		uint256 senderBalance = _balances[sender];
		require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
		unchecked {
			_balances[sender] = senderBalance - amount;
		}
		_balances[recipient] += amount;

		emit Transfer(sender, recipient, amount);

		_afterTokenTransfer(sender, recipient, amount);
	}

	/** @dev Creates `amount` tokens and assigns them to `account`, increasing
	 * the total supply.
	 *
	 * Emits a {Transfer} event with `from` set to the zero address.
	 *
	 * Requirements:
	 *
	 * - `account` cannot be the zero address.
	 */
	function _mint(address account, uint256 amount) internal virtual {
		require(account != address(0), "ERC20: mint to the zero address");

		_beforeTokenTransfer(address(0), account, amount);

		_totalSupply += amount;
		_balances[account] += amount;
		emit Transfer(address(0), account, amount);

		_afterTokenTransfer(address(0), account, amount);
	}

	/**
	 * @dev Destroys `amount` tokens from `account`, reducing the
	 * total supply.
	 *
	 * Emits a {Transfer} event with `to` set to the zero address.
	 *
	 * Requirements:
	 *
	 * - `account` cannot be the zero address.
	 * - `account` must have at least `amount` tokens.
	 */
	function _burn(address account, uint256 amount) internal virtual {
		require(account != address(0), "ERC20: burn from the zero address");

		_beforeTokenTransfer(account, address(0), amount);

		uint256 accountBalance = _balances[account];
		require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
		unchecked {
			_balances[account] = accountBalance - amount;
		}
		_totalSupply -= amount;

		emit Transfer(account, address(0), amount);

		_afterTokenTransfer(account, address(0), amount);
	}

	/**
	 * @dev Sets `amount` 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.
	 */
	function _approve(
		address owner,
		address spender,
		uint256 amount
	) internal virtual {
		require(owner != address(0), "ERC20: approve from the zero address");
		require(spender != address(0), "ERC20: approve to the zero address");

		_allowances[owner][spender] = amount;
		emit Approval(owner, spender, amount);
	}

	/**
	 * @dev Hook that is called before any transfer of tokens. This includes
	 * minting and burning.
	 *
	 * Calling conditions:
	 *
	 * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
	 * will be transferred to `to`.
	 * - when `from` is zero, `amount` tokens will be minted for `to`.
	 * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
	 * - `from` and `to` are never both zero.
	 *
	 * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
	 */
	function _beforeTokenTransfer(
		address from,
		address to,
		uint256 amount
	) internal virtual {}

	/**
	 * @dev Hook that is called after any transfer of tokens. This includes
	 * minting and burning.
	 *
	 * Calling conditions:
	 *
	 * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
	 * has been transferred to `to`.
	 * - when `from` is zero, `amount` tokens have been minted for `to`.
	 * - when `to` is zero, `amount` of ``from``'s tokens have been burned.
	 * - `from` and `to` are never both zero.
	 *
	 * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
	 */
	function _afterTokenTransfer(
		address from,
		address to,
		uint256 amount
	) internal virtual {}
}

// File: Forest.sol



// SPDX-License-Identifier: MIT LICENSE

pragma solidity ^0.8.0;

import "./IERC721Receiver.sol";
import "./Pausable.sol";
import "./IWoolf.sol";
import "./MutantPeach.sol";

contract Forest is Ownable, IERC721Receiver, Pausable {
	// maximum alpha score for a Wolf
	uint8 public constant MAX_ALPHA = 8;

	// struct to store a stake's token, owner, and earning values
	struct Stake {
		uint16 tokenId;
		uint80 value;
		address owner;
	}

	event TokenStaked(address owner, uint256 tokenId, uint256 value);
	event ApeClaimed(uint256 tokenId, uint256 earned, bool unstaked);
	event WolfClaimed(uint256 tokenId, uint256 earned, bool unstaked);

	// reference to the IWoolf NFT contract
	IWoolf woolf;
	// reference to the $MutantPeach contract for minting $MutantPeach earnings
	MutantPeach mutantPeach;

	// maps tokenId to stake
	mapping(uint256 => Stake) public forest;
	// maps alpha to all Wolf stakes with that alpha
	mapping(uint256 => Stake[]) public pack;
	// tracks location of each Wolf in Pack
	mapping(uint256 => uint256) public packIndices;

	// total alpha scores staked
	uint256 public totalAlphaStaked = 0;
	// any rewards distributed when no wolves are staked
	uint256 public unaccountedRewards = 0;
	// amount of $MutantPeach due for each alpha point staked
	uint256 public woolPerAlpha = 0;

	// ape earn 5000 $MutantPeach per day
	uint256 public constant DAILY_MP_RATE = 5000 ether;
	// ape must have 2 days worth of $MutantPeach to unstake or else it's too cold
	uint256 public constant MINIMUM_TO_EXIT = 4 days;
	// wolves take a 20% tax on all $MutantPeach claimed
	uint256 public constant MP_CLAIM_TAX_PERCENTAGE = 20;
	// there will only ever be (roughly) 2.4 billion $MutantPeach earned through staking
	uint256 public constant MAXIMUM_GLOBAL_MP = 2400000000 ether;

	// amount of $MutantPeach earned so far
	uint256 public totalWoolEarned;
	// number of Ape staked in the Forest
	uint256 public totalApeStaked;
	// the last time $MutantPeach was claimed
	uint256 public lastClaimTimestamp;

	// emergency rescue to allow unstaking without any checks but without $MutantPeach
	bool public rescueEnabled = false;

	/**
	 * @param _woolf reference to the IWoolf NFT contract
	 * @param _peach reference to the $MutantPeach token
	 */
	constructor(address _woolf, address _peach) {
		woolf = IWoolf(_woolf);
		mutantPeach = MutantPeach(_peach);
	}

	/** STAKING */

	/**
	 * adds Ape and Wolves to the Forest and Pack
	 * @param account the address of the staker
	 * @param tokenIds the IDs of the Ape and Wolves to stake
	 */
	function addManyToForestAndPack(address account, uint16[] calldata tokenIds) external {
		require(account == _msgSender() || _msgSender() == address(woolf), "DONT GIVE YOUR TOKENS AWAY");
		for (uint256 i = 0; i < tokenIds.length; i++) {
			if (_msgSender() != address(woolf)) {
				// dont do this step if its a mint + stake
				require(woolf.ownerOf(tokenIds[i]) == _msgSender(), "AINT YO TOKEN");
				woolf.transferFrom(_msgSender(), address(this), tokenIds[i]);
			} else if (tokenIds[i] == 0) {
				continue; // there may be gaps in the array for stolen tokens
			}
			if (isApe(tokenIds[i])) _addApeToForest(account, tokenIds[i]);
			else _addWolfToPack(account, tokenIds[i]);
		}
	}

	/**
	 * adds a single Ape to the Forest
	 * @param account the address of the staker
	 * @param tokenId the ID of the Ape to add to the Forest
	 */
	function _addApeToForest(address account, uint256 tokenId) internal whenNotPaused _updateEarnings {
		forest[tokenId] = Stake({ owner: account, tokenId: uint16(tokenId), value: uint80(block.timestamp) });
		totalApeStaked += 1;
		emit TokenStaked(account, tokenId, block.timestamp);
	}

	/**
	 * adds a single Wolf to the Pack
	 * @param account the address of the staker
	 * @param tokenId the ID of the Wolf to add to the Pack
	 */
	function _addWolfToPack(address account, uint256 tokenId) internal {
		uint256 alpha = _alphaForWolf(tokenId);
		totalAlphaStaked += alpha; // Portion of earnings ranges from 8 to 5
		packIndices[tokenId] = pack[alpha].length; // Store the location of the wolf in the Pack
		pack[alpha].push(Stake({ owner: account, tokenId: uint16(tokenId), value: uint80(woolPerAlpha) })); // Add the wolf to the Pack
		emit TokenStaked(account, tokenId, woolPerAlpha);
	}

	/** CLAIMING / UNSTAKING */

	/**
	 * realize $MutantPeach earnings and optionally unstake tokens from the Forest / Pack
	 * to unstake a Ape it will require it has 2 days worth of $MutantPeach unclaimed
	 * @param tokenIds the IDs of the tokens to claim earnings from
	 * @param unstake whether or not to unstake ALL of the tokens listed in tokenIds
	 */
	function claimManyFromForestAndPack(uint16[] calldata tokenIds, bool unstake) external whenNotPaused _updateEarnings {
		uint256 owed = 0;
		for (uint256 i = 0; i < tokenIds.length; i++) {
			if (isApe(tokenIds[i])) owed += _claimApeFromForest(tokenIds[i], unstake);
			else owed += _claimWolfFromPack(tokenIds[i], unstake);
		}
		if (owed == 0) return;
		mutantPeach.mint(_msgSender(), owed);
	}

	/**
	 * realize $MutantPeach earnings for a single Ape and optionally unstake it
	 * if not unstaking, pay a 20% tax to the staked Wolves
	 * if unstaking, there is a 50% chance all $MutantPeach is stolen
	 * @param tokenId the ID of the Ape to claim earnings from
	 * @param unstake whether or not to unstake the Ape
	 * @return owed - the amount of $MutantPeach earned
	 */
	function _claimApeFromForest(uint256 tokenId, bool unstake) internal returns (uint256 owed) {
		Stake memory stake = forest[tokenId];
		require(stake.owner == _msgSender(), "SWIPER, NO SWIPING");
		require(!(unstake && block.timestamp - stake.value < MINIMUM_TO_EXIT), "GONNA BE COLD WITHOUT TWO DAY'S MutantPeach");
		if (totalWoolEarned < MAXIMUM_GLOBAL_MP) {
			owed = ((block.timestamp - stake.value) * DAILY_MP_RATE) / 1 days;
		} else if (stake.value > lastClaimTimestamp) {
			owed = 0; // $MutantPeach production stopped already
		} else {
			owed = ((lastClaimTimestamp - stake.value) * DAILY_MP_RATE) / 1 days; // stop earning additional $MutantPeach if it's all been earned
		}
		if (unstake) {
			if (random(tokenId) & 1 == 1) {
				// 50% chance of all $MutantPeach stolen
				_payWolfTax(owed);
				owed = 0;
			}
			woolf.safeTransferFrom(address(this), _msgSender(), tokenId, ""); // send back Ape
			delete forest[tokenId];
			totalApeStaked -= 1;
		} else {
			_payWolfTax((owed * MP_CLAIM_TAX_PERCENTAGE) / 100); // percentage tax to staked wolves
			owed = (owed * (100 - MP_CLAIM_TAX_PERCENTAGE)) / 100; // remainder goes to Ape owner
			forest[tokenId] = Stake({ owner: _msgSender(), tokenId: uint16(tokenId), value: uint80(block.timestamp) }); // reset stake
		}
		emit ApeClaimed(tokenId, owed, unstake);
	}

	/**
	 * realize $MutantPeach earnings for a single Wolf and optionally unstake it
	 * Wolves earn $MutantPeach proportional to their Alpha rank
	 * @param tokenId the ID of the Wolf to claim earnings from
	 * @param unstake whether or not to unstake the Wolf
	 * @return owed - the amount of $MutantPeach earned
	 */
	function _claimWolfFromPack(uint256 tokenId, bool unstake) internal returns (uint256 owed) {
		require(woolf.ownerOf(tokenId) == address(this), "AINT A PART OF THE PACK");
		uint256 alpha = _alphaForWolf(tokenId);
		Stake memory stake = pack[alpha][packIndices[tokenId]];
		require(stake.owner == _msgSender(), "SWIPER, NO SWIPING");
		owed = (alpha) * (woolPerAlpha - stake.value); // Calculate portion of tokens based on Alpha
		if (unstake) {
			totalAlphaStaked -= alpha; // Remove Alpha from total staked
			woolf.safeTransferFrom(address(this), _msgSender(), tokenId, ""); // Send back Wolf
			Stake memory lastStake = pack[alpha][pack[alpha].length - 1];
			pack[alpha][packIndices[tokenId]] = lastStake; // Shuffle last Wolf to current position
			packIndices[lastStake.tokenId] = packIndices[tokenId];
			pack[alpha].pop(); // Remove duplicate
			delete packIndices[tokenId]; // Delete old mapping
		} else {
			pack[alpha][packIndices[tokenId]] = Stake({ owner: _msgSender(), tokenId: uint16(tokenId), value: uint80(woolPerAlpha) }); // reset stake
		}
		emit WolfClaimed(tokenId, owed, unstake);
	}

	/**
	 * emergency unstake tokens
	 * @param tokenIds the IDs of the tokens to claim earnings from
	 */
	function rescue(uint256[] calldata tokenIds) external {
		require(rescueEnabled, "RESCUE DISABLED");
		uint256 tokenId;
		Stake memory stake;
		Stake memory lastStake;
		uint256 alpha;
		for (uint256 i = 0; i < tokenIds.length; i++) {
			tokenId = tokenIds[i];
			if (isApe(tokenId)) {
				stake = forest[tokenId];
				require(stake.owner == _msgSender(), "SWIPER, NO SWIPING");
				woolf.safeTransferFrom(address(this), _msgSender(), tokenId, ""); // send back Ape
				delete forest[tokenId];
				totalApeStaked -= 1;
				emit ApeClaimed(tokenId, 0, true);
			} else {
				alpha = _alphaForWolf(tokenId);
				stake = pack[alpha][packIndices[tokenId]];
				require(stake.owner == _msgSender(), "SWIPER, NO SWIPING");
				totalAlphaStaked -= alpha; // Remove Alpha from total staked
				woolf.safeTransferFrom(address(this), _msgSender(), tokenId, ""); // Send back Wolf
				lastStake = pack[alpha][pack[alpha].length - 1];
				pack[alpha][packIndices[tokenId]] = lastStake; // Shuffle last Wolf to current position
				packIndices[lastStake.tokenId] = packIndices[tokenId];
				pack[alpha].pop(); // Remove duplicate
				delete packIndices[tokenId]; // Delete old mapping
				emit WolfClaimed(tokenId, 0, true);
			}
		}
	}

	/** ACCOUNTING */

	/**
	 * add $MutantPeach to claimable pot for the Pack
	 * @param amount $MutantPeach to add to the pot
	 */
	function _payWolfTax(uint256 amount) internal {
		if (totalAlphaStaked == 0) {
			// if there's no staked wolves
			unaccountedRewards += amount; // keep track of $MutantPeach due to wolves
			return;
		}
		// makes sure to include any unaccounted $MutantPeach
		woolPerAlpha += (amount + unaccountedRewards) / totalAlphaStaked;
		unaccountedRewards = 0;
	}

	/**
	 * tracks $MutantPeach earnings to ensure it stops once 2.4 billion is eclipsed
	 */
	modifier _updateEarnings() {
		if (totalWoolEarned < MAXIMUM_GLOBAL_MP) {
			totalWoolEarned += ((block.timestamp - lastClaimTimestamp) * totalApeStaked * DAILY_MP_RATE) / 1 days;
			lastClaimTimestamp = block.timestamp;
		}
		_;
	}

	/** ADMIN */

	/**
	 * allows owner to enable "rescue mode"
	 * simplifies accounting, prioritizes tokens out in emergency
	 */
	function setRescueEnabled(bool _enabled) external onlyOwner {
		rescueEnabled = _enabled;
	}

	/**
	 * enables owner to pause / unpause minting
	 */
	function setPaused(bool _paused) external onlyOwner {
		if (_paused) _pause();
		else _unpause();
	}

	function getPackByAlphaAndID(uint256 alpha, uint256 tokenId) public view returns (Stake memory) {
		return pack[alpha][packIndices[tokenId]];
	}

	function getForestStakeByID(uint256 id) public view returns (Stake memory) {
		return forest[id];
	}

	/** READ ONLY */

	/**
	 * checks if a token is a Ape
	 * @param tokenId the ID of the token to check
	 * @return ape - whether or not a token is a Ape
	 */
	function isApe(uint256 tokenId) public view returns (bool ape) {
		// (ape, , , , , , ) = woolf.getTokenTraits(tokenId);
		IWoolf.ApeWolf memory obj = woolf.getTokenTraits(tokenId);
		return obj.isApe;
	}

	/**
	 * gets the alpha score for a Wolf
	 * @param tokenId the ID of the Wolf to get the alpha score for
	 * @return the alpha score of the Wolf (5-8)
	 */
	function _alphaForWolf(uint256 tokenId) internal view returns (uint8) {
		IWoolf.ApeWolf memory obj = woolf.getTokenTraits(tokenId);
		return MAX_ALPHA - obj.alphaIndex; // alpha index is 0-3
	}

	/**
	 * chooses a random Wolf thief when a newly minted token is stolen
	 * @param seed a random value to choose a Wolf from
	 * @return the owner of the randomly selected Wolf thief
	 */
	function randomWolfOwner(uint256 seed) external view returns (address) {
		if (totalAlphaStaked == 0) return address(0x0);
		uint256 bucket = (seed & 0xFFFFFFFF) % totalAlphaStaked; // choose a value from 0 to total alpha staked
		uint256 cumulative;
		seed >>= 32;
		// loop through each bucket of Wolves with the same alpha score
		for (uint256 i = MAX_ALPHA - 3; i <= MAX_ALPHA; i++) {
			cumulative += pack[i].length * i;
			// if the value is not inside of that bucket, keep going
			if (bucket >= cumulative) continue;
			// get the address of a random Wolf with that alpha score
			return pack[i][seed % pack[i].length].owner;
		}
		return address(0x0);
	}

	/**
	 * generates a pseudorandom number
	 * @param seed a value ensure different outcomes for different sources in the same block
	 * @return a pseudorandom value
	 */
	function random(uint256 seed) internal view returns (uint256) {
		return uint256(keccak256(abi.encodePacked(tx.origin, blockhash(block.number - 1), block.timestamp, seed)));
	}

	function setWolfAddress(address _address) external onlyOwner {
		woolf = IWoolf(_address);
	}

	function setWoolAddress(address _address) external onlyOwner {
		mutantPeach = MutantPeach(_address);
	}

	function onERC721Received(
		address,
		address from,
		uint256,
		bytes calldata
	) external pure override returns (bytes4) {
		require(from == address(0x0), "Cannot send tokens to Forest directly");
		return IERC721Receiver.onERC721Received.selector;
	}
}

// File: IERC20.sol



// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
	/**
	 * @dev Returns the amount of tokens in existence.
	 */
	function totalSupply() external view returns (uint256);

	/**
	 * @dev Returns the amount of tokens owned by `account`.
	 */
	function balanceOf(address account) external view returns (uint256);

	/**
	 * @dev Moves `amount` tokens from the caller's account to `recipient`.
	 *
	 * Returns a boolean value indicating whether the operation succeeded.
	 *
	 * Emits a {Transfer} event.
	 */
	function transfer(address recipient, uint256 amount) 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 `amount` 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 amount) external returns (bool);

	/**
	 * @dev Moves `amount` tokens from `sender` to `recipient` using the
	 * allowance mechanism. `amount` is then deducted from the caller's
	 * allowance.
	 *
	 * Returns a boolean value indicating whether the operation succeeded.
	 *
	 * Emits a {Transfer} event.
	 */
	function transferFrom(
		address sender,
		address recipient,
		uint256 amount
	) external returns (bool);

	/**
	 * @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);
}

// File: IERC20Metadata.sol



// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
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);
}

// File: IERC721Receiver.sol



// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @title ERC721 token receiver interface
 * @dev Interface for any contract that wants to support safeTransfers
 * from ERC721 asset contracts.
 */
interface IERC721Receiver {
	/**
	 * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
	 * by `operator` from `from`, this function is called.
	 *
	 * It must return its Solidity selector to confirm the token transfer.
	 * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
	 *
	 * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
	 */
	function onERC721Received(
		address operator,
		address from,
		uint256 tokenId,
		bytes calldata data
	) external returns (bytes4);
}

// File: IWoolf.sol



// SPDX-License-Identifier: MIT LICENSE

pragma solidity ^0.8.0;

interface IWoolf {
	// struct to store each token's traits
	struct ApeWolf {
		bool isApe;
		uint8 skin;
		uint8 eyes;
		uint8 mouth;
		uint8 clothing;
		uint8 headwear;
		uint8 alphaIndex;
	}

	function getPaidTokens() external view returns (uint256);

	function getTokenTraits(uint256 tokenId) external view returns (ApeWolf memory);

	function ownerOf(uint256 tokenId) external view returns (address owner);

	function transferFrom(
		address from,
		address to,
		uint256 tokenId
	) external;

	function safeTransferFrom(
		address from,
		address to,
		uint256 tokenId,
		bytes calldata data
	) external;
}

// File: MutantPeach.sol



// SPDX-License-Identifier: MIT LICENSE

pragma solidity ^0.8.0;
import "./ERC20.sol";
import "./Ownable.sol";

contract MutantPeach is ERC20, Ownable {
	// a mapping from an address to whether or not it can mint / burn
	mapping(address => bool) controllers;

	constructor() ERC20("MutantPeach", "MutantPeach") {}

	/**
	 * mints $MutantPeach to a recipient
	 * @param to the recipient of the $MutantPeach
	 * @param amount the amount of $MutantPeach to mint
	 */
	function mint(address to, uint256 amount) external {
		require(controllers[msg.sender], "Only controllers can mint");
		_mint(to, amount);
	}

	/**
	 * burns $MutantPeach from a holder
	 * @param from the holder of the $MutantPeach
	 * @param amount the amount of $MutantPeach to burn
	 */
	function burn(address from, uint256 amount) external {
		require(controllers[msg.sender], "Only controllers can burn");
		_burn(from, amount);
	}

	/**
	 * enables an address to mint / burn
	 * @param controller the address to enable
	 */
	function addController(address controller) external onlyOwner {
		controllers[controller] = true;
	}

	/**
	 * disables an address from minting / burning
	 * @param controller the address to disbale
	 */
	function removeController(address controller) external onlyOwner {
		controllers[controller] = false;
	}
}

// File: Ownable.sol



// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./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.
 *
 * By default, the owner account will be the one that deploys the contract. 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;

	event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

	/**
	 * @dev Initializes the contract setting the deployer as the initial owner.
	 */
	constructor() {
		_setOwner(_msgSender());
	}

	/**
	 * @dev Returns the address of the current owner.
	 */
	function owner() public view virtual returns (address) {
		return _owner;
	}

	/**
	 * @dev Throws if called by any account other than the owner.
	 */
	modifier onlyOwner() {
		require(owner() == _msgSender(), "Ownable: caller is not the owner");
		_;
	}

	/**
	 * @dev Leaves the contract without owner. It will not be possible to call
	 * `onlyOwner` functions anymore. Can only be called by the current owner.
	 *
	 * NOTE: Renouncing ownership will leave the contract without an owner,
	 * thereby removing any functionality that is only available to the owner.
	 */
	function renounceOwnership() public virtual onlyOwner {
		_setOwner(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 {
		require(newOwner != address(0), "Ownable: new owner is the zero address");
		_setOwner(newOwner);
	}

	function _setOwner(address newOwner) private {
		address oldOwner = _owner;
		_owner = newOwner;
		emit OwnershipTransferred(oldOwner, newOwner);
	}
}

// File: Pausable.sol



// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./Context.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
	/**
	 * @dev Emitted when the pause is triggered by `account`.
	 */
	event Paused(address account);

	/**
	 * @dev Emitted when the pause is lifted by `account`.
	 */
	event Unpaused(address account);

	bool private _paused;

	/**
	 * @dev Initializes the contract in unpaused state.
	 */
	constructor() {
		_paused = false;
	}

	/**
	 * @dev Returns true if the contract is paused, and false otherwise.
	 */
	function paused() public view virtual returns (bool) {
		return _paused;
	}

	/**
	 * @dev Modifier to make a function callable only when the contract is not paused.
	 *
	 * Requirements:
	 *
	 * - The contract must not be paused.
	 */
	modifier whenNotPaused() {
		require(!paused(), "Pausable: paused");
		_;
	}

	/**
	 * @dev Modifier to make a function callable only when the contract is paused.
	 *
	 * Requirements:
	 *
	 * - The contract must be paused.
	 */
	modifier whenPaused() {
		require(paused(), "Pausable: not paused");
		_;
	}

	/**
	 * @dev Triggers stopped state.
	 *
	 * Requirements:
	 *
	 * - The contract must not be paused.
	 */
	function _pause() internal virtual whenNotPaused {
		_paused = true;
		emit Paused(_msgSender());
	}

	/**
	 * @dev Returns to normal state.
	 *
	 * Requirements:
	 *
	 * - The contract must be paused.
	 */
	function _unpause() internal virtual whenPaused {
		_paused = false;
		emit Unpaused(_msgSender());
	}
}