Skip to content

Commit 1e35d16

Browse files
committed
Adds KHYPEApi3ReaderProxyV1 and WstHYPEApi3ReaderProxyV1 adapter contracts
1 parent a9c17ac commit 1e35d16

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.27;
3+
4+
import "@api3/contracts/interfaces/IApi3ReaderProxy.sol";
5+
6+
// Minimal interface for StakingAccountant
7+
interface IStakingAccountant {
8+
function kHYPEToHYPE(uint256 kHYPEAmount) external view returns (uint256);
9+
}
10+
11+
/// @title An immutable proxy contract that reads the kHYPE/HYPE exchange rate on
12+
/// the HyperEVM network.
13+
/// from the StakingAccountant contract.
14+
/// @dev This contract implements only the IApi3ReaderProxy and not the
15+
/// AggregatorV2V3Interface which is usually implemented with Api3 proxies. The
16+
/// user of this contract needs to be aware of this and only use this contract
17+
/// where the IApi3ReaderProxy interface is expected.
18+
contract KHYPEApi3ReaderProxyV1 is IApi3ReaderProxy {
19+
/// @dev Address of the StakingAccountant contract. This address belongs to
20+
/// the deployment on HyperEVM chain.
21+
IStakingAccountant public constant STAKING_ACCOUNTANT =
22+
IStakingAccountant(0x9209648Ec9D448EF57116B73A2f081835643dc7A);
23+
24+
/// @inheritdoc IApi3ReaderProxy
25+
/// @dev The value returned by this function is the HYPE amount for 1 kHYPE,
26+
/// scaled to 18 decimals. The timestamp returned is the current block
27+
/// timestamp.
28+
function read()
29+
public
30+
view
31+
override
32+
returns (int224 value, uint32 timestamp)
33+
{
34+
// The kHYPEToHYPE function returns the amount of HYPE for a given amount
35+
// of kHYPE.
36+
// 1e18 is passed (representing 1 kHYPE, as it has 18 decimals) to get
37+
// the rate.
38+
uint256 HYPEPerKHYPE = STAKING_ACCOUNTANT.kHYPEToHYPE(1e18);
39+
40+
value = int224(int256(HYPEPerKHYPE));
41+
timestamp = uint32(block.timestamp);
42+
}
43+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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

Comments
 (0)