{
    "Function": "slitherConstructorVariables",
    "File": "contracts/MerkleVesting.sol",
    "Parent Contracts": [],
    "High-Level Calls": [],
    "Internal Calls": [],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "contract MerkleVesting {\n    using MerkleLib for bytes32;\n\n    // the number of vesting schedules in this contract\n    uint public numTrees = 0;\n    \n    // this represents a single vesting schedule for a specific address\n    struct Tranche {\n        uint totalCoins;  // total number of coins released to an address after vesting is completed\n        uint currentCoins; // how many coins are left unclaimed by this address, vested or unvested\n        uint startTime; // when the vesting schedule is set to start, possibly in the past\n        uint endTime;  // when the vesting schedule will have released all coins\n        uint coinsPerSecond; // an intermediate value cached to reduce gas costs, how many coins released every second\n        uint lastWithdrawalTime; // the last time a withdrawal occurred, used to compute unvested coins\n        uint lockPeriodEndTime; // the first time at which coins may be withdrawn\n    }\n\n    // this represents a set of vesting schedules all in the same token\n    struct MerkleTree {\n        bytes32 rootHash;  // merkleroot of tree whose leaves are (address,uint,uint,uint,uint) representing vesting schedules\n        bytes32 ipfsHash; // ipfs hash of entire dataset, used to reconstruct merkle proofs if our servers go down\n        address tokenAddress; // token that the vesting schedules will be denominated in\n        uint tokenBalance; // current amount of tokens deposited to this tree, used to make sure trees don't share tokens\n    }\n\n    // initialized[recipient][treeIndex] = wasItInitialized?\n    mapping (address => mapping (uint => bool)) public initialized;\n\n    // array-like sequential map for all the vesting schedules\n    mapping (uint => MerkleTree) public merkleTrees;\n\n    // tranches[recipient][treeIndex] = initializedVestingSchedule\n    mapping (address => mapping (uint => Tranche)) public tranches;\n\n    // every time there's a withdrawal\n    event WithdrawalOccurred(uint indexed treeIndex, address indexed destination, uint numTokens, uint tokensLeft);\n\n    // every time a tree is added\n    event MerkleRootAdded(uint indexed treeIndex, address indexed tokenAddress, bytes32 newRoot, bytes32 ipfsHash);\n\n    // every time a tree is topped up\n    event TokensDeposited(uint indexed treeIndex, address indexed tokenAddress, uint amount);\n\n    /// @notice Add a new merkle tree to the contract, creating a new merkle-vesting-schedule\n    /// @dev Anyone may call this function, therefore we must make sure trees cannot affect each other\n    /// @dev Root hash should be built from (destination, totalCoins, startTime, endTime, lockPeriodEndTime)\n    /// @param newRoot root hash of merkle tree representing vesting schedules\n    /// @param ipfsHash the ipfs hash of the entire dataset, used for redundance so that creator can ensure merkleproof are always computable\n    /// @param tokenAddress the address of the token contract that is being distributed\n    /// @param tokenBalance the amount of tokens user wishes to use to fund the airdrop, note trees can be under/overfunded\n    function addMerkleRoot(bytes32 newRoot, bytes32 ipfsHash, address tokenAddress, uint tokenBalance) public {\n        // prefix operator ++ increments then evaluates\n        merkleTrees[++numTrees] = MerkleTree(\n            newRoot,\n            ipfsHash,\n            tokenAddress,\n            0    // no funds have been allocated to the tree yet\n        );\n        // fund the tree now\n        depositTokens(numTrees, tokenBalance);\n        emit MerkleRootAdded(numTrees, tokenAddress, newRoot, ipfsHash);\n    }\n\n    /// @notice Add funds to an existing merkle-vesting-schedule\n    /// @dev Anyone may call this function, the only risk here is that the token contract is malicious, rendering the tree malicious\n    /// @dev If the tree is over-funded, excess funds are lost. No clear way to get around this without zk-proofs\n    /// @param treeIndex index into array-like map of merkleTrees\n    /// @param value the amount of tokens user wishes to use to fund the airdrop, note trees can be underfunded\n    function depositTokens(uint treeIndex, uint value) public {\n        // storage since we are editing\n        MerkleTree storage merkleTree = merkleTrees[treeIndex];\n\n        // bookkeeping to make sure trees don't share tokens\n        merkleTree.tokenBalance += value;\n\n        // transfer tokens, if this is a malicious token, then this whole tree is malicious\n        // but it does not effect the other trees\n        require(IERC20(merkleTree.tokenAddress).transferFrom(msg.sender, address(this), value), \"ERC20 transfer failed\");\n        emit TokensDeposited(treeIndex, merkleTree.tokenAddress, value);\n    }\n\n    /// @notice Called once per recipient of a vesting schedule to initialize the vesting schedule\n    /// @dev Anyone may call this function, the only risk here is that the token contract is malicious, rendering the tree malicious\n    /// @dev If the tree is over-funded, excess funds are lost. No clear way to get around this without zk-proofs of global tree stats\n    /// @dev The contract has no knowledge of the vesting schedules until this function is called\n    /// @param treeIndex index into array-like map of merkleTrees\n    /// @param destination address that will receive tokens\n    /// @param totalCoins amount of tokens to be released after vesting completes\n    /// @param startTime time that vesting schedule starts, can be past or future\n    /// @param endTime time vesting schedule completes, can be past or future\n    /// @param lockPeriodEndTime time that coins become unlocked, can be after endTime\n    /// @param proof array of hashes linking leaf hash of (destination, totalCoins, startTime, endTime, lockPeriodEndTime) to root\n    function initialize(uint treeIndex, address destination, uint totalCoins, uint startTime, uint endTime, uint lockPeriodEndTime, bytes32[] memory proof) external {\n        // must not initialize multiple times\n        require(!initialized[destination][treeIndex], \"Already initialized\");\n        // leaf hash is digest of vesting schedule parameters and destination\n        // NOTE: use abi.encode, not abi.encodePacked to avoid possible (but unlikely) collision\n        bytes32 leaf = keccak256(abi.encode(destination, totalCoins, startTime, endTime, lockPeriodEndTime));\n        // memory because we read only\n        MerkleTree memory tree = merkleTrees[treeIndex];\n        // call to MerkleLib to check if the submitted data is correct\n        require(tree.rootHash.verifyProof(leaf, proof), \"The proof could not be verified.\");\n        // set initialized, preventing double initialization\n        initialized[destination][treeIndex] = true;\n        // precompute how many coins are released per second\n        uint coinsPerSecond = totalCoins / (endTime - startTime);\n        // create the tranche struct and assign it\n        tranches[destination][treeIndex] = Tranche(\n            totalCoins,  // total coins to be released\n            totalCoins,  // currentCoins starts as totalCoins\n            startTime,\n            endTime,\n            coinsPerSecond,\n            startTime,    // lastWithdrawal starts as startTime\n            lockPeriodEndTime\n        );\n        // if we've passed the lock time go ahead and perform a withdrawal now\n        if (lockPeriodEndTime < block.timestamp) {\n            withdraw(treeIndex, destination);\n        }\n    }\n\n    /// @notice Claim funds as a recipient in the merkle-drop\n    /// @dev Anyone may call this function for anyone else, funds go to destination regardless, it's just a question of\n    /// @dev who provides the proof and pays the gas, msg.sender is not used in this function\n    /// @param treeIndex index into array-like map of merkleTrees, which tree should we apply the proof to?\n    /// @param destination recipient of tokens\n    function withdraw(uint treeIndex, address destination) public {\n        // cannot withdraw from an uninitialized vesting schedule\n        require(initialized[destination][treeIndex], \"You must initialize your account first.\");\n        // storage because we will modify it\n        Tranche storage tranche = tranches[destination][treeIndex];\n        // no withdrawals before lock time ends\n        require(block.timestamp > tranche.lockPeriodEndTime, 'Must wait until after lock period');\n        // revert if there's nothing left\n        require(tranche.currentCoins >  0, 'No coins left to withdraw');\n\n        // declaration for branched assignment\n        uint currentWithdrawal = 0;\n\n        // if after vesting period ends, give them the remaining coins\n        if (block.timestamp >= tranche.endTime) {\n            currentWithdrawal = tranche.currentCoins;\n        } else {\n            // compute allowed withdrawal\n            currentWithdrawal = (block.timestamp - tranche.lastWithdrawalTime) * tranche.coinsPerSecond;\n        }\n\n        // decrease allocation of coins\n        tranche.currentCoins -= currentWithdrawal;\n        // this makes sure coins don't get double withdrawn\n        tranche.lastWithdrawalTime = block.timestamp;\n\n        // update the tree balance so trees can't take each other's tokens\n        MerkleTree storage tree = merkleTrees[treeIndex];\n        tree.tokenBalance -= currentWithdrawal;\n\n        // Transfer the tokens, if the token contract is malicious, this will make the whole tree malicious\n        // but this does not allow re-entrance due to struct updates and it does not effect other trees.\n        // It is also consistent with the ethereum general security model:\n        // other contracts do what they want, it's our job to protect our contract\n        IERC20(tree.tokenAddress).transfer(destination, currentWithdrawal);\n        emit WithdrawalOccurred(treeIndex, destination, currentWithdrawal, tranche.currentCoins);\n    }\n\n}"
}