building-blocks/SKILL.md
DeFi legos on Hyperliquid — HyperSwap V2, bonding curves, HyperCore perps/spot as composable primitives. How to build on top of existing protocols instead of reinventing them.
npx skillsauth add cloudzombie/liquidskills building-blocksInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
"I need to deploy my own DEX." HyperSwap V2 is already deployed on HyperEVM. It's Uniswap V2 compatible. Use it for swaps, liquidity, and price discovery on HyperEVM assets.
"I need to write an orderbook contract." HyperCore's native CLOB processes 100k orders/sec. You can't deploy a better orderbook in Solidity. Build on HyperCore's native orderbook via the API.
"Token launches need a lot of setup." HIP-1 + HIP-2 handles the whole thing at the protocol level. Bonding curve, initial liquidity, graduation to full orderbook — built in.
HyperSwap V2 is the primary AMM DEX on HyperEVM. It's Uniswap V2 compatible — same interface, same mechanics, different chain.
See addresses/SKILL.md for deployed contract addresses.
x * y = kimport "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
interface IHyperSwapV2Router02 is IUniswapV2Router02 {}
// Address from addresses/SKILL.md
IHyperSwapV2Router02 router = IHyperSwapV2Router02(HYPERSWAP_V2_ROUTER);
// Approve first
IERC20(tokenIn).approve(address(router), amountIn);
// Swap exact tokens for tokens
address[] memory path = new address[](2);
path[0] = tokenIn;
path[1] = tokenOut;
uint256[] memory amounts = router.swapExactTokensForTokens(
amountIn,
amountOutMin, // ALWAYS set a minimum — never 0
path,
recipient,
block.timestamp + 300
);
// TypeScript: swap on HyperSwap V2
import { parseAbi, parseEther, parseUnits } from 'viem';
const hyperSwapRouterAbi = parseAbi([
'function swapExactTokensForTokens(uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline) returns (uint256[] memory amounts)',
'function getAmountsOut(uint256 amountIn, address[] calldata path) view returns (uint256[] memory amounts)',
]);
// Get expected output
const amounts = await publicClient.readContract({
address: HYPERSWAP_V2_ROUTER,
abi: hyperSwapRouterAbi,
functionName: 'getAmountsOut',
args: [parseEther('1'), [WETH_ADDRESS, USDC_ADDRESS]],
});
const expectedOut = amounts[1];
const amountOutMin = expectedOut * 99n / 100n; // 1% slippage
// Approve and swap
await walletClient.writeContract({
address: HYPERSWAP_V2_ROUTER,
abi: hyperSwapRouterAbi,
functionName: 'swapExactTokensForTokens',
args: [parseEther('1'), amountOutMin, [WETH_ADDRESS, USDC_ADDRESS], recipientAddress, BigInt(Date.now() / 1000) + 300n],
});
// Add liquidity to a HyperSwap V2 pair
IERC20(tokenA).approve(address(router), amountADesired);
IERC20(tokenB).approve(address(router), amountBDesired);
(uint amountA, uint amountB, uint liquidity) = router.addLiquidity(
tokenA,
tokenB,
amountADesired,
amountBDesired,
amountAMin, // Minimum A accepted (slippage protection)
amountBMin, // Minimum B accepted (slippage protection)
recipient,
deadline
);
HyperCore's CLOB is the highest-leverage building block. You compose with it via the API, not via contracts.
Reading perp state:
import requests
# All perp markets + metadata
meta = requests.post('https://api.hyperliquid.xyz/info',
json={'type': 'meta'}).json()
# All current mid prices
mids = requests.post('https://api.hyperliquid.xyz/info',
json={'type': 'allMids'}).json()
# Specific user's positions
state = requests.post('https://api.hyperliquid.xyz/info', json={
'type': 'clearinghouseState',
'user': '0xYourAddress'
}).json()
# Open interest and funding
ctx = requests.post('https://api.hyperliquid.xyz/info', json={
'type': 'metaAndAssetCtxs'
}).json()
Using perps in a vault strategy:
from hyperliquid.exchange import Exchange
from hyperliquid.info import Info
# Delta-neutral vault: long spot, short perp
def rebalance_vault(exchange, info, target_notional):
# Get current ETH perp price
mids = info.all_mids()
eth_price = float(mids['ETH'])
# Calculate position size
size = target_notional / eth_price
# Open short perp
result = exchange.order(
"ETH",
is_buy=False, # Short
sz=size,
limit_px=eth_price * 0.999, # 0.1% below mid
order_type={"limit": {"tif": "Gtc"}},
reduce_only=False
)
return result
HIP-1 spot tokens are the building blocks for anything token-related on HyperCore:
# Get all spot markets
spot_meta = requests.post('https://api.hyperliquid.xyz/info',
json={'type': 'spotMeta'}).json()
# Get spot orderbook for a token
book = requests.post('https://api.hyperliquid.xyz/info', json={
'type': 'l2Book',
'coin': 'PURR' # Example HIP-1 token
}).json()
# Place spot limit order (buy PURR)
result = exchange.order(
"PURR",
is_buy=True,
sz=1000,
limit_px=0.001,
order_type={"limit": {"tif": "Gtc"}}
)
HIP-1 tokens use a bonding curve before graduating to a full orderbook:
The RYPE pattern (x*y=k until threshold):
Price discovery phase:
- New HIP-1 token launches with bonding curve
- x*y=k: buying increases price, selling decreases it
- No traditional LP needed — protocol handles liquidity
Graduation:
- When market cap hits the threshold (varies by configuration)
- Protocol removes liquidity from bonding curve
- Full CLOB (limit orderbook) activates
- Token now tradeable with all order types
Building on bonding curve mechanics:
# Monitor token graduation
def watch_for_graduation(token_symbol, exchange, info):
spot_meta = info.spot_meta()
# Find the token
token = next(t for t in spot_meta['tokens']
if t['name'] == token_symbol)
token_index = spot_meta['tokens'].index(token)
asset_id = 10000 + token_index
# Check if bonding curve is still active or graduated
# When graduated, there will be a CLOB with bid/ask spread
book = info.l2_snapshot(token_symbol)
if book['levels'][0] and book['levels'][1]:
print(f"{token_symbol}: Graduated! Full orderbook active.")
else:
print(f"{token_symbol}: Still on bonding curve.")
The HLP (Hyperliquid Liquidity Provider) vault is a protocol-native vault. You can:
Custom vault pattern:
# Vault manager: accept user deposits, deploy into HyperCore strategies
class HyperliquidVault:
def __init__(self, exchange, info):
self.exchange = exchange
self.info = info
def deposit(self, amount_usdc, user_address):
# Record deposit in your own accounting
# USDC is in HyperCore balance
pass
def rebalance(self):
# Use HyperCore perps/spot for strategy execution
mids = self.info.all_mids()
eth_price = float(mids['ETH'])
# Example: long/short strategy
self.exchange.order("ETH", True, 1.0, eth_price * 1.001,
{"limit": {"tif": "Gtc"}})
A HyperEVM contract can trigger HyperCore actions by reading from the HyperCore precompile:
// Reading HyperCore state from HyperEVM
// System precompile (verify address in latest docs)
address constant HYPERCORE_PRECOMPILE = 0x0000000000000000000000000000000000000800;
// This enables conditional logic based on HyperCore state
// e.g., "execute this contract action only if ETH perp price > $2000"
Since HyperEVM and HyperCore share finality:
This is the most powerful composability pattern — using both layers atomically.
Build on top of primitives. Don't rebuild them.
development
Why build on Hyperliquid. HyperBFT consensus, native orderbook, speed, AI agent angle, honest tradeoffs. Use when someone asks "should I build on Hyperliquid?", "why not Ethereum?", or when an agent needs to understand what makes Hyperliquid unique.
development
Wallets on Hyperliquid — MetaMask + chain ID 999 setup, HyperCore API wallets, agent wallet patterns, EIP-712 signing for exchange actions. Essential for any agent that needs to interact with Hyperliquid.
tools
Development tools for Hyperliquid — Foundry, Hardhat, viem, wagmi for HyperEVM; Python SDK and TypeScript SDK for HyperCore API. What works, what to use, how to set up.
testing
Smart contract testing for HyperEVM with Foundry/Hardhat — unit tests, fuzz testing, testnet fork testing. What to test, what not to test, and what LLMs get wrong on Hyperliquid.