Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions contracts/KHYPEApi3ReaderProxyV1.sol
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);
Copy link
Contributor

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)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

}

/// @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
// 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);
}
}
51 changes: 51 additions & 0 deletions contracts/WstHYPEApi3ReaderProxyV1.sol
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);
}
}
Loading