Monaco has agreed a six-year contract extension to host the Formula One Grand Prix until 2031, organisers announced.