function deposit(address token, uint256 amount, bool lock_) external whenNotPaused onlyState(State.Opened) onlySupportedTokens(token) {
    totals[token].total += amount;

    if (caps[token] > 0 && totals[token].total > caps[token]) {
        revert ErrCapReached();
    }
}
function withdraw(address token, uint256 amount) external whenNotPaused onlySupportedTokens(token) {
    balances[msg.sender][token].unlocked -= amount;
    balances[msg.sender][token].total -= amount;
    totals[token].unlocked -= amount;
    totals[token].total -= amount;
    token.safeTransfer(msg.sender, amount);
}
function deposit(address token, uint256 amount, bool lock_) external whenNotPaused onlyState(State.Opened) onlySupportedTokens(token) {
    totals[token].total += amount;

-    if (caps[token] > 0 && totals[token].total > caps[token]) {
+    if (caps[token] > 0 && totals[token].locked > caps[token]) {
        revert ErrCapReached();
    }
}
function lock(address token, uint256 amount) external whenNotPaused onlyState(State.Opened) onlySupportedTokens(token) {
    balances[msg.sender][token].unlocked -= amount;
    balances[msg.sender][token].locked += amount;
    totals[token].unlocked -= amount;
    totals[token].locked += amount;
+    if (caps[token] > 0 && totals[token].locked > caps[token]) {
+        revert ErrCapReached();
+    }
}
