# Builder codes

### Overview

beHYPE is a liquid staking token that represents staked HYPE tokens. Users can stake HYPE to receive beHYPE tokens, which continue to earn staking rewards while remaining liquid and transferable.

### Contract Addresses

```solidity
BeHYPE: 0xd8FC8F0b03eBA61F64D08B0bef69d80916E5DdA9
WithdrawManager: 0x9d0B0877b9f2204CF414Ca7862E4f03506822538
StakingCore: 0xCeaD893b162D38e714D82d06a7fe0b0dc3c38E0b
RoleRegistry: 0x90102473a816A01A9fB0809F2289438B2e294F76
BeHYPETimelock: 0xA24aF73EaDD17997EeEdbEd36672e996544D2DE4
L1Read: 0xb7467E0524Afba7006957701d1F06A59000d15A2
beHYPEBatchWithdrawalClaim: 0xA86b7a6942A1861E90BAf713ad70308545BeF966
```

### Minting (Staking)

Send a transaction to the StakingCore contract with the function signature `stake(string communityCode)`. The `communityCode` is the validator name you want those tokens to be designated to. The amount minted will be the amount of HYPE included in the value of the transaction. If you do not have a specific validator to stake to, you can pass an empty string ("") for automatic distribution across validators.

This will mint beHYPE tokens to the caller's address.

```solidity
function Stake() public {
    address user = address(0x1234);
    vm.deal(user, 10 ether);

    vm.startPrank(user); // using the private key of the user
    
    // Stake 10 HYPE to a specific validator
    stakingCore.stake{value: 10 ether}("validator_name");
    
    // Stake another 10 HYPE with automatic validator distribution
    stakingCore.stake{value: 10 ether}("");
}
```

### Burning (Unstaking)

Burning is a multistep process that depends on the amount of free (unstaked) tokens available in the protocol. There will typically always be a small float of the total supply unstaked to instantly fulfill burns, but for large amounts or high outflow volume, it becomes a two-step process.

**Step 1:** Approve the WithdrawManager contract with the amount of beHYPE tokens you want to unstake.

**Step 2:** Call `withdraw(uint256 beHypeAmount, bool instant, uint256 minAmountOut)` to burn `beHypeAmount` of tokens. The redeemed HYPE will be processed based on the `instant` parameter:

* `instant = false`: Normal withdrawal (7-day processing, no fee)
* `instant = true`: Instant withdrawal (0.5% fee applied)

The `minAmountOut` parameter provides slippage protection. This function returns a `withdrawalId` which will be used to claim the withdrawal once processed.

**Step 3:** For normal withdrawals, wait for processing time, then call `claimWithdrawal(uint256 withdrawalId)` to receive your HYPE tokens.

```solidity
function Burn() public {
    uint256 decimals = 10 ** 18;
    address user = address(0x1234); // set up with a balance of 10 beHYPE
    vm.startPrank(user);
    
    // 1. Approve 10 beHYPE (18 decimals)
    behype.approve(withdrawManager, 10 * decimals); 

    // 2. Normal withdrawal (7-day processing, no fee)
    uint256 minAmountOut = 9.9 ether; // 1% slippage tolerance
    uint256 withdrawalId = withdrawManager.withdraw(10 * decimals, false, minAmountOut);
    
    // 3. Wait for processing time (7 days)
    // ...
    
    // 4. Claim the withdrawal
    withdrawManager.claimWithdrawal(withdrawalId);
    require(user.balance >= 9.9 ether, "user should have received HYPE");
}
```

### Instant Redemption

For immediate access to HYPE, you can use instant redemption with a 0.5% fee:

```solidity
function InstantBurn() public {
    uint256 decimals = 10 ** 18;
    address user = address(0x1234); // set up with a balance of 10 beHYPE
    vm.startPrank(user);
    
    // 1. Approve 10 beHYPE
    behype.approve(withdrawManager, 10 * decimals);
    
    // 2. Instant withdrawal (immediate, 0.5% fee)
    uint256 minAmountOut = 9.4 ether; // accounting for 0.5% fee + slippage
    withdrawManager.withdraw(10 * decimals, true, minAmountOut);
    
    // Tokens are received immediately
    require(user.balance >= 9.4 ether, "user should have received HYPE instantly");
}
```

### API Endpoints

#### Base URL

```
https://api.hyperbeat.org/api/v1/behype/
```

#### Available Endpoints

1. **Get beHYPE Balance**
   * `GET /balance/{user_address}`
   * Returns user's beHYPE balance
2. **Get Exchange Ratio Updates**
   * `GET /exchange-ratio-update`
   * Returns latest exchange ratio between beHYPE and HYPE
3. **Get TVL Data**
   * `GET /tvl`
   * Returns total value locked, exchange ratio, and price information

### Function Signatures

#### StakingCore Contract

```solidity
// Stake HYPE to receive beHYPE
function stake(string calldata communityCode) external payable;
```

#### WithdrawManager Contract

```solidity
// Withdraw beHYPE for HYPE (returns withdrawal ID)
function withdraw(uint256 beHypeAmount, bool instant, uint256 minAmountOut) 
    external returns (uint256 withdrawalId);

// Claim completed withdrawal
function claimWithdrawal(uint256 withdrawalId) external;
```

#### BeHYPE Token Contract (ERC20)

```solidity
// Standard ERC20 functions
function balanceOf(address account) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
```

### Support

For additional support or questions about beHYPE integration, ask us on [discord](https://discord.gg/hyperbeat) or contact the development team.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hyperbeat.org/hyperbeat-staking/behype/builder-codes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
