Honestly, I'd make it a federal law that if the difference between the top 2 for any federal office (including electors for President) is less than 1% of the total votes cast, there's an automatic recount, overseen by judges, costs paid by the federal government, which cannot be interrupted, challenged, or stopped for any reason barring natural disasters, and mandate paper trails for all voting machines (or, better, that voting machines used for federal elections read voter-marked paper ballots, not just print off a paper receipt). (Up here the federal threshold is 0.1%, and, yes, I'd make that 1%, too.)
Your proposed law violates basic precepts of federalism, and is unconstitutional.
That's fair. I think it would make elections fairer, but I can see how it is
ultra vires the federal government. Still, there could be the "bribe them to do it" approach (or the "withhold highway funding" approach--as I recall that's how the federal government got the drinking age raised to 21 in every state).
However, I would note that it doesn't necessarily violate basic precepts of federalism, only US-style federalism (up here the federal governments regulates its own elections, for instance, and Canada is most definitely federal*), and constitutions can be amended.
*If you want to object that Canada leaves residual powers to the federal government, not the provinces, then I would note, for one, that provinces also regulate their own elections, and for another, that in Australia, which is also federal, residual powers are left to the states, not the federal government**, and the federal government, rather than the states, regulates federal elections.
**This is why the gun ban in Australia is achieved through coordinating state and territorial legislation, rather than federal legislation. The Australian government has no authority to regulate firearms.
My proposal may well violate the precepts of the federal system to which you're accustomed, but it most definitely does not violate the "basic precepts of federalism," because the particulars of an implementation of the concept of federalism that are not shared across all systems implementing it (as this one is not) cannot, by definition, be "basic precepts."