> For the complete documentation index, see [llms.txt](https://gemhunt.gitbook.io/doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gemhunt.gitbook.io/doc/technical-reference/presale-contract-functions-documentation.md).

# Presale Contract Functions Documentation

Immutable, secure, referral-based presale with automated PancakeSwap V2 liquidity deployment on Binance Smart Chain.

#### Presale Contract Address

```
0x27D9C6482A2c7A6aC9533F8da876Befe1B4B216B
```

### Public / External Functions

#### `contribute(address _referrer)` – payable

**Purpose:** Buy presale tokens by sending BNB\
**What it does:**

* Accepts BNB from user (minimum 0.002 BNB, maximum 20 BNB per wallet)
* Registers user exactly once
* Assigns the provided `_referrer` as their upline
* Instantly distributes referral rewards:
  * 10% → Level 1 referrer
  * 5% → Level 2 referrer
  * 5% → Level 3 referrer
* If `_referrer` is the official marketing wallet → marketing gets full 20% instantly (no L2/L3 split)
* Increases `totalRaised`

**Why:** One-click purchase with instant multi-level referral payout

***

#### `receive()` – payable fallback

**Purpose:** Allow direct BNB sends to contract\
**What it does:** Automatically calls `contribute(MARKETING_WALLET)`\
**Why:** Users can just send BNB directly → they get tokens and marketing wallet earns the full 20% referral reward

***

#### `withdraw()` – external

**Purpose:** Let users cancel their contribution before liquidity is added\
**What it does:**

* Refunds 80% of contributed BNB
* 20% Early Withdraw Penalty Applied
* Reduces `totalRaised` accordingly
* Can only be used before pool creation

**Why:** Fair exit option with penalty to discourage exploits and boost marketing by redirecting penalty to referral rewards and marketing wallet

***

#### `claimTokens()` – external

**Purpose:** Claim your purchased GemHunt tokens after liquidity pool is created\
**What it does:**

* Calculates tokens owed: `contribution × 800,000 tokens per BNB`
* Transfers exact amount from contract to user
* Prevents double-claiming

**Why:** Final token distribution step after fair launch

***

#### `finalizeAndCreatePool()` – onlyOwner

**Purpose:** Owner finalizes presale and adds liquidity to PancakeSwap\
**What it does:**

* Takes exactly 50% of raised BNB + 200M GemHunt tokens
* Calls PancakeSwap `addLiquidityETH()`
* Sends ALL LP tokens to dead address (permanent burn)
* Marks presale as finalized
* Can retry up to 3 times if router temporarily fails

**Why:** Guaranteed fair launch – no LP rug possible

***

***

#### `claimDevFee()` – onlyOwner

**Purpose:** Claim 30% development/marketing fee\
**What it does:**

* Transfers 30% of totalRaised to owner

**Why:** Fund development, marketing, audits, CEX listings

***

***

#### `withdrawRemainingETH()` – onlyOwner

**Purpose:** Sweep any dust BNB left after launch\
**Why:** Clean up contract balance

***

#### `recoverWrongTokens(address _token)` – onlyOwner

**Purpose:** Recover any ERC20 accidentally sent to contract\
**What it does:** Transfers tokens to owner (cannot recover the presale token itself)\
**Why:** Standard safety function

***

### Key View Functions&#x20;

| Function                      | Returns                                              | Use Case               |
| ----------------------------- | ---------------------------------------------------- | ---------------------- |
| `getTokenAllocation(address)` | How many tokens a user can claim                     | Show user balance      |
| `getUserInfo(address)`        | Full user data (contributed, earned, referrer, etc.) | Dashboard display      |
| `getReferralChain(address)`   | L1 → L2 → L3 referrers                               | Show referral tree     |
| `getDirectReferrals(address)` | Array of all people you directly referred            | Referral leaderboard   |
| `getPresaleStats()`           | Total raised, remaining to hard cap, tokens sold     | Progress bar           |
| `getBNBDistribution()`        | How much BNB goes to LP / dev / referrals            | Transparency page      |
| `canClaimDevFee()`            | true if dev fee is ready to be claimed               | Owner panel            |
| `canFinalizePool()`           | true if presale can be launched                      | Finalize button enable |

***

### Constants Summary

| Name                    | Value          | Meaning                                   |
| ----------------------- | -------------- | ----------------------------------------- |
| Tokens per BNB          | 800,000 GEM    | Presale price                             |
| Presale allocation      | 800M GEM       | Sold to users                             |
| Liquidity allocation    | 200M GEM       | Added to PancakeSwap                      |
| Hard cap                | 1000 BNB       | Maximum raise                             |
| Min / Max buy           | 0.002 – 20 BNB | Per wallet limits                         |
| Liquidity               | 50% of raised  | Burned                                    |
| Dev/Marketing fee       | 30% of raised  | Claimable                                 |
| Referral rewards        | 10% + 5% + 5%  | Instant payout                            |
| Marketing direct reward | 20%            | When marketing wallet is used as referrer |
| Early withdraw penalty  | 20%            | Discourages Exploits                      |

\
No ownership renouncement needed — ownership is only used for finalization and fee claim (standard practice).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://gemhunt.gitbook.io/doc/technical-reference/presale-contract-functions-documentation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
