{
    "Function": "withdraw",
    "File": "contracts/MerkleVesting.sol",
    "Parent Contracts": [],
    "High-Level Calls": [
        "IERC20"
    ],
    "Internal Calls": [
        "require(bool,string)",
        "require(bool,string)",
        "require(bool,string)"
    ],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "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    }"
}