Optimal Incentives in a Principal-Agent Model with Endogenous Technology