Lockie Ferguson bowled only two overs before having to leave the field because of a calf injury, but he claimed a hat-trick to rip out Sri Lanka's top order, as he collected figures of 3 for 7.