Skip to content

Conversation

@tbwebb22
Copy link

@tbwebb22 tbwebb22 commented Oct 14, 2025

Closes ACX-4548

@tbwebb22 tbwebb22 self-assigned this Oct 14, 2025
@tbwebb22 tbwebb22 marked this pull request as draft October 15, 2025 01:20
@tbwebb22 tbwebb22 changed the title Hypercorelib feat: Hypercorelib Oct 15, 2025
@linear
Copy link

linear bot commented Oct 15, 2025

ACX-4548 `HyperCoreLib`

* @param to The address to receive tokens on HyperCore
* @param amountCore The amount to transfer on HyperCore
*/
function transferERC20CoreToCore(uint64 erc20CoreIndex, address to, uint64 amountCore) internal {
Copy link
Author

Choose a reason for hiding this comment

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

This function could check this contract's spot balance on HyperCore and revert if it is less than amountCore. Or this check could be handled at the higher level handler contracts. Thoughts on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

My intuition is that we treat this lib as a rather low-level primitive. Handler contracts are the ones to make sure our interactions with HCore make sense in terms of failures. I'd leave this responsibility to them

Copy link
Contributor

@fusmanii fusmanii left a comment

Choose a reason for hiding this comment

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

Great stuff, looks good just have some minor comments and questions

* @param erc20CoreIndex The HyperCore index id of the token to transfer
* @param decimalDiff The decimal difference of evmDecimals - coreDecimals
* @param bridgeAddress The asset bridge address of the token to transfer
* @param amountEVM The number of tokens that (pre-dusted) that we are trying to send
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @param amountEVM The number of tokens that (pre-dusted) that we are trying to send
* @param amountEVM The number of tokens (pre-dusted) that we are trying to send

also what do you mean by pre-dusted here?

Copy link
Author

Choose a reason for hiding this comment

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

so since the EVM and HyperCore typically have different decimals for the same token, when bridging across you can end up losing this dust amount that results from the decimal difference. This function takes the amount we want to send (EVM decimals, this is the pre-dusted amount) and removes that small amount that we would have lost from dust. So we send a little less, but don't lose any amount to dust.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok makes sense, and that would only be true in the case that evm decimal > core decimal

* @param assetBridgeAddress The asset bridge address to convert
* @return erc20CoreIndex The core token index id
*/
function into_tokenId(address assetBridgeAddress) internal pure returns (uint64) {
Copy link
Contributor

Choose a reason for hiding this comment

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

let use camelCase for this and the rest of the functions below

Copy link
Author

Choose a reason for hiding this comment

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

good call, done!

Comment on lines +329 to +330
if (amountEVM > maxTransferableAmountEVM)
revert TransferAmtExceedsAssetBridgeBalance(amountEVM, maxTransferableAmountEVM);
Copy link
Contributor

Choose a reason for hiding this comment

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

nice check!!

// Basic sanity checks
if (limitPriceX1e8 == 0) revert LimitPxIsZero();
if (sizeX1e8 == 0) revert OrderSizeIsZero();
if (!(encodedTif == 1 || encodedTif == 2 || encodedTif == 3)) revert InvalidTif();
Copy link
Contributor

Choose a reason for hiding this comment

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

should we create an enum for these?

Copy link
Author

Choose a reason for hiding this comment

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

I like that, enum added

* @param cloid The client order id of the order, 0 means no cloid
*/
function submitLimitOrder(
uint32 asset,
Copy link
Contributor

Choose a reason for hiding this comment

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

is asset here different than the erc20CoreIndex you have in the functions above?

Copy link
Author

Choose a reason for hiding this comment

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

yes, asset refers to a spot market index which is different from the erc20CoreIndex

https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/asset-ids

// Basic sanity checks
if (limitPriceX1e8 == 0) revert LimitPxIsZero();
if (sizeX1e8 == 0) revert OrderSizeIsZero();
if (tif == Tif.None || uint8(tif) > uint8(Tif.IOC)) revert InvalidTif();
Copy link
Contributor

Choose a reason for hiding this comment

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

since tif will never be None lets remove it

also you can just do

Suggested change
if (tif == Tif.None || uint8(tif) > uint8(Tif.IOC)) revert InvalidTif();
if (uint8(tif) > uint8(type(Tif).max)) revert InvalidTif();

@tbwebb22 tbwebb22 marked this pull request as ready for review October 15, 2025 23:37
@tbwebb22 tbwebb22 merged commit cd311fd into audit-oct-20 Oct 15, 2025
7 of 8 checks passed
@tbwebb22 tbwebb22 deleted the hypercorelib branch October 15, 2025 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants