[Gas - 02] - Directly settle short orders in exercise
In exercise, why not directly settling the deal ?
The gas overhead would be minimal has the transfers are already done, and you’d save a ton of gas in the overall flow. Instead of doing a 2 time transfer msg.sender -> contract during exercise and then contract -> maker or taker during withdraw, you could directly do the accounting, burn the position and do the correct transfers in exercise. There would still be a withdraw function, but only for non-exercised options.
Especially as the order is immutable, we already know during exercise than withdraw will be called, so this optimisation is worth doing to me, although it requires some work.
[Gas - 01] - Use Custom Errors
Instead of using error strings, to reduce deployment and runtime cost, you should use Custom Errors: see https://blog.soliditylang.org/2021/04/21/custom-errors/. This would save both deployment and runtime cost.
[Gas - 02] - Directly settle short orders in
exercise
In
exercise
, why not directly settling the deal ?The gas overhead would be minimal has the transfers are already done, and you’d save a ton of gas in the overall flow. Instead of doing a 2 time transfer
msg.sender
->contract
duringexercise
and thencontract
->maker
ortaker
during withdraw, you could directly do the accounting, burn the position and do the correct transfers inexercise
. There would still be awithdraw
function, but only for non-exercised options.Especially as the order is immutable, we already know during
exercise
thanwithdraw
will be called, so this optimisation is worth doing to me, although it requires some work.