contract ERC20CappedShort is
    ERC20Short,
    ERC20CappedPosition,
    DetailedERC20
{
    using SafeMath for uint256;

    // ============ Constructor ============

    constructor(
        bytes32 positionId,
        address margin,
        address initialTokenHolder,
        address[] trustedRecipients,
        address[] trustedWithdrawers,
        address[] trustedLateClosers,
        uint256 cap,
        string name,
        string symbol,
        uint8 decimals
    )
        public
        ERC20Short(
            positionId,
            margin,
            initialTokenHolder,
            trustedRecipients,
            trustedWithdrawers
        )
        ERC20CappedPosition(
            trustedLateClosers,
            cap
        )
        DetailedERC20(
            name,
            symbol,
            decimals
        )
    {
    }

    // ============ Internal Overriding Functions ============

    function getTokenAmountOnAdd(
        uint256 principalAdded
    )
        internal
        view
        returns (uint256)
    {
        uint256 tokenAmount = super.getTokenAmountOnAdd(principalAdded);

        require(
            totalSupply_.add(tokenAmount) <= tokenCap,
            "ERC20CappedShort#getTokenAmountOnAdd: Adding tokenAmount would exceed cap"
        );

        return tokenAmount;
    }
}
/**
 * @title ERC20CappedShort
 * @author dYdX
 *
 * ERC20Short with a limit on the number of tokens that can be minted, and a restriction on
 * which addreses can close the position after it is force-recoverable.
 */
function getTokenAmountOnAdd(
        uint256 principalAdded
    )
        internal
        view
        returns (uint256)
    {
        uint256 tokenAmount = super.getTokenAmountOnAdd(principalAdded);

        require(
            totalSupply_.add(tokenAmount) <= tokenCap,
            "ERC20CappedShort#getTokenAmountOnAdd: Adding tokenAmount would exceed cap"
        );

        return tokenAmount;
    }
// ============ Internal Overriding Functions ============