The positionExpirations and exercisedPositions mappings may be packed into a single mapping using a struct, if you're willing to use a smaller integer type to represent expiration timestamps.
/**
@notice The current expiration timestamp of a position. Maps
from positionId to an expiration unix timestamp.
*/
mapping(uint256 => uint256) public positionExpirations;
/**
@notice Whether or not a position has been exercised. Maps
from positionId to isExercised.
*/
mapping(uint256 => bool) public exercisedPositions;
For example, something like:
struct Position {
uint128 expiration;
bool exercised;
}
mapping(uint256 => Position) public positions;
This will save gas on exercise and withdraw, but slightly increase the cost of fillOrder.
Pack storage variables
The
positionExpirations
andexercisedPositions
mappings may be packed into a single mapping using a struct, if you're willing to use a smaller integer type to represent expiration timestamps.PuttyV2.sol#L145-155
:For example, something like:
This will save gas on
exercise
andwithdraw
, but slightly increase the cost offillOrder
.Gas report before:
Gas report after: