|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.27; |
| 3 | + |
| 4 | +import "@api3/contracts/interfaces/IApi3ReaderProxy.sol"; |
| 5 | + |
| 6 | +// Minimal interface for wstHYPE |
| 7 | +interface IWstHYPE { |
| 8 | + function sthype() external view returns (address); |
| 9 | +} |
| 10 | + |
| 11 | +// Minimal interface for stHYPE |
| 12 | +interface IStHYPE { |
| 13 | + function sharesToBalance(uint256 shares) external view returns (uint256); |
| 14 | +} |
| 15 | + |
| 16 | +/// @title An immutable proxy contract that reads the wstHYPE/stHYPE exchange |
| 17 | +/// rate on the HyperEVM network. |
| 18 | +/// @dev This contract implements only the IApi3ReaderProxy and not the |
| 19 | +/// AggregatorV2V3Interface which is usually implemented with Api3 proxies. The |
| 20 | +/// user of this contract needs to be aware of this and only use this contract |
| 21 | +/// where the IApi3ReaderProxy interface is expected. |
| 22 | +contract WstHYPEApi3ReaderProxyV1 is IApi3ReaderProxy { |
| 23 | + /// @dev Address of the wstHYPE contract. This address belongs to the |
| 24 | + /// deployment on HyperEVM chain. |
| 25 | + IWstHYPE public constant WST_HYPE = |
| 26 | + IWstHYPE(0x94e8396e0869c9F2200760aF0621aFd240E1CF38); |
| 27 | + |
| 28 | + /// @inheritdoc IApi3ReaderProxy |
| 29 | + /// @dev The value returned by this function is the stHYPE amount for 1 |
| 30 | + /// wstHYPE, scaled to 18 decimals. The timestamp returned is the current |
| 31 | + /// block timestamp. |
| 32 | + function read() |
| 33 | + public |
| 34 | + view |
| 35 | + override |
| 36 | + returns (int224 value, uint32 timestamp) |
| 37 | + { |
| 38 | + address stHYPEAddress = WST_HYPE.sthype(); |
| 39 | + |
| 40 | + // The logic is analogous to wstETH's stEthPerToken(), which returns |
| 41 | + // stETH.getPooledEthByShares(1 ether). |
| 42 | + // Here, it is assumed 1 wstHYPE corresponds to 1e24 shares of stHYPE, as |
| 43 | + // stHYPE shares have 24 decimals. |
| 44 | + // These shares are then converted to a balance of stHYPE (which has 18 |
| 45 | + // decimals). |
| 46 | + uint256 stHYPEPerToken = IStHYPE(stHYPEAddress).sharesToBalance(1e24); |
| 47 | + |
| 48 | + value = int224(int256(stHYPEPerToken)); |
| 49 | + timestamp = uint32(block.timestamp); |
| 50 | + } |
| 51 | +} |
0 commit comments