// File: Free32.sol



// SPDX-License-Identifier: CC0


/*
 /$$$$$$$$ /$$$$$$$  /$$$$$$$$ /$$$$$$$$        /$$$$$$   /$$$$$$
| $$_____/| $$__  $$| $$_____/| $$_____/       /$$__  $$ /$$__  $$
| $$      | $$  \ $$| $$      | $$            |__/  \ $$|__/  \ $$
| $$$$$   | $$$$$$$/| $$$$$   | $$$$$            /$$$$$/  /$$$$$$/
| $$__/   | $$__  $$| $$__/   | $$__/           |___  $$ /$$____/
| $$      | $$  \ $$| $$      | $$             /$$  \ $$| $$
| $$      | $$  | $$| $$$$$$$$| $$$$$$$$      |  $$$$$$/| $$$$$$$$
|__/      |__/  |__/|________/|________/       \______/ |________/



 /$$
| $$
| $$$$$$$  /$$   /$$
| $$__  $$| $$  | $$
| $$  \ $$| $$  | $$
| $$  | $$| $$  | $$
| $$$$$$$/|  $$$$$$$
|_______/  \____  $$
           /$$  | $$
          |  $$$$$$/
           \______/
  /$$$$$$  /$$$$$$$$ /$$$$$$$$ /$$    /$$ /$$$$$$ /$$$$$$$$ /$$$$$$$
 /$$__  $$|__  $$__/| $$_____/| $$   | $$|_  $$_/| $$_____/| $$__  $$
| $$  \__/   | $$   | $$      | $$   | $$  | $$  | $$      | $$  \ $$
|  $$$$$$    | $$   | $$$$$   |  $$ / $$/  | $$  | $$$$$   | $$$$$$$/
 \____  $$   | $$   | $$__/    \  $$ $$/   | $$  | $$__/   | $$____/
 /$$  \ $$   | $$   | $$        \  $$$/    | $$  | $$      | $$
|  $$$$$$/   | $$   | $$$$$$$$   \  $/    /$$$$$$| $$$$$$$$| $$
 \______/    |__/   |________/    \_/    |______/|________/|__/


CC0 2023
*/


pragma solidity ^0.8.23;


import "./FreeChecker.sol";

interface OffOn {
  function latestHash() external view returns (uint256);
}

interface Free19 {
  function claimer() external view returns (address);
}

interface IFree30 {
  function free30Claimer() external view returns (address);
}

interface FastCashMoneyPlus {
  function balanceOf(address owner) external view returns (uint256 balance);
}

contract Free32 is FreeChecker {
  OffOn public offon = OffOn(0xA860D381A193A0811C77c8FCD881B3E9F245A419);
  Free19 public free19 = Free19(0xaBCeF3a4aDC27A6c962b4fC17181F47E62244EF0);
  FastCashMoneyPlus public fastcash = FastCashMoneyPlus(0xcA5228D1fe52D22db85E02CA305cddD9E573D752);


  function percentBpsRequired() public view returns (uint256) {
    bool turnedOff = offon.latestHash() == 0;
    uint256 free3Supply = free.collectionSupply(3);
    uint256 free20Supply = free.collectionSupply(20);
    address free30Addr = free.collectionIdToMinter(30);
    address free30Claimer = IFree30(free30Addr).free30Claimer();

    uint256 free20Bps = free20Supply * 8;

    uint256 free3NegBps = free3Supply > free20Bps + 50
      ? free20Bps + 50
      : free3Supply;

    return 50
      + (turnedOff ? 0 : 50)
      + (free19.claimer() == address(this) ? 0 : 25)
      + (free30Claimer == address(this) ? 0 : 25)
      + (fastcash.balanceOf(0x56FF4F826795f2dE13A89F60ea7B1cF14c714252) / 15 ether)
      + free20Bps
      - free3NegBps;
  }

  function freesRequired() public view returns (uint256) {
    uint256 totalFreeSupply = free.totalSupply();
    return totalFreeSupply * percentBpsRequired() / 10000;
  }

  function claim(uint256 free0TokenId) external {
    preCheck(free0TokenId, '32');

    uint256 senderFreeBalance = free.balanceOf(msg.sender);

    require(senderFreeBalance >= freesRequired());

    postCheck(free0TokenId, 32, '32');
  }

}
// File: FreeChecker.sol




// SPDX-License-Identifier: CC0


/*
CC0 2023
*/


pragma solidity ^0.8.23;

interface IFree {
  function totalSupply() external  view returns (uint256);
  function balanceOf(address) external  view returns (uint256);
  function ownerOf(uint256 tokenId) external view returns (address owner);
  function tokenIdToCollectionId(uint256 tokenId) external view returns (uint256 collectionId);
  function collectionSupply(uint256 collectionId) external view returns (uint256);
  function collectionIdToMinter(uint256 collectionId) external view returns (address);
  function mint(uint256 collectionId, address to) external;
  function appendAttributeToToken(uint256 tokenId, string memory attrKey, string memory attrValue) external;
  function safeTransferFrom(address from, address to, uint256 tokenId) external;
}

abstract contract FreeChecker {
  mapping(uint256 => bool) public free0TokenIdUsed;
  IFree public immutable free = IFree(0x30b541f1182ef19c56a39634B2fdACa5a0F2A741);

  function preCheck(uint256 free0TokenId, string memory freeStr) internal view {
    require(free.tokenIdToCollectionId(free0TokenId) == 0, 'Invalid Free0');
    require(!free0TokenIdUsed[free0TokenId],
      string(abi.encodePacked('This Free0 has already been used to mint a Free', freeStr))
    );
    require(free.ownerOf(free0TokenId) == msg.sender, 'You must be the owner of this Free0');

  }

  function postCheck(uint256 free0TokenId, uint256 freeNumber, string memory freeStr) internal {
    free0TokenIdUsed[free0TokenId] = true;
    free.appendAttributeToToken(free0TokenId,
      string(abi.encodePacked('Used For Free', freeStr, ' Mint')),
      'true'
    );
    free.mint(freeNumber, msg.sender);
  }

  function checkFreeToken(uint256 freeTokenId, uint256 collectionId) internal view {
    require(free.ownerOf(freeTokenId) == msg.sender, 'Not owner of token');
    require(free.tokenIdToCollectionId(freeTokenId) == collectionId, 'Token collection mismatch');
  }
}