HyperFunToken

VaultCore (HyperFunToken.sol)

HyperFunToken.sol is the core vault contract. It is also the ERC20 vault token and AMM.

Inheritance

contract HyperFunToken is
    Initializable,
    UUPSUpgradeable,
    OwnableUpgradeable,
    ReentrancyGuardUpgradeable,
    ERC20Upgradeable

Key Constants

uint256 public constant BPS = 10000;
uint256 public constant PRECISION = 1e18;
uint256 public constant MAX_FEE = 3000; // 30%

address public constant USDC = 0xb88339CB7199b77E23DB6E890353E22632Ba630f;
address public constant CORE_DEPOSIT_WALLET = 0x6B9E773128f453f5c2C60935Ee2DE2CBc5390A24;
ICoreWriter public constant CORE_WRITER = ICoreWriter(0x3333333333333333333333333333333333333333);
address public constant USDC_L1_SYSTEM = 0x2000000000000000000000000000000000000000;
address public constant PRECOMPILE_SPOT = 0x0000000000000000000000000000000000000801;

State Variables

Vault Roles

Bonding Curve

Fee Settings

Note: Trading fee, price limits, exit fee tiers, and other settings are now read from Factory global settings via _getSettings() and _getSettingsExt().

Accounting

Pending Sells

TWAP NAV (V40)

Metadata


Core Functions

Buy Tokens

Buy vault tokens with USDC. Includes slippage protection via minTokensOut.

Flow:

  1. Validate usdcAmount >= minDepositUsdc

  2. Get smoothed NAV for price protection

  3. Transfer USDC to vault

  4. Deduct trading fee (default 1%)

  5. Calculate tokens via constant product formula

  6. Check slippage: tokensOut >= minTokensOut

  7. Check max buy limit (90% of virtual tokens)

  8. Update bonding curve reserves

  9. Mint tokens to buyer

  10. Update entry record and purchase info

  11. Transfer fee to treasury

  12. Trigger auto-rebalance

  13. Update TWAP NAV

Sell Tokens

Sell vault tokens for USDC. Includes slippage protection via minUsdcOut.

Flow:

  1. Validate balance and no existing pending sell

  2. Get smoothed NAV

  3. Calculate performance fee (if profitable)

  4. Calculate USDC out via constant product formula

  5. Calculate exit fee (time-based)

  6. Cap by available liquidity

  7. Check slippage: netUsdcOut >= minUsdcOut

  8. Update bonding curve reserves

  9. Burn tokens

  10. Mint performance fee tokens to leader

  11. Transfer USDC (or create pending sell)

  12. Update TWAP NAV

Claim Pending Sell

Claim USDC from a pending sell after L1 funds have arrived.

Leader Deposit

Leader-only function to deposit USDC at NAV (no bonding curve, no trading fee).


View Functions

Calculations

Assets & Liquidity

Bonding Curve


Admin Functions

Factory Owner Only

Trading Module Only

Leader Only

Emergency (Factory Owner)


Events


Access Control


Upgrade Authority

Security: Only factory owner can upgrade. Leaders cannot upgrade, protecting investors from malicious upgrades.


Internal Mechanisms

NAV uses graduation tiers from Factory for dynamic virtual assets:

TWAP NAV (V40)

Smoothed NAV protects against sudden price spikes during liquidations:

Performance Fee

Calculated on profit using weighted average entry NAV:

Entry NAV Inheritance

Prevents performance fee gaming via token transfers:


Contract
Role

HyperFunFactory

Global settings, vault creation

HyperFunTrading

L1 trading execution

Last updated