-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[VEN-2999]: add transient storage to Resilient oracle #239
base: develop
Are you sure you want to change the base?
Conversation
8753f1f
to
a799afb
Compare
contracts/ResilientOracle.sol
Outdated
@@ -88,6 +88,9 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr | |||
|
|||
mapping(address => TokenConfig) private tokenConfigs; | |||
|
|||
/// Slot to cache the asset's price, used for transient storage | |||
bytes32 constant CACHE_SLOT = keccak256(abi.encode("venus-protocol/oracle/ResilientOracle/cache")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
vars should be declared above tokenConfigs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Debugger022 The CI is failing |
contracts/ResilientOracle.sol
Outdated
/** | ||
* @notice Cache the asset price into transient storage | ||
* @param key address of the asset | ||
* @param value asset price | ||
*/ | ||
function _cachePrice(address key, uint256 value) internal { | ||
bytes32 slot = keccak256(abi.encode(CACHE_SLOT, key)); | ||
assembly ("memory-safe") { | ||
tstore(slot, value) | ||
} | ||
} | ||
|
||
/** | ||
* @notice Read cached price from transient storage | ||
* @param key address of the asset | ||
* @return value cached asset price | ||
*/ | ||
function _readCachedPrice(address key) internal view returns (uint256 value) { | ||
bytes32 slot = keccak256(abi.encode(CACHE_SLOT, key)); | ||
assembly ("memory-safe") { | ||
value := tload(slot) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could extract these functions to an external file, to reuse it in other oracles caching prices
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contracts/lib/Transient.sol
Outdated
/// Slot to cache the asset's price, used for transient storage | ||
bytes32 public constant CACHE_SLOT = keccak256(abi.encode("venus-protocol/oracle/ResilientOracle/cache")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not put this in the library. It seems it's specific to the ResilientOracle contract. I would allow every contract using this library to define their own slot. Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description
Resolves #
Checklist