Skip to content
Merged
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
22 changes: 21 additions & 1 deletion contracts/libraries/HyperCoreLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ library HyperCoreLib {
* @param index The asset index to get the spot price of
* @return spotPx The spot price of the specified asset on HyperCore scaled by 1e8
*/
function spotPx(uint32 index) external view returns (uint64) {
function spotPx(uint32 index) internal view returns (uint64) {
(bool success, bytes memory result) = SPOT_PX_PRECOMPILE_ADDRESS.staticcall(abi.encode(index));
if (!success) revert SpotPxPrecompileCallFailed();
return abi.decode(result, (uint64));
Expand All @@ -237,6 +237,26 @@ library HyperCoreLib {
return _tokenInfo;
}

/**
* @notice Checks if an amount is safe to bridge from HyperEVM to HyperCore
* @dev Verifies that the asset bridge has sufficient balance to cover the amount plus a buffer
* @param erc20CoreIndex The HyperCore index id of the token
* @param coreAmount The amount that the bridging should result in on HyperCore
* @param coreBufferAmount The minimum buffer amount that should remain on HyperCore after bridging
* @return True if the bridge has enough balance to safely bridge the amount, false otherwise
*/
function isCoreAmountSafeToBridge(
uint64 erc20CoreIndex,
uint64 coreAmount,
uint64 coreBufferAmount
) internal view returns (bool) {
address bridgeAddress = toAssetBridgeAddress(erc20CoreIndex);
uint64 currentBridgeBalance = spotBalance(bridgeAddress, erc20CoreIndex);

// Return true if currentBridgeBalance >= coreAmount + coreBufferAmount
return currentBridgeBalance >= coreAmount + coreBufferAmount;
}

/**
* @notice Converts a core index id to an asset bridge address
* @param erc20CoreIndex The core token index id to convert
Expand Down
Loading