Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Hyperliquid Integration #33

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
6 changes: 6 additions & 0 deletions projects/hyperliquid/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"trailingComma": "all",
"tabWidth": 4,
"printWidth": 180
}
114 changes: 114 additions & 0 deletions projects/hyperliquid/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Hyperliquid

Integration with Hyperliquid

## Overview

Hyperliquid is a performant L1 optimized from the ground up. The vision is a fully onchain open financial system with user built applications interfacing with performant native components, all without compromising end user experience. The Hyperliquid L1 is performant enough to operate an entire ecosystem of permissionless financial applications – every order, cancel, trade, and liquidation happens transparently on-chain with block latency <1 second. The chain currently supports 100k orders / second.

The Hyperliquid L1 uses a custom consensus algorithm called HyperBFT which is heavily inspired by Hotstuff and its successors. Both the algorithm and networking stack are optimized from the ground up to support the L1. The flagship native application is a fully onchain order book perpetuals exchange, the Hyperliquid DEX. Further developments include a native token standard, spot trading, permissionless liquidity, etc.

## Supported Networks

- ARBITRUM

## Common Tasks

- "Bridge 100 USDC to Hyperliquid from Arbitrum network"
- "Move 50 USDC from Arbitrum network to Hyperliquid"
- "Send 25.5 USDC to Hyperliquid bridge on Arbitrum network"
- "Withdraw 20 USDC from Hyperliquid to Arbitrum"
- "Move 10.5 USDC from Hyperliquid back to Arbitrum"
- "Move 100USDC from my spot to my perp balance on Hyperliquid"
- "I need you to transfer 55.5 USD from perps to spot on Hyperliquid"
- "Open a long on 12$ of BTC with no leverage on Hyperliquid"
- "Short me 1 BTC with 50x leverage on Hyperliquid"
- "Close my ARB position on Hyperliquid"
- "Close my Bitcoin position on Hyperliquid"

## Available Functions

- Bridging to Hyperliquid (minimum 5 USDC)
- Withdrawing from Hyperliquid (minimum 2 USDC)
- Moving USDC between spot and perp balances on Hyperliquid
- Opening and closing perp positions on Hyperliquid

## Tests

To run tests:

```bash
npm test
```

To check test coverage:

```bash
npm run test:coverage
```

## Installation

```bash
yarn add @heyanon/hyperliquid
```

## Usage

### Bridging USDC to Hyperliquid

```typescript
// Bridge USDC from Arbitrum to Hyperliquid
await bridgeToHyperliquid({
chainName: 'arbitrum',
account: '0x...',
amount: '10', // Amount in USDC
});
```

### Withdrawing USDC from Hyperliquid

```typescript
// Withdraw USDC from Hyperliquid to Arbitrum
await withdrawFromHyperliquid({
chainName: 'hyperliquid',
account: '0x...',
amount: '5', // Amount in USDC
});
```

### Moving USDC from spot to perp balance on Hyperliquid

```typescript
// Move funds from spot to perp account
await transferToPerpetual({
amount: '5', // Amount in USDC
});
```

### Moving USDC from perp to spot balance on Hyperliquid

```typescript
// Move funds from perp to spot account
await transferToSpot({
amount: '900', // Amount in USDC
});
```

### Opening a perp position

```typescript
// Shorts 1000$ of BTC at 50x leverage on Hyperliquid
await openPerp({ account: '0xYourAddress', asset: 'BTC', size: '1000', sizeUnit: 'USD', leverage: 50, short: true });
```

### Closing a perp position

```typescript
// Closes the open ETH perp position on Hyperliquid
await closePerp({ account: '0xYourAddress', asset: 'ETH' });
```

## Note

Trading functionality development is in progress. Next features will include order management, position tracking, and advanced trading operations.
44 changes: 44 additions & 0 deletions projects/hyperliquid/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "@heyanon/project-hyperliquid",
"version": "1.0.0",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"module": "dist/index.mjs",
"files": [
"dist"
],
"engines": {
"node": ">=18"
},
"publishConfig": {
"access": "public"
},
"scripts": {
"start": "tsup --watch",
"build": "tsup",
"test": "vitest --run",
"lint": "tsdx lint",
"prepare": "pnpm run build",
"size": "size-limit",
"analyze": "size-limit --why",
"format": "prettier --write \"*/**/*.ts\""
},
"devDependencies": {
"@size-limit/preset-small-lib": "^9.0.0",
"@types/big.js": "^6.2.0",
"@types/jest": "^29.5.12",
"tsdx": "^0.14.1",
"tslib": "^2.6.2",
"tsup": "^7.2.0",
"typescript": "^5.7.3"
},
"dependencies": {
"@heyanon/sdk": "^2.0.2",
"@msgpack/msgpack": "2.8.0",
"axios": "^1.8.1",
"viem": "2.22.9",
"vitest": "^2.1.8"
},
"description": "Hyperliquid is Layer 1 blockchain providing CEX-like trading experience through on-chain order books. Enables USDC bridging and supports both spot/perpetual trading with full position management."
}
Loading