# Smart Contracts

{% hint style="warning" %}
DO NOT SEND YOUR TOKENS TO ANY OF THE BELOW CONTRACTS
{% endhint %}

## H4SHFund Contracts

<table><thead><tr><th width="189.76811671711715">Contract</th><th>Address</th></tr></thead><tbody><tr><td>Factory</td><td>0x...</td></tr><tr><td>Treasury</td><td>0x...</td></tr></tbody></table>

## Smart Contracts&#x20;

The Core Smart contracts are as follows

## Factory:&#x20;

The factory is responsible for deploying EIP-1167 compatible clones for LaunchEvents.&#x20;

It handles the protocol fee and early withdrawl fees which can be set by an owner.&#x20;

The Fee Receiver is the nominated address where protocol fees will be directed too.&#x20;

## Leap Contract Documentation

The Leap contract is a next-generation campaign and fundraising manager that enables decentralized fundraising campaigns with automated liquidity provisioning, token vesting, and treasury management capabilities.

### Key Features

* Decentralized fundraising campaigns
* Automated liquidity provisioning on Uniswap V3
* Token vesting via Sablier streams
* Treasury management for DAOs

### Contract Overview

The Leap contract inherits from `LeapBase` and implements `ReentrancyGuard` to provide secure fundraising functionality.

#### Constructor Parameters

* `_positionManager`: Address of the Uniswap V3 position manager
* `_wNative`: Address of the wrapped native token
* `_uniswapV3Factory`: Address of the Uniswap V3 factory
* `_lockupLinear`: Address of the Sablier lockup linear contract
* `_leapFactory`: Address of the LeapFactory contract

### Core Functions

#### depositNative()

Allows users to deposit native tokens into the launch event during the deposit phase.

**Requirements:**

* Must be in `PHASE_DEPOSIT`
* If whitelist is enabled, sender must be whitelisted
* Deposit amount must be within min/max allocation limits
* Cannot exceed maximum raise amount (if set)

#### withdrawNative(uint256 amountToRemove)

Enables users to withdraw their native tokens during deposit or phase one.

**Parameters:**

* `amountToRemove`: Amount of native tokens to withdraw

**Features:**

* Available during `PHASE_DEPOSIT` and `PHASE_ONE`
* Incurs a withdrawal fee during `PHASE_ONE`
* Burns corresponding receipt tokens

#### createTokenSetupLiquidityAndVesting(bytes32 tokenSalt, int24 tickLower, int24 tickUpper)

Finalizes the campaign by setting up the token, liquidity pool, and vesting stream.

**Parameters:**

* `tokenSalt`: Salt for token creation
* `tickLower`: Lower tick for Uniswap V3 position
* `tickUpper`: Upper tick for Uniswap V3 position

**Actions:**

1. Creates the launch token
2. Calculates and distributes protocol fees
3. Sets up Uniswap V3 liquidity pool (if LP percentage > 0)
4. Creates Sablier vesting stream (if tokens remain for vesting)
5. Distributes remaining funds to DAO treasury

**Requirements:**

* Can only be called by owner
* Must be in `PHASE_THREE` or `DEPLETED`
* Total raised amount must be greater than 0

### Events

* `NativeDeposited(address indexed user, uint256 amount)`
* `NativeWithdrawn(address indexed user, uint256 amount, uint256 fee)`
* `CampaignFinalized(uint256 streamId, uint256 protocolFeeAmount)`

### Security Features

* ReentrancyGuard implementation
* Phase-based access control
* Whitelist support
* Comprehensive input validation
* Fee management system

### Dependencies

The contract integrates with several external protocols and libraries:

* Uniswap V3 for liquidity provisioning
* Sablier V2 for token vesting
* OpenZeppelin for security features
* Custom libraries for math operations and error handling

&#x20;

## LeapBase Contract Documentation

The LeapBase contract serves as the foundational abstract contract for all LEAP events, providing core functionality for launch events, Sablier streams, and Uniswap V3 pool management.

### Core Components

#### Constants

* `PRECISION`: 1e18 (used for percentage calculations)
* `MAX_TOKEN_SUPPLY`: 1 billion tokens (with 18 decimals)
* `FEE_TIER`: 10,000 (1% fee tier for Uniswap V3)

#### Immutable Variables

* `LOCKUP_LINEAR`: Sablier V2 lockup linear contract interface
* `UNISWAP_V3_FACTORY`: Uniswap V3 factory interface
* `WNATIVE`: Wrapped native token address
* `POSITION_MANAGER`: Uniswap V3 position manager address
* `LEAP_FACTORY`: LEAP factory contract address

#### Storage Variables

* `launchToken`: Token details (address, name, symbol)
* `phaseTimeStamps`: Timestamps for different launch phases
* `launchParams`: Launch parameters (treasury, token supply, etc.)
* `totalRaised`: Total native tokens raised
* `uniswapV3PoolCreated`: Address of created Uniswap V3 pool
* `uniswapLPTokenId`: ID of Uniswap V3 LP position
* `streamId`: Sablier stream ID
* `accTokenPerShare`: Accumulated tokens per share
* `usersRewardDebt`: User reward debt mapping

### Key Functions

#### Initialization

```solidity
function initialize(
    LEAPDataTypes.LaunchToken memory _launchToken,
    LEAPDataTypes.PhaseTimeStamps memory _phaseTimeStamps,
    LEAPDataTypes.LaunchParams memory _launchParams,
    address _deployer
) external
```

Initializes the contract with launch parameters. Can only be called once.

#### Liquidity Management

**Initialize Pool and Mint Liquidity**

```solidity
function _initializePoolMintLiquidity(
    int24 tickLower,
    int24 tickUpper,
    uint24 feeTier,
    uint256 amount0
) internal
```

Creates and initializes a Uniswap V3 pool with initial liquidity.

**Remove LP**

```solidity
function removeLP() external
```

Removes LP position after lock period and transfers to DAO treasury.

**Claim LP Fees**

```solidity
function claimLPFees() external returns (uint256 amount0, uint256 amount1)
```

Claims accumulated fees from LP position to DAO treasury.

#### Sablier Stream Management

**Create Vesting Stream**

```solidity
function _createSablierVestingStream(uint128 vestingAmount) internal returns (uint256)
```

Creates a Sablier vesting stream for token distribution.

**Redeem Streamed Amount**

```solidity
function redeemStreamedAmount() external returns (uint256)
```

Allows users to claim their vested tokens based on receipt token balance.

#### Token Management

```solidity
function _createTokenAndMintSupply(address _treasury, bytes32 tokenSalt) internal
```

Creates the launch token and distributes initial supply.

#### Phase Management

```solidity
function currentPhase() public view returns (LEAPDataTypes.Phase)
```

Returns the current phase of the launch event:

* `NOT_STARTED`
* `PHASE_DEPOSIT`
* `PHASE_ONE`
* `PHASE_TWO`
* `PHASE_THREE`
* `DEPLETED`

#### Whitelist Management

```solidity
function addToWhitelist(address[] calldata addresses) external onlyOwner
function removeFromWhitelist(address removedAddress) external onlyOwner
```

Manages whitelisted addresses for participation.

### Receipt Token Functionality

The contract includes modified ERC20 functionality for receipt tokens:

* Transfers restricted to zero address or contract address
* Custom name ("RX Token") and symbol ("RX")
* Non-transferable design to maintain vesting mechanics

### Events

* `TokenCreated`: Emitted when launch token is created
* `UniswapV3PoolCreated`: Emitted when Uniswap pool is created
* `LPTransferred`: Emitted when LP position is transferred
* `LPFeesClaimed`: Emitted when LP fees are claimed
* `AddWhitelist`: Emitted when address added to whitelist
* `RemoveWhitelist`: Emitted when address removed from whitelist

### Security Features

* Ownership controls via OpenZeppelin's `Ownable`
* Phase-based access control
* Non-transferable receipt tokens
* Comprehensive parameter validation
* Safe ERC20 operations

### Integration Points

* Uniswap V3 for liquidity management
* Sablier V2 for token vesting
* OpenZeppelin for security and token standards
* Custom error handling via `Errors` library

## LeapDaoManager Contract Documentation

The LeapDaoManager contract serves as the treasury management system for LEAP events, providing basic but secure functionality for DAO treasury control. This is version 0.0.1, designed as the foundational implementation with room for future upgrades.

### Core Features

* Multi-manager style management (up to 5 managers)
* Generic execution capability for treasury management
* Native token receiving capability
* Manager addition and removal functionality

### Storage

#### Manager Storage

```solidity
address[] public daoManagers
```

Array storing all DAO manager addresses (maximum 5 managers)

### Key Functions

#### Constructor

```solidity
constructor(address initialOwner)
```

Initializes the contract with the first DAO manager.

**Parameters:**

* `initialOwner`: Address of the initial DAO manager

#### Manager Management

**Add Manager**

```solidity
function addDaoManager(address manager) external onlyDaoManager
```

Adds a new DAO manager to the system.

**Requirements:**

* Caller must be an existing manager
* New manager must not already be a manager
* Cannot exceed 5 total managers
* Emits `ManagerAdded` event

**Remove Manager**

```solidity
function removeDaoManager(address manager) external onlyDaoManager
```

Removes an existing DAO manager from the system.

**Requirements:**

* Caller must be an existing manager
* Cannot remove yourself
* Cannot remove last manager
* Emits `ManagerRemoved` event

**View Functions**

```solidity
function getAllManagers() external view returns (address[] memory)
```

Returns array of all current DAO managers.

```solidity
function isDaoManager(address manager) public view returns (bool)
```

Checks if an address is a current DAO manager.

#### Treasury Management

**Execute**

```solidity
function execute(
    address[] calldata contracts,
    bytes[] calldata data,
    uint256[] calldata msgValues
) external onlyDaoManager
```

Allows managers to execute arbitrary transactions for treasury management.

**Parameters:**

* `contracts`: Array of target contract addresses
* `data`: Array of calldata for each contract interaction
* `msgValues`: Array of native token amounts to send with each call

**Requirements:**

* Caller must be a DAO manager
* All array lengths must match
* Each call must succeed

### Events

#### ManagerAdded

```solidity
event ManagerAdded(address indexed addedBy, address indexed manager)
```

Emitted when a new manager is added.

**Parameters:**

* `addedBy`: Address of the manager who added the new manager
* `manager`: Address of the newly added manager

#### ManagerRemoved

```solidity
event ManagerRemoved(address indexed removedBy, address indexed manager)
```

Emitted when a manager is removed.

**Parameters:**

* `removedBy`: Address of the manager who removed the manager
* `manager`: Address of the removed manager

### Security Features

* Manager-only access control via `onlyDaoManager` modifier
* Maximum of 5 managers to prevent coordination issues
* Cannot remove last manager to ensure continued control
* Cannot remove self to prevent accidental lockouts
* Safe ERC20 operations using OpenZeppelin's SafeERC20

### Native Token Handling

The contract can receive native tokens through:

```solidity
receive() external payable
```

### Limitations and Future Improvements

1. Basic implementation with room for upgrades
2. No time-locks on manager changes
3. No voting mechanism for manager decisions
4. No quorum requirements for execution
5. No transaction queuing system

### Integration Points

* OpenZeppelin's SafeERC20 for token operations
* Custom error handling via `Errors` library
* Compatible with any ERC20 token and native currency


---

# 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://whitepaper.h4shfund.com/h4shfund-platform/smart-contracts.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.
