
Gas Optimization Tips
1. Batch Multiple Reads
bytes32[] memory assetIds = new bytes32[](3);
// populate array
(IIfaPriceFeed.PriceFeed[] memory infos, bool[] memory exists) = oracle.getAssetsInfo(assetIds);2. Cache Prices in Storage (When Appropriate)
mapping(bytes32 => int256) public cachedPrices;
uint256 public lastCacheUpdate;
function updateCache(bytes32[] calldata assetIds) external {
// ... batch read and store
lastCacheUpdate = block.timestamp;
}3. Use Constants for Asset IDs and Oracle Address
4. Pack Variables Efficiently
5. Minimize External Calls in Hot Paths
Quick Gas Checklist
Last updated
Was this helpful?

