compute_spot_to_evm_withdrawal_amount

Documentation for eth_defi.hyperliquid.core_writer.compute_spot_to_evm_withdrawal_amount function.

compute_spot_to_evm_withdrawal_amount(spot_balance, desired_amount)

Compute the actual sendAsset amount after reserving bridge fee margin.

HyperCore charges a bridge fee on spot before the linked token settles on HyperEVM. When the caller intends to bridge the entire spot balance, the requested amount must be reduced by HYPERCORE_BRIDGE_FEE_MARGIN so that enough USDC remains on spot to cover the fee.

If the desired amount already leaves sufficient margin (spot_balance - desired_amount >= HYPERCORE_BRIDGE_FEE_MARGIN), it is returned unchanged.

If the spot balance is too small (at or below the fee margin), returns Decimal(0) — callers must check for this and skip the withdrawal or raise an operator error.

Parameters
  • spot_balance (decimal.Decimal) – Current HyperCore spot free USDC balance (human-readable).

  • desired_amount (decimal.Decimal) – Amount the caller wants to bridge to HyperEVM (human-readable).

Returns

Adjusted withdrawal amount (human-readable). May be zero if the spot balance cannot cover the fee margin.

Return type

decimal.Decimal