We introduce a model in which firms trade goods via bilateral contracts which specify a buyer, a seller, and the terms of the exchange. This setting subsumes (many-to-many) matching with contracts, as well as supply chain matching. When firms' relationships do not exhibit a supply chain structure, stable allocations need not exist. By contrast, in the presence of supply chain structure, a natural substitutability condition characterizes the maximal domain of firm preferences for which stable allocations always exist. Furthermore, the classical lattice structure, rural hospitals theorem, and one-sided strategy-proofness results all generalize to this setting.The theoretical literature on two-sided matching began with the simple one-to-one (marriage) model of Gale and Shapley (1962), in which agents on opposite sides of a market (men and women) seek to match into pairs. The central solution concept in this literature is stability, the requirement that, if two agents are not matched to each other, at least one of them prefers his or her assigned partner to the other agent. Gale and Shapley (1962) showed that stable one-to-one matches exist in general, and obtained conditions under which this existence result is preserved even if agents on one side of the market are allowed to match to multiple partners, that is, when the matching is many-to-one (as in college admissions and doctor-hospital matching). Following high-profile applications of matching in labor markets and school choice programs, 1 the foundational work on matching has been extensively generalized. 2 Kelso and Crawford (1982) extended many-to-one matching to a setting in which matches are supplemented by wage negotiations; Hatfield and Milgrom (2005) generalized this framework still further, by allowing agents to negotiate contracts which fully specify both a matching and the conditions of the match; the possibility of such a generalization was first noted by remarks of Crawford and Knoer (1981) and Kelso and Crawford (1982).Meanwhile, a host of work has studied the existence of stable matchings in many-to-many matching settings, two-sided markets in which all agents may match to multiple partners (as in the matching of consultants to firms). Many-to-many matching has been studied, for example, in the work of Sotomayor (1999Sotomayor ( , 2004, Echenique and Oviedo (2006), and Konishi andÜnver (2006). Recently, Walzl (2009) andKominers (2010) merged this line of research with that of Hatfield and Milgrom (2005), introducing a theory of many-to-many matching with contracts.