Skip to content

CrimsonLuckyLabs/hyperhook-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@hyperhook/sdk

TypeScript SDK for Hyperhook — hourly BTC UP/DOWN markets on a Uniswap v4 hook.

Read market state and curve quotes off-chain, build transaction calldata with viem, and sign with any wallet. The SDK does not send transactions or hold keys.

Install

npm install github:CrimsonLuckyLabs/hyperhook-sdk viem

Or in package.json:

{
  "dependencies": {
    "@hyperhook/sdk": "github:CrimsonLuckyLabs/hyperhook-sdk",
    "viem": "^2"
  }
}

From source

git clone https://github.com/CrimsonLuckyLabs/hyperhook-sdk.git
cd hyperhook-sdk
npm install
npm run build

Quick start

import {
  createHyperhookClient,
  applySlippageBps,
  defaultDeadline,
} from "@hyperhook/sdk";

const client = createHyperhookClient({ chainId: 1 });

const market = await client.getMarket();
console.log(market.epoch, market.tradingOpen);
console.log("UP spot (USDC):", Number(market.curve.upSpotWei) / 1e6);

const amount = 3_000_000n; // $3 USDC (6 decimals)
const quote = await client.quoteBuy({ side: "up", collateralAmount: amount });
const tx = client.buildBuyTx({
  side: "up",
  amount,
  minNetOut: applySlippageBps(quote.tokensOut, 100),
  deadline: defaultDeadline(),
});

// Pass tx.to + tx.data to your wallet (viem, ethers, MetaMask, etc.)

What you can do

API Description
getMarket() Epoch, strike, trading open, curve spots, token addresses, floor
getCurveState() Raw curve inputs for custom quotes
getUserPosition(address, epoch?) hhUP / hhDOWN stake for an account
quoteBuy({ side, collateralAmount }) Outcome tokens for a USDC buy
quoteSellOpen({ side, tokenAmount }) USDC proceeds for an open-epoch sell
buildBuyTx / buildSellOpenTx Calldata for curve trades
buildRedeemWinnerTx Claim winner after epoch (+ tax window rules on-chain)
buildSellWinnerWithTaxTx Early winner exit with decay tax
buildClaimConsolationTx Loser consolation claim
buildRedeemAtFloorTx Burn $HYPERHOOK for backing USDC
buildApproveCollateralTx ERC20 approve Hyperhook to spend USDC

Wallet example (viem)

import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { mainnet } from "viem/chains";

const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
const wallet = createWalletClient({
  account,
  chain: mainnet,
  transport: http("https://ethereum.publicnode.com"),
});

const client = createHyperhookClient({ chainId: 1 });

const allowance = await client.getCollateralAllowance(account.address);
if (allowance < amount) {
  const approve = client.buildApproveCollateralTx({ amount: 2n ** 256n - 1n });
  await wallet.sendTransaction({ ...approve, account });
}

const buy = client.buildBuyTx({ side: "up", amount, minNetOut, deadline: defaultDeadline() });
await wallet.sendTransaction({ ...buy, account });

Custom deployment

Mainnet defaults are bundled. For other hooks or chains:

import { createHyperhookClientAsync } from "@hyperhook/sdk";

const client = await createHyperhookClientAsync({
  chainId: 1,
  hook: "0xYourHyperhookAddress",
  rpcUrl: "https://your-rpc.example",
});

Mainnet defaults

Address
Hyperhook 0x9aEF5dd3Be8ff4746e62946b85C5948CDD92C488
USDC 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
Default RPC https://ethereum.publicnode.com

Development

npm run build   # compile to dist/

Peer dependency: viem ^2.

License

MIT — see LICENSE.

About

Hyperhook SDK

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors