Monaco will continue to host Formula 1 races until at least 2031 after a new six-year deal was agreed.