improve: add shared HyperCore primitives to HyperCoreLib - #1530
improve: add shared HyperCore primitives to HyperCoreLib#1530droplet-rl wants to merge 6 commits into
Conversation
ffb15b7 to
a7d49c6
Compare
|
Addressed the review in 9ade0c5. The one inline comment: Two deviations worth flagging:
|
|
@droplet-rl remove these from HyperCoreLib as we no longer need them in
|
|
Removed all seven in 4f10326:
Also dropped their four tests. Grep confirms no remaining references anywhere in Left Verified: Net effect on the PR: it's now the HYPE/chain/system-address primitives only — |
CounterfactualHyperCoreWithdrawer (contracts-v5#203) hand-rolled a set of HyperCore constants and calls that HyperCoreLib already owns the equivalents of. Review on that PR asked for them to be upstreamed rather than kept as a second source of truth. Adds, with no change to existing behavior: - WITHDRAWABLE_PRECOMPILE_ADDRESS (0x803) and withdrawable(), decoded through a named Withdrawable struct to match spotBalance/coreUserExists - USD_CLASS_TRANSFER_HEADER and transferUsdClass(), replacing a direct ICoreWriter.sendRawAction at the call site - HYPE_SYSTEM_ADDRESS, HYPE_CORE_INDEX, HYPE_CORE_INDEX_TESTNET, plus hypeCoreIndex()/isHype() for the chain-dependent index selection - HYPEREVM_CHAIN_ID, HYPEREVM_TESTNET_CHAIN_ID and isHyperEVMChain() Encodings verified against the vendored hyper-evm-lib reference (PrecompileLib.withdrawable, CoreWriterLib.transferUsdClass, HLConstants). Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: droplet-rl <284132418+droplet-rl@users.noreply.github.com>
…rawal contracts-v5#203 dropped its perp -> spot -> EVM two-step for a single `sendAsset` carrying a `sourceDex`, so the shape of what the leaf needs from this library changed. - Drop `transferUsdClass` / `USD_CLASS_TRANSFER_HEADER`. Their only motivating caller was the leaf's `_perpToSpot`, removed in 933ddfc6; `transferERC20CoreToCore` already covers the new path. - Add `CORE_MAIN_PERP_DEX_ID` and `PERP_USD_TO_USDC_CORE_WEI`, the two constants the rewritten leaf now keeps locally. USDC's Core `weiDecimals` is 8 against perp's 1e6, so the ratio is 100 (read off the mainnet `tokenInfo` precompile, not assumed). - Add `toSystemAddress`, the remaining duplicated branch of the leaf's `_bridgeTarget`. Held back last time because it owned a revert; the rounding removal in 187e8d4e left it a plain address resolver, and it was flagged twice in review. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: droplet-rl <284132418+droplet-rl@users.noreply.github.com>
Replace the hardcoded PERP_USD_TO_USDC_CORE_WEI = 100 factor with a PERP_USD_DECIMALS constant and a perpUsdToCoreWei helper that reads USDC's weiDecimals off tokenInfo, so the conversion tracks the token's actual on-chain config instead of baking in today's 1e6 -> 1e8 gap. Co-Authored-By: Claude <noreply@anthropic.com>
CounterfactualHyperCoreWithdrawer no longer needs these, so remove them rather than ship dead surface area: withdrawable(), the Withdrawable struct, WITHDRAWABLE_PRECOMPILE_ADDRESS, WithdrawablePrecompileCallFailed, perpUsdToCoreWei(), PERP_USD_DECIMALS, and CORE_MAIN_PERP_DEX_ID, plus their tests. Co-Authored-By: Claude <noreply@anthropic.com>
4f10326 to
db554d3
Compare
Fold toAssetBridgeAddress into toSystemAddress (now uint64) so every sender resolves through the HYPE-aware, linkage-checked path: isCoreAmountSafeToBridge previously read the derived 0x2000... address for HYPE instead of 0x2222...2222, and the ERC20 EVM -> Core paths stranded funds at inert addresses for unlinked indices instead of reverting TokenNotBridgeable. Add transferNativeEVMToSelfOnSpot, the native-HYPE sibling of transferERC20EVMToSelfOnSpot, for callers hand-rolling raw sends to HYPE_SYSTEM_ADDRESS. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Ihor Farion <ihor@umaproject.org>
Motivation
Review on contracts-v5#203 (counterfactual HyperCore withdrawals) flagged that
CounterfactualHyperCoreWithdrawerhand-rolls a set of HyperCore constants and calls thatHyperCoreLibalready owns the equivalents of — a second source of truth for precompile addresses and action headers, which is how they drift. Raised by @grasphoper in three separate comments and independently in this one.This PR upstreams them so the v5 leaf can drop its local copies. Opened separately because the lib sits behind the submodule boundary.
What's added
Purely additive — no existing function or constant changes behavior.
WITHDRAWABLE_PRECOMPILE_ADDRESS(0x803),struct Withdrawable,withdrawable(address)abi.decode(result, (uint64))in_perpWithdrawableHYPE_SYSTEM_ADDRESS,HYPE_CORE_INDEX,HYPE_CORE_INDEX_TESTNET,hypeCoreIndex(),isHype(uint32)_bridgeTargetHYPEREVM_CHAIN_ID,HYPEREVM_TESTNET_CHAIN_ID,isHyperEVMChain()execute(suggested name)CORE_MAIN_PERP_DEX_ID(0),PERP_USD_TO_USDC_CORE_WEI(100)MAIN_PERP_DEX/PERP_TO_CORE_WEItoSystemAddress(uint32),error TokenNotBridgeable(uint32)_bridgeTargetwithdrawabledecodes through a namedWithdrawablestruct rather than a bareuint64to match howspotBalance/coreUserExists/tokenInfoalready read their precompiles. Single-field structs abi-decode identically, so this is wire-compatible with the v5 version.CORE_MAIN_PERP_DEX_IDsits next to the existingCORE_SPOT_DEX_ID, its counterpart in the samesendAssetselector space. Only the constants are upstreamed, not the leaf's saturating conversion — clamping vs. reverting on a widened reading is caller policy, so it stays at the call site.Changed in the retarget
Dropped
transferUsdClass/USD_CLASS_TRANSFER_HEADER. Their only motivating caller was the leaf's_perpToSpot, removed in933ddfc6— the perp source now ridestransferERC20CoreToCore, which this lib already had. Rather than land an unused CoreWriter action in a library that's heading into audit, it comes back when something needs it. Say the word if you'd rather keep it.Added
toSystemAddress, previously in out of scope here. It was held back because it owned theevmContract == address(0)revert, which looked like leaf policy;187e8d4edropped theevmExtraWeiDecimalsreturn and left it a plain address resolver, so it now reads as a lib-shaped primitive. It's also the line @grasphoper flagged in this comment.The error moves with it.
TokenNotBridgeable(uint32)has the same signature in both places, so the selector is unchanged and no off-chain decoding breaks; only the Solidity reference path moves (HyperCoreLib.TokenNotBridgeablerather than the leaf's).Verification
Constants were read off the live mainnet/testnet
tokenInfoprecompile (0x…80C) rather than copied from the v5 PR, so a mistake there wouldn't be propagated:tokenInfo(0), mainnet"USDC",weiDecimals = 8,evmExtraWeiDecimals = -2→ confirmsPERP_USD_TO_USDC_CORE_WEI = 1e8/1e6 = 100tokenInfo(150), mainnet"HYPE",evmContract = address(0)→ confirms the HYPE branch must precede the bridgeability checktokenInfo(1105), testnet"HYPE"→ confirmsHYPE_CORE_INDEX_TESTNETwithdrawable's shape was cross-checked against the vendoredhyper-evm-libreference (PrecompileLib.withdrawable→ precompile0x803, decoded viaWithdrawable { uint64 withdrawable; }).End-to-end against v5#203. Pointed the v5
across-contractssubmodule at this branch, rewrote the leaf to use the new helpers, and ran 203's own suite:The leaf goes 146 → 114 lines (
+7 −39): all six local constants, both private helpers (_bridgeTarget,_perpWithdrawable), and one error go away.This side:
Heads-up: the submodule bump is blocked independently of this PR
Consuming this in v5 means bumping
lib/across-contractsoff its current pin (8026a507). That pin is an ancestor ofmaster, but #1520 (db91f503, counterfactual v3 deployments) reshapedICounterfactualBeaconin between, removinggateway(),stablePrice()and the*DepositExecutor()getters that the v5 counterfactual vertical calls. A straight bump tomasterfails to compile atCounterfactualPrefunder.sol:63.Nothing to do with these changes — I verified above by overlaying only
HyperCoreLib.solonto the existing pin — but it's in the way of picking them up, so either cherry-pick this file or reconcile v5 with #1520 first. Flagging rather than guessing which.Still out of scope
The substantive design questions on v5#203 (HYPE fee reserve,
_resolveAmount, full-amount-only withdrawals) belong on that PR.🤖 Generated with Claude Code