Design and valuation of debt contracts