Skip to content
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

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from

Conversation

Debugger022
Copy link
Contributor

Description

Resolves #

Checklist

  • I have updated the documentation to account for the changes in the code.
  • If I added new functionality, I added tests covering it.
  • If I fixed a bug, I added a test preventing this bug from silently reappearing again.
  • My contribution follows Venus contribution guidelines.

@Debugger022 Debugger022 self-assigned this Dec 4, 2024
@coreyar coreyar force-pushed the feat/transient-storage branch from 8753f1f to a799afb Compare December 12, 2024 15:46
@Debugger022 Debugger022 marked this pull request as ready for review January 7, 2025 10:21
@@ -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"));
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@web3rover
Copy link
Contributor

@Debugger022 The CI is failing

@chechu chechu changed the title Add transient storage to Resilient oracle [VEN-2999]: add transient storage to Resilient oracle Jan 7, 2025
Comment on lines 347 to 369
/**
* @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)
}
}
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 5 to 6
/// Slot to cache the asset's price, used for transient storage
bytes32 public constant CACHE_SLOT = keccak256(abi.encode("venus-protocol/oracle/ResilientOracle/cache"));
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

Code Coverage

Package Line Rate Branch Rate Health
contracts 81% 79%
contracts.interfaces 28% 21%
contracts.lib 50% 100%
contracts.oracles 89% 80%
contracts.oracles.common 100% 100%
Summary 83% (300 / 363) 76% (145 / 192)

@Debugger022 Debugger022 requested a review from chechu January 14, 2025 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants