-
Couldn't load subscription status.
- Fork 0
Adds KHYPEApi3ReaderProxyV1 and WstHYPEApi3ReaderProxyV1 adapter contracts #51
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.27; | ||
|
|
||
| import "@api3/contracts/interfaces/IApi3ReaderProxy.sol"; | ||
|
|
||
| // Minimal interface for StakingAccountant | ||
| interface IStakingAccountant { | ||
| function kHYPEToHYPE(uint256 kHYPEAmount) external view returns (uint256); | ||
| } | ||
|
|
||
| /// @title An immutable proxy contract that reads the kHYPE/HYPE exchange rate | ||
| /// from the StakingAccountant contract. | ||
| /// @dev This contract implements only the IApi3ReaderProxy and not the | ||
| /// AggregatorV2V3Interface which is usually implemented with Api3 proxies. The | ||
| /// user of this contract needs to be aware of this and only use this contract | ||
| /// where the IApi3ReaderProxy interface is expected. | ||
| contract KHYPEApi3ReaderProxyV1 is IApi3ReaderProxy { | ||
| /// @dev Address of the StakingAccountant contract. This address belongs to | ||
| /// the deployment on HyperEVM chain. | ||
| IStakingAccountant public constant STAKING_ACCOUNTANT = | ||
| IStakingAccountant(0x9209648Ec9D448EF57116B73A2f081835643dc7A); | ||
|
|
||
| /// @inheritdoc IApi3ReaderProxy | ||
| /// @dev The value returned by this function is the HYPE amount for 1 kHYPE, | ||
| /// scaled to 18 decimals. The timestamp returned is the current block | ||
| /// timestamp. | ||
| function read() | ||
| public | ||
| view | ||
| override | ||
| returns (int224 value, uint32 timestamp) | ||
| { | ||
| // The kHYPEToHYPE function returns the amount of HYPE for a given amount | ||
acenolaza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // of kHYPE. | ||
| // 1e18 is passed (representing 1 kHYPE, as it has 18 decimals) to get | ||
| // the rate. | ||
| uint256 HYPEPerKHYPE = STAKING_ACCOUNTANT.kHYPEToHYPE(1e18); | ||
|
|
||
| value = int224(int256(HYPEPerKHYPE)); | ||
| timestamp = uint32(block.timestamp); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.27; | ||
|
|
||
| import "@api3/contracts/interfaces/IApi3ReaderProxy.sol"; | ||
|
|
||
| // Minimal interface for wstHYPE | ||
| interface IWstHYPE { | ||
| function sthype() external view returns (address); | ||
| } | ||
|
|
||
| // Minimal interface for stHYPE | ||
| interface IStHYPE { | ||
| function sharesToBalance(uint256 shares) external view returns (uint256); | ||
| } | ||
|
|
||
| /// @title An immutable proxy contract that reads the wstHYPE/stHYPE exchange | ||
| /// rate on the HyperEVM network. | ||
| /// @dev This contract implements only the IApi3ReaderProxy and not the | ||
| /// AggregatorV2V3Interface which is usually implemented with Api3 proxies. The | ||
| /// user of this contract needs to be aware of this and only use this contract | ||
| /// where the IApi3ReaderProxy interface is expected. | ||
| contract WstHYPEApi3ReaderProxyV1 is IApi3ReaderProxy { | ||
| /// @dev Address of the wstHYPE contract. This address belongs to the | ||
| /// deployment on HyperEVM chain. | ||
| IWstHYPE public constant WST_HYPE = | ||
| IWstHYPE(0x94e8396e0869c9F2200760aF0621aFd240E1CF38); | ||
|
|
||
| /// @inheritdoc IApi3ReaderProxy | ||
| /// @dev The value returned by this function is the stHYPE amount for 1 | ||
| /// wstHYPE, scaled to 18 decimals. The timestamp returned is the current | ||
| /// block timestamp. | ||
| function read() | ||
| public | ||
| view | ||
| override | ||
| returns (int224 value, uint32 timestamp) | ||
| { | ||
| address stHYPEAddress = WST_HYPE.sthype(); | ||
|
|
||
| // The logic is analogous to wstETH's stEthPerToken(), which returns | ||
| // stETH.getPooledEthByShares(1 ether). | ||
| // Here, it is assumed 1 wstHYPE corresponds to 1e24 shares of stHYPE, as | ||
| // stHYPE shares have 24 decimals. | ||
| // These shares are then converted to a balance of stHYPE (which has 18 | ||
| // decimals). | ||
| uint256 stHYPEPerToken = IStHYPE(stHYPEAddress).sharesToBalance(1e24); | ||
|
|
||
| value = int224(int256(stHYPEPerToken)); | ||
| timestamp = uint32(block.timestamp); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
where did you find this iface? On https://purrsec.com/address/0xfD739d4e423301CE9385c1fb8850539D657C296D/contract I can't seem to find source of the implementation (only proxy)
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.
here's the implementation code https://hyperevmscan.io/address/0xecaa7cd734668e086812bd4241d6fc0260dba513#code