OpenPond
1Branch0Tags
GL
glucryptoMerge commit 'refs/tmp/prod-master'
typescript
import { z } from "zod"; import { store } from "opentool/store"; import { wallet } from "opentool/wallet"; import { depositToHyperliquidBridge, fetchHyperliquidClearinghouseState, resolveHyperliquidChainConfig, } from "opentool/adapters/hyperliquid"; export const profile = { description: "Bridge USDC to the Hyperliquid bridge (creates the HL user on first deposit).", }; const decimalString = z .string() .min(1, "amount is required") .refine((v) => /^\d+(?:\.\d+)?$/.test(v), "must be a decimal string"); export const schema = z.object({ amount: decimalString, environment: z.enum(["mainnet", "testnet"]).default("testnet"), }); export async function POST(req: Request): Promise<Response> { const body = await req.json().catch(() => ({})); const { amount, environment } = schema.parse(body); const chainConfig = resolveHyperliquidChainConfig(environment); const context = await wallet({ chain: chainConfig.chain, }); const walletAddress = context.address; const deposit = await depositToHyperliquidBridge({ amount, environment, wallet: context, }); const clearinghouse = await fetchHyperliquidClearinghouseState({ environment, walletAddress, }); await store({ source: "hyperliquid", ref: deposit.txHash, status: "submitted", walletAddress, action: "deposit", notional: amount, network: environment === "mainnet" ? "hyperliquid" : "hyperliquid-testnet", metadata: { environment, txHash: deposit.txHash, bridge: deposit.bridgeAddress, amountUnits: deposit.amountUnits, clearinghouse, }, }); return Response.json({ ok: true, environment, walletAddress, deposit, clearinghouse, }); }