King & Wood Mallesons and Wachtell, Lipton, Rosen & Katz have advised U.S. payments provider Square on its deal to buy Australian buy-now-pay-later company Afterpay, in the largest public M&A deal in Australia’s history.

Afterpay was advised by Australian firm Gilbert + Tobin and U.S.-based Cravath, Swaine & Moore in the all-scrip deal with an implied value of A$39 billion (US$29 billion).